vike: Missing query parameters in pageContext.urlOriginal with prerendering
Description
Using prerendering during production, the pageContext.urlOriginal doesn’t load the query parameters.
Reproduction
- clone https://github.com/templates-ecosystem/template-vike-solid-daisyui-hono#no-query
yarnyarn buildyarn prod- Go to
http://localhost:3000/?a=1 - The page output is
urlOriginal: /instead ofurlOriginal: http://localhost:3000/?a=1
Results
| Start command | Value of +config.prerender |
Page URL | Actual value of pageContext.urlOriginal |
Expected value of pageContext.urlOriginal |
It works? |
|---|---|---|---|---|---|
yarn dev |
true |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
Yes |
yarn dev |
true |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
Yes |
yarn dev |
false |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
Yes |
yarn dev |
false |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
Yes |
yarn build && yarn prod |
true |
http://localhost:3000/?a=1 |
/ |
http://localhost:3000/?a=1 |
No |
yarn build && yarn prod |
true |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
Yes |
yarn build && yarn prod |
false |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
http://localhost:3000/?a=1 |
Yes |
yarn build && yarn prod |
false |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
http://localhost:3000/user/userId1?a=1 |
Yes |
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (21 by maintainers)
Commits related to this issue
- docs: further clarify `pageContext` upon-prerendering and mention workarounds (#2185) — committed to vikejs/vike by brillout 2 years ago
Thank you for circling back on this. Indeed, we should improve the documentation around this. My plan is to further explore the
onHydrationEnd()workaround in the context of https://github.com/vikejs/vike/issues/1476 and, then, add a new sectionvike.dev/pre-rendering#dynamic-routesand make the inherent limitation as crystal clear as possible.You cannot pre-render a page that has dynamic content, right? That’s impossible.
So either don’t pre-render it, or use the
onHydrationEnd()workaround. I don’t think anything else makes sense here, right?Please thoroughly read the note about hydration mismatches at https://vike.dev/pageContext#pre-rendering.
Sorry for confusing, after some analysis, the issue and the test cases are now clear. I updated the main comment with a table to recap all behaviors/tests. In the table there is only 1 row of the case that doesn’t work. Tell me if you need more details or anything. Thanks for the help.
https://vike.dev/pageContext#pre-rendering but feel free to elaborate your use case.