kit icon indicating copy to clipboard operation
kit copied to clipboard

`$page.data` does not get updated correctly

Open ivanhofer opened this issue 2 years ago • 1 comments

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

ivanhofer avatar Dec 14 '22 16:12 ivanhofer

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

dummdidumm avatar Dec 19 '22 10:12 dummdidumm

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?

yuliankarapetkov avatar Apr 23 '24 05:04 yuliankarapetkov