Description
Describe the bug
With the following conditions:
- SPA mode enabled (ssr = false in +layout.ts)
- A redirect from the load function in +layout.ts
- An unknown route (e.g. '/bad_route`)
Expected Behavior: It either redirects or the error page shows up.
Actual Behavior: Neither the error page nor the redirect works. Instead nothing loads at all.
Notes
In the actual case where I encountered this, the redirect was to a login page when we detect that the user is not logged in.
This behavior happens either on initial load or from a client-side navigation, but only when SSR is disabled.
The redirect shows up in the console as an uncaught rejection, which hints at it maybe starting the layout load function but not actually awaiting it once it can't find a page? I haven't looked into it more yet though.
Workaround
Avoid throwing the redirect if route.id
is empty. Might not work for unexpected errors though?
Reproduction
https://github.com/dimfeld/sveltekit-redirect-on-404
Load the app at http://localhost:5173/bad_route
or click the bad route link from the login page, and see that nothing shows up at all.
Logs
No response
System Info
System:
OS: macOS 14.1
CPU: (16) arm64 Apple M3 Max
Memory: 58.39 GB / 128.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - /opt/homebrew/bin/node
Yarn: 1.22.21 - ~/.pnpm/yarn
npm: 10.1.0 - /opt/homebrew/bin/npm
pnpm: 8.10.5 - ~/.pnpm/pnpm
bun: 1.0.13 - /opt/homebrew/bin/bun
Browsers:
Brave Browser: 119.1.60.118
Safari: 17.1
npmPackages:
@sveltejs/adapter-auto: ^1.0.0-next.90 => 1.0.3
@sveltejs/kit: ^1.0.0-next.587 => 1.27.6
svelte: ^3.54.0 => 3.59.2
vite: ^4.0.0 => 4.5.0
Severity
serious, but I can work around it
Additional Information
No response