Rendering issue with Svelte/Svelte Kit

81 views Asked by At

To give a bit of context, I'm building a web app using Svelte/Svelte kit and node js et psql which is like a market place for players of a certain video game. Players can come on the website, connect and then put their items on sale through a formular. Then, the offer with the specific characteristics entered by the seller is visible by all the user visitors.

There are two types of items equipment (hat, belt, ring, etc...) and weapons. For the equipments, the system works perfectly but it doesn't work correctly for weapons, the damages are not displayed

First, let me show you a correct example and the problem as well as the code I use.

This is the classic process of selling an objet, the user fill the formular, a post request is sent to the database, the page reload and the item is displayed on the market place

The Gif is slow down a bit so you can see what is the problem. The user fill the formular with damage and characteristics, a post request is sent, the page reload and the weapon is displayed but I don't get why the damages are not displayed. They are but then they disappear

To solve this issue I first try to investigate why there is this kind of blinking when the page is loading that makes the damages of the weapon disappear.

To have a better understanding of what is happening during the load of the page, I used Goggle light House. As you can see from the screen below the damages appear at first but then there is another phase of rendering and they disappear.

Damages appearing

Damages disappear after a new phase of rendering

Nevertheless, I couldn't identify clearly what was inside this rendering that make the damages disappearing.

So then, I tried to investigate in my code and I found something very interesting that might solve the problem if I fix it but I can't figure what.

This is an extract of my the script of the +page.svelte itemCard component concerned by the issue. Basically, here I import all the component needed for the itemCard and I retrieve the props passed by the +page.svelte to the itemcard component. The one which is relevant is the

Result of the console.log(item) of the itemCard component within the browser

Result of the console.log(item) of the itemCard component within VsCode terminal. As you can see the objects are identical

Result of the console.log(item) of the itemCard component within the browser. We don't see the damages (degats_neutre_before, degats_neutre_after

Result of the console.log(item) of the itemCard component within VsCode terminal. As you can see the degats_neutre_before and degats_neutre_after appear

And something that I found strange as well is when hardcode in my script the item, I have the same issue between the browser and the VsCode terminal but the damages are displayed on the itemcard.

Here the weapon we took as an example is harcoded directly

Result of the console.log(item) of the itemCard component when the item is harcoded within VsCode terminal. As you can see the degats_neutre_before and degats_neutre_after appear

Result of the console.log(item) of the itemCard component within the browser. We don't see the damages (degats_neutre_before, degats_neutre_after

The market place display the hardcoded item with the damages

So I'm a bit stuck right now and I asking for help. I hope my explications are clear

1

There are 1 answers

0
brunnerh On

Given that the URL and tab icon change, this looks like a hard navigation so some blinking is to be expected. Probably because the button causes a form submission; make sure to use the enhance action to update the page dynamically instead.

When things are shown first and then disappear that suggests that server-side rendering worked correctly but something on the client-side did not. Maybe some of the data is used non-reactively.