sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.49k stars 1.89k forks source link

goto("...", { invalidateAll: true }) does not work as expected. #12668

Open jjones315 opened 2 weeks ago

jjones315 commented 2 weeks ago

Describe the bug

when using goto("...", { invalidateAll: true }) the destination page is navigated to before the parent layout has updated. if the child page relies on anything from the layout to update the page will fail.

when i use invalidateAll().then(() => goto("...")) everything works as expected. it is unintuitive that these 2 calls do no behave the same.

Reproduction

https://github.com/jjones315/invalidate-example

to reproduce to to home page and enter text in textbox, click one of the 2 buttons to try submitting. notice the Add Item ({ invalidateAll:true }) button will result in the error being logged. the other button works as intended.

Logs

Uncaught TypeError: Cannot read properties of undefined (reading 'id')

    in {expression}
    in +page.svelte
    in +layout.svelte
    in root.svelte

    at {expression} (+page.svelte:10:10)
    at update_reaction (chunk-VUECRJEY.js?v=1021c0c3:1527:23)
    at update_effect (chunk-VUECRJEY.js?v=1021c0c3:1621:21)
    at create_effect (chunk-VUECRJEY.js?v=1021c0c3:969:7)
    at render_effect (chunk-VUECRJEY.js?v=1021c0c3:1077:10)
    at Module.template_effect (chunk-VUECRJEY.js?v=1021c0c3:1085:10)
    at _page (+page.svelte:7:56)
    at chunk-TN26QBVN.js?v=1021c0c3:205:58
    at update_reaction (chunk-VUECRJEY.js?v=1021c0c3:1527:23)
    at update_effect (:5174/node_modules/.vite/deps/chunk-VUECRJEY.js?v=1021c0c3:1621:21)TypeError: Cannot read properties of undefined (reading 'id')
    at {expression} (+page.svelte:10:10)
    at update_reaction (chunk-VUECRJEY.js?v=1021c0c3:1527:23)
    at update_effect (chunk-VUECRJEY.js?v=1021c0c3:1621:21)
    at create_effect (chunk-VUECRJEY.js?v=1021c0c3:969:7)
    at render_effect (chunk-VUECRJEY.js?v=1021c0c3:1077:10)
    at Module.template_effect (chunk-VUECRJEY.js?v=1021c0c3:1085:10)
    at _page (+page.svelte:7:56)
    at chunk-TN26QBVN.js?v=1021c0c3:205:58
    at update_reaction (chunk-VUECRJEY.js?v=1021c0c3:1527:23)
    at update_effect (chunk-VUECRJEY.js?v=1021c0c3:1621:21)

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900
    Memory: 5.57 GB / 31.70 GB
  Binaries:
    Node: 21.6.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.7.1 - ~\AppData\Roaming\npm\pnpm.CMD
    bun: 1.1.15 - ~\AppData\Roaming\npm\bun.CMD
  Browsers:
    Edge: Chromium (127.0.2651.86)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.4
    @sveltejs/kit: ^2.0.0 => 2.5.26
    @sveltejs/vite-plugin-svelte: ^4.0.0-next.6 => 4.0.0-next.7
    svelte: 5.0.0-next.234 => 5.0.0-next.234
    vite: ^5.0.3 => 5.4.4

Severity

serious, but I can work around it

Additional Information

No response

jjones315 commented 1 week ago

After Testing this more, one of my use cases has a redirect in the load, the issue is still present there, so i think the root issue is the layout not being updated before the child page. the invalidateAll().then(() => goto("...")) is just masking it by giving the layout enough time to update before actually redirecting.