kit
kit copied to clipboard
`$page.data` does not get updated correctly
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
- toggle between the
rootandpage-1links a few time - the heading at the top should update accordingly
- now toggle between
rootand thepage-2links - the heading does not get updated when clicking on
root - now add
other: 5to the return object in/routes/+page.layout.js - now toggling between
rootandpage-2works - but toggling between
rootandpage-1does not update the heading
Logs
No response
System Info
Stackblitz
Severity
serious, but I can work around it
Additional Information
No response
The "has the data changed" logic here https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/client.js#L446-L463 is flawed
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?