Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$page.data does not get updated correctly #8157

Closed
ivanhofer opened this issue Dec 14, 2022 · 2 comments · Fixed by #8377
Closed

$page.data does not get updated correctly #8157

ivanhofer opened this issue Dec 14, 2022 · 2 comments · Fixed by #8377
Labels
bug Something isn't working

Comments

@ivanhofer
Copy link
Contributor

Describe the bug

If the data returned from load inside a +page.server.js ("page-X") has the same shape as the data returned inside its corresponding +layout.server.js, the $page.data does not get updated when routing from "page-X" to another page that does not have its own +page.server.js file.

As a workaround I'm currently just adding a random key to the return value of +layout.server.js.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-bcif9n?file=src/routes/page-2/+page.server.js

  1. toggle between the root and page-1 links a few time
  2. the heading at the top should update accordingly
  3. now toggle between root and the page-2 links
  4. the heading does not get updated when clicking on root
  5. now add other: 5 to the return object in /routes/+page.layout.js
  6. now toggling between root and page-2 works
  7. but toggling between root and page-1 does not update the heading

Logs

No response

System Info

Stackblitz

Severity

serious, but I can work around it

Additional Information

No response

@dummdidumm dummdidumm added the bug Something isn't working label Dec 19, 2022
@dummdidumm
Copy link
Member

@yuliankarapetkov
Copy link

yuliankarapetkov commented Apr 23, 2024

I am still experiencing an issue with this where the data in the load() function and the data in the component itself is different.

// in load()
console.log(userId); // prints 123
return { userId };

// in component
export let data;

$: console.log(data) // prints { userId: undefined }
$: console.log($page.data) // prints { userId: undefined }

Why is this happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants