sveltejs / kit

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

+layout.js/ts when ssr off and 404 error happens, then data in load function is null #10157

Closed ToP29 closed 1 year ago

ToP29 commented 1 year ago

Describe the bug

When i turn off ssr (in +layout.js) and 404 error happens, then data is always null in +layout.js in load function

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-ck2eek?file=src%2Froutes%2F%2Blayout.js&terminal=dev

go to some non-existing page and try turning ssr on and off and observe log in console

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.5.0 => 1.20.2 
    svelte: ^3.54.0 => 3.59.1 
    vite: ^4.3.0 => 4.3.9

Severity

blocking all usage of SvelteKit

Additional Information

No response

eltigerchino commented 1 year ago

This happens because disabling SSR in +layout.js causes +layout.server.js to never run for any pages. Hence, data is never populated by the server load function.

brunobely commented 1 year ago

Maybe this is the intended behavior, but I've been facing a similar bug and just did some testing by putting console.logs at the top of each of the handle, load (server), load (client), functions, and these are the logs, in order:

Note: I'm using "@sveltejs/kit": "^1.22.6".