-
-
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
Navigating from prerendered page to non-prerendered page does not trigger hooks #4426
Comments
Ah, interesting! I wonder what the ideal solution is when landing on a prerendered page:
The first option means wasted requests for visits that don't involve non-prerendered pages, and also means that we need to be able to distinguish between static sites and those that can dynamically render stuff (though it could be as simple as requesting The second option slows down the first navigation; the third option slows down the first navigation to a non-prerendered page, and also requires the client-side router to distinguish between prerendered and non-prerendered pages. |
FWIW, the third option is the way I thought it worked from reading the docs. |
How can I work around this? I am facing this issue with my dashboard. In my hook, I decode my JWT token and store the user in locals.user but when I redirect to my dashboard after login, I have to reload the page in order for the user info to appear in the navbar. note: In the navbar I use |
@hessel-bb - Did the |
Looks like #4545 will also provide another possible workaround, setting a |
👋🏻 I'd just like to chime in here and say I've run into this same issue! I almost opened a ticket for it awhile back, but wasn't sure if this was intended behavior or not. I'm currently using Right now I'm just calling Also, I think there are similar discussions happening over in #3722 and #1726. |
Also chiming in :) Wouldn't it be possible to include the I think this would solve a bunch of problems, including the ones above as well as #1726. It would also make calls to |
I am also struggling with this, I thought it was my code that messed up 🙃 |
Describe the bug
When a site has a mix of prerendered and non-prerendered pages, if the first page a client lands on is a prerendered page,
getSession
will not be called when the client navigates to a non-prerendered page.This means that if you have a site with a landing page (which is the same for all users) and personalized content (log in to save your todo lists), prerendering becomes a trap. Because if you use
getSession
to look up the users' data in the database and load their todo lists, that will break as soon as you decide to prerender your landing page.Reproduction
https://github.com/rmunn/prerender-and-hooks-repro
Run
pnpm run dev
, then go to/
first, which is prerendered. Then click on the navigation link to/userpage
, and notice thatgetSession
is not called, so the user page would not be able to present its personalized content.Navigating directly to
/userpage
works.Logs
System Info
Severity
serious, but I can work around it
Additional Information
I can work around this by adding
router = false
to the landing page which I've marked asprerender = true
. But the current behavior, where prerendering one page changes the behavior of a different page (whosehandle
andgetSession
hooks no longer run) seems wrong to me. The https://kit.svelte.dev/docs/hooks documentation is quite clear that hooks for prerendered pages run at build time, but I expected that that meant thathandle
andgetSession
hooks would only run for non-prerendered pages, not that they would never run at all if a prerendered page was the first page visited on the site.So either this is a bug, or it's a case of unclear documentation.
The text was updated successfully, but these errors were encountered: