sveltejs / kit

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

Disabling SSR does not work #12155

Closed herrjemand closed 3 weeks ago

herrjemand commented 3 weeks ago

Describe the bug

Putting export const ssr = true into the root layout.svelte and layout.js/ts does not work, and breaks goto as it still tries to render on server.

Reproduction

Place export const ssr = true into the root layout.svelte and/or layout.js/ts

Try using GOTO, or window.location.href = "/login"

Server nukes itself

Logs

ReferenceError: window is not defined
    at /Users/yadev/Github/vistrem/svelte-frontend/src/lib/components/authcheck/Authcheck.svelte:10:9
    at Object.$$render (/Users/yadev/Github/vistrem/svelte-frontend/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at eval (/Users/yadev/Github/vistrem/svelte-frontend/src/routes/case/[id]/+layout.svelte:25:97)
    at Object.$$render (/Users/yadev/Github/vistrem/svelte-frontend/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at Object.default (/Users/yadev/Github/vistrem/svelte-frontend/.svelte-kit/generated/root.svelte:47:42)
    at eval (/Users/yadev/Github/vistrem/svelte-frontend/src/routes/+layout.svelte:13:41)
    at Object.$$render (/Users/yadev/Github/vistrem/svelte-frontend/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at /Users/yadev/Github/vistrem/svelte-frontend/.svelte-kit/generated/root.svelte:45:40
    at $$render (/Users/yadev/Github/vistrem/svelte-frontend/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at Object.render (/Users/yadev/Github/vistrem/svelte-frontend/node_modules/svelte/src/runtime/internal/ssr.js:164:17)
/Users/yadev/Github/vistrem/svelte-frontend/src/lib/api/auth.api.ts:11
    throw new Error(`Error checking login status: ${error}`);
          ^

Error: Error checking login status: Error: Error fetching data from /v1/auth/: Error: Cannot use relative URL (/v1/auth/) with global fetch — use `event.fetch` instead: https://kit.svelte.dev/docs/web-standards#fetch-apis
    at Module.isLoggedIn (/Users/yadev/Github/vistrem/svelte-frontend/src/lib/api/auth.api.ts:11:11)
    at async checkLoggedIn (/Users/yadev/Github/vistrem/svelte-frontend/src/lib/stores/auth.ts:17:22)

Node.js v20.10.0

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 356.81 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
  Browsers:
    Brave Browser: 123.1.64.122
    Chrome: 115.0.5790.114
    Safari: 17.4.1
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.0 
    @sveltejs/kit: ^2.0.0 => 2.5.7 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.0 
    svelte: ^4.2.7 => 4.2.15 
    vite: ^5.0.3 => 5.2.10

Severity

serious, but I can work around it

Additional Information

No response

herrjemand commented 3 weeks ago

Ref https://github.com/sveltejs/kit/issues/10168

herrjemand commented 3 weeks ago

Ok. This was fixed by putting

export const ssr = true

specifically in the +layout.ts

Shout out to https://github.com/sveltejs/kit/issues/10958