question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

+layout.server.js not correctly passing data down during client-side hydration

See original GitHub issue

Describe 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

Logs

No response

System Info

stackblitz default template fork

Severity

serious, but I can work around it

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rmunncommented, Aug 16, 2022

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 whether load 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.

1reaction
robertadamsonsmithcommented, Aug 16, 2022

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 and await parent()): https://stackblitz.com/edit/sveltejs-kit-template-default-euznnp?file=src/routes/+layout.svelte

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found