You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 exports export const prerender = false the build step will invoke hooks.server.js with the URL. If there is logic in the hooks.server.js#handle() function that is not prerenderable, (e.g. accessing event.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 in hooks.server.js before doing anything non-prerenderable. This probably deserves a mention in the docs since handle() will be invoked even for non-prerenderable URLs.
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
The text was updated successfully, but these errors were encountered: