bug(frontend): SvelteKit prerender-crawl bakes redirect-to-login into static HTML for protected routes (HIGH, prod-blocking) #514
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
svelte.config.jslists/hilfe/transkriptionas a prerender entry. SvelteKit's defaultprerender.crawl = truethen follows nav links from that page and tries to prerender/,/documents,/persons,/geschichten,/stammbaum, … Those routes'loadfunctions throwredirect(302, '/login')when the build-time request has no auth cookie. SvelteKit captures that redirect and emits a static HTML file:These prerendered files (
build/prerendered/index.html,build/prerendered/documents.html, etc.) are served before the runtimehooks.server.tsever runs. So an authenticated user with a validauth_tokencookie still gets the static "redirect to /login" response — every time, forever.Reproduction (on staging right now)
Why local dev works
Vite dev mode doesn't prerender — every request runs through the real handle chain. The bug only manifests in
npm run buildoutput.Impact
/), but/serves the baked bounce-back HTML and they appear stuck on/login./hilfe/transkription(the only intentional prerender entry).Fix
With
crawl: false, SvelteKit only prerenders the explicit entries. The dynamic routes will not be touched at build time.Discovered
Deploying staging via #497 / #499. Cookie was set correctly, backend accepted the credentials, but every page in the browser bounced back to
/login. Inspecting the production build artifacts found the baked HTML files.