Open coryvirok opened 1 year ago
FWIW I ran into this issue waaaaay back in like v250 of the beta (back when building
was prerendering
or something) and had the same confusing experience. I'm not sure what the best way to communicate this is, but I definitely felt the pain.
Describe the bug
I'm not sure if this is a bug or not but I was confused by it so maybe we need a docs update.
The issue is that even though
+layout.js
exportsexport const prerender = false
the build step will invokehooks.server.js
with the URL. If there is logic in thehooks.server.js#handle()
function that is not prerenderable, (e.g. accessingevent.url.search
) the build will fail.I assumed that since the layout disabled prerendering for its page tree,
handle()
would not even be invoked.I think it's pretty common to have non-prerenderable code in
hooks.server.js
. In my case, I check auth and then redirect to/login?next=PATH_AND_SEARCH_OF_ORIGINAL_URL
which breaks prerender.The workaround is to check
building
inhooks.server.js
before doing anything non-prerenderable. This probably deserves a mention in the docs sincehandle()
will be invoked even for non-prerenderable URLs.Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-dapyhy?file=src/hooks.server.js
Run
npm run build
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response