Skip to content

Update for runes dependant on PageData object fired for old component, after navigating with newly loaded data. #12851

@eldiGH

Description

@eldiGH

Describe the bug

When we have a rune dependent on the PageData object, after navigation it updates for the component that is being unmounted; however, it uses the new PageData object already for the old page. This causes some undefined errors in my case. Tested with $derived and $inspect runes.

Reproduction

I've created simple stackblitz repro repo. It's only two pages with links to each other and load function returning object. For each click on the link we are getting "TypeError: Cannot read properties of undefined".

stackblitz: https://stackblitz.com/edit/sveltejs-kit-template-default-4e5vkn?description=The%20default%20SvelteKit%20template,%20generated%20with%20create-svelte&file=package.json&title=SvelteKit%20Default%20Template

Logs

From my repro repo:

init test
[email protected]:26 TypeError: Cannot read properties of undefined (reading 'bar')
    at +page.svelte:4:21
    at chunk-P7K6PZIY.js?v=8436a562:395:15
    at update_reaction (chunk-SPZDVXP4.js?v=8436a562:1677:23)
    at update_effect (chunk-SPZDVXP4.js?v=8436a562:1768:21)
    at internal_set (chunk-SPZDVXP4.js?v=8436a562:2356:13)
    at set (chunk-SPZDVXP4.js?v=8436a562:2327:10)
    at Object.set (chunk-MTDI236X.js?v=8436a562:691:11)
    at Function.assign (<anonymous>)
    at Svelte4Component.__privateGet.$set (chunk-MTDI236X.js?v=8436a562:722:14)
    at Svelte4Component.$set (chunk-MTDI236X.js?v=8436a562:730:35)
console.error @ [email protected]:26
(anonymous) @ chunk-P7K6PZIY.js?v=8436a562:397
update_reaction @ chunk-SPZDVXP4.js?v=8436a562:1677
update_effect @ chunk-SPZDVXP4.js?v=8436a562:1768
internal_set @ chunk-SPZDVXP4.js?v=8436a562:2356
set @ chunk-SPZDVXP4.js?v=8436a562:2327
set @ chunk-MTDI236X.js?v=8436a562:691
Svelte4Component.__privateGet.$set @ chunk-MTDI236X.js?v=8436a562:722
$set @ chunk-MTDI236X.js?v=8436a562:730
navigate @ client.js?v=8436a562:1418
await in navigate
(anonymous) @ client.js?v=8436a562:2155
Show 10 more frames
Show lessUnderstand this error
+page.svelte:14 init sub test
[email protected]:26 TypeError: Cannot read properties of undefined (reading 'subBar')
    at +page.svelte:4:24
    at chunk-P7K6PZIY.js?v=8436a562:395:15
    at update_reaction (chunk-SPZDVXP4.js?v=8436a562:1677:23)
    at update_effect (chunk-SPZDVXP4.js?v=8436a562:1768:21)
    at internal_set (chunk-SPZDVXP4.js?v=8436a562:2356:13)
    at set (chunk-SPZDVXP4.js?v=8436a562:2327:10)
    at Object.set (chunk-MTDI236X.js?v=8436a562:691:11)
    at Function.assign (<anonymous>)
    at Svelte4Component.__privateGet.$set (chunk-MTDI236X.js?v=8436a562:722:14)
    at Svelte4Component.$set (chunk-MTDI236X.js?v=8436a562:730:35)
console.error @ [email protected]:26
(anonymous) @ chunk-P7K6PZIY.js?v=8436a562:397
update_reaction @ chunk-SPZDVXP4.js?v=8436a562:1677
update_effect @ chunk-SPZDVXP4.js?v=8436a562:1768
internal_set @ chunk-SPZDVXP4.js?v=8436a562:2356
set @ chunk-SPZDVXP4.js?v=8436a562:2327
set @ chunk-MTDI236X.js?v=8436a562:691
Svelte4Component.__privateGet.$set @ chunk-MTDI236X.js?v=8436a562:722
$set @ chunk-MTDI236X.js?v=8436a562:730
navigate @ client.js?v=8436a562:1418
await in navigate
(anonymous) @ client.js?v=8436a562:2155
Show 10 more frames
Show lessUnderstand this error
+page.svelte:14 init test

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 7.37 GB / 31.95 GB
  Binaries:
    Node: 22.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.10.5 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-auto: ^3.2.5 => 3.2.5
    @sveltejs/kit: ^2.7.2 => 2.7.2
    @sveltejs/vite-plugin-svelte: ^4.0.0 => 4.0.0
    svelte: ^5.0.4 => 5.0.4
    vite: ^5.4.9 => 5.4.9

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions