fix(nuxt): preserve query parameters in payload extraction for cached routes#34751
fix(nuxt): preserve query parameters in payload extraction for cached routes#34751zowievangeest wants to merge 3 commits into
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughServer renderer URL handling was changed to use the URL API to derive the base pathname and explicitly remove the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/nitro-server/src/runtime/handlers/renderer.ts`:
- Line 112: Remove the invalid assignment to event._path in renderer.ts and keep
only the valid request URL update: delete the expression assigning to
event._path (the left side "event._path") and retain the existing
event.node.req.url = routeUrl assignment so only the supported H3Event property
is updated; look for the statement that sets "event._path = event.node.req.url =
routeUrl" and change it to just "event.node.req.url = routeUrl".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 03af60e7-308f-4484-8b44-00b120e5f1a3
📒 Files selected for processing (2)
packages/nitro-server/src/runtime/handlers/renderer.tspackages/nuxt/src/app/composables/payload.ts
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
Merging this PR will improve performance by 11.55%
Performance Changes
Comparing Footnotes
|
🔗 Linked issue
Resolves #34496
📚 Description
When using
routeRuleswithcacheorisr/swr, payload extraction breaks for routes that depend on query parameters. For example,/items?id=1and/items?id=2both resolve to the same_payload.json, causing hydration mismatches because the client gets the wrong data.It looks like this was introduced in #33467 which extended payload extraction to ISR/SWR cached routes, but the URL construction never accounted for query params.
Someone in the issue mentioned
payloadExtraction: 'client'as a partial fix, but I can confirm it still doesn't work in 3.21.3. The server-side payload URL still strips query params regardless of that setting.What I changed
The root cause is that the build hash was a bare unnamed query parameter (
?abc123), making it impossible to tell apart from actual route query params. I introduced a named_bparameter instead, so the payload URL becomes/items/_payload.json?id=1&_b=abc123rather than/items/_payload.json?abc123.renderer.ts: Uses
_bnamed param for the build hash. TheisRenderingPayloadhandler now parses the URL properly withURLSearchParams.delete('_b')to reconstruct the original page URL with query params intact. Extracted a_buildPayloadURLhelper to keep it clean.payload.ts: Same
_bapproach on the client side for_getPayloadURL. Also added an early return inshouldLoadPayloadfor absolute URLs. Thepayload: trueroute rule from #33467 was causing it to try preloading payloads for full URLs likehttps://example.com/pagefrom<NuxtLink>elements, which always failed.Open question
I chose
_bas the named parameter for the build hash since it's short and unlikely to collide with real query params, but I'm open to a different name or approach if the team has concerns about changing the payload URL format.