+layout.server.js not correctly passing data down during client-side hydration
See original GitHub issueDescribe the bug
After client side navigation, calling await parent()
from within a +page.server.js exported load function returns {"data":null}
instead of the value returned from the +layout.server.js exported load function
Reproduction
- Load https://stackblitz.com/edit/sveltejs-kit-template-default-8az3ew?file=src/routes/+page.server.js
- Note that layout data, and page data are correct initially
- Click on ‘Another page’ link, to do a client side navigation to a new page
- Note that layout data is now incorrect (as is the layout data that was merged into page data)
Logs
No response
System Info
stackblitz default template fork
Severity
serious, but I can work around it
Additional Information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
React 18: Hydration failed because the initial UI does not ...
So in my own opinion based on my personal experience the problem is caused by improper arrangement of html elements and to solve...
Read more >Why Efficient Hydration in JavaScript Frameworks is so ...
When it comes to client side hydration there are two characteristics that are pretty unfortunate. One is we render on the server, and...
Read more >Keeping Server-Side Rendering Cool With React Hydration
Missing Data on Server-Side Once the data was available it hydrated on the page without shifting the layout. Loading patterns like this can...
Read more >Progressive Hydration - Patterns.dev
Hydration allows client-side React to recognize the ReactDOM components that are rendered on the server and attach events to these components.
Read more >Server-side rendering - Apollo GraphQL Docs
Server -side rendering (SSR) is a performance optimization for modern web apps. ... This will ensure the client-side React hydration works correctly by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
On first navigation, the load function in
+layout.server.js
is run, because the server is hit. The second navigation is a client-side-only nagivation, so the server isn’t hit, and therefore+layout.server.js
isn’t run and the values it returns aren’t preserved. And instead,await parent()
gets{ data: null }
, which indeed doesn’t seem right.In https://github.com/sveltejs/kit/discussions/5883#discussioncomment-3393943, Rich Harris wrote that
load
results are re-used; the question I don’t yet know the answer to is whetherload
results from server load functions are intended to be preserved after client-side navigations. I suspect the answer is yes, in which case the issue title should probably be changed to “load() results from server discarded after client-side nagivation” to better reflect what the actual bug is.I agree - I don’t know if changing the title of the issue would confuse somebody that has already seen it once though. Unless the issue extends beyond the
+layout.server.js
though, perhaps the title should be: “load() results from +layout.server.js discarded after client-side navigation”I’ve reduced the reproduction to one which shows the problem in a more minimal way (i.e. without a
+page.server.js
andawait parent()
): https://stackblitz.com/edit/sveltejs-kit-template-default-euznnp?file=src/routes/+layout.svelte