-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle hook doesn’t run on prerendered pages or static content in production #1862
Comments
I assume that when a page is rendered in the browser, then the Node server is not called and the However, I wasn’t able to call the |
Hi, which other routes do you have? If you are using parameterized routes (e.g. [slug]), you need to add the paths to kit.prerender.pages in |
My issue doesn't relate to prerendering (at least not directly). In fact, I don't want to prerender anything. The problem I ran into is that the |
Ok, I’ve made some progress.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I spent some more time looking into this and I think I found the cause. The node adapter uses polka to process requests, passing each through a series of middleware. The final middleware calls the Two preceding middleware functions are |
@malinowskip can you clarify what your use case is? I asked Rich about this and he suggested it was working as intended. After a page has been rendered, is it still useful to call We would at least need to update the docs though. Right now the first sentence is "this function runs on every request", which isn't strictly true |
Thanks, @benmccann. I was originally exploring SvelteKit’s client/server-side capabilities and tried to use the
Yes, I agree. After initially reading the docs, I assumed that |
You're almost certainly won't prerender a page that can be logged into. If you want to display the logged in user, or a logout button, or anything else that might differ between visits then you can't prerender it
Hmm, yeah, that is a really good use case we should figure out how to support |
I think the best way to support that use case will be to use your adapter. E.g. for |
Thanks, I think that clarifies everything. The ability to add middleware to each request would be a cool feature to have in the future. |
Describe the bug
The
handle
hook is not called when the app is built using thenode
adapter and when the server is run directly via node:node build/index.js
.To Reproduce
npm init svelte@next my-app
.node
adapter:yarn add -D @sveltejs/adapter-node
.node()
in./svelte.config.js
inconfig.kit.adapter
.handle
function insrc/hooks
.yarn build
If you run the application using
node build/index.js
, the hook is triggered only when you navigate to the/todos
route.Expected behavior
Things work correctly if you run the app with
yarn preview
, i.e. the hook is called on every page and on every refresh. I assume that this is the expected behavior.Severity
This seems to break hooks in production.
Additional context
I haven’t tested this with other adapters.
Also doesn't work with static pages: #2060
The text was updated successfully, but these errors were encountered: