fix(router-core): stringify parent params for missing route templates - #7897
fix(router-core): stringify parent params for missing route templates#7897xianjianlf2 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesRouter parent canonicalization
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Fixes #7877.
When Start prunes a server-only leaf route from the client route tree, a client-side
buildLocation()call for that route template cannot find an exactroutesByPathentry. The current fallback leavesdestRoutesempty for route templates, so parentparams.stringifyhooks are skipped and the generated href can differ from SSR.This keeps exact route-template matches unchanged, but when a template is missing it falls back to the longest known parent route branch. That gives parent routes a chance to canonicalize path params while still leaving the server-only leaf absent from the client route tree.
The regression test models the client route tree after a server-only child was pruned: only
/$postTypeexists locally, while a link is built for/$postType/$postId/download. The parent stringify mapsarticleback to the canonicalarticlessegment.Tests run:
PATH=/opt/homebrew/bin:$PATH pnpm --dir packages/history buildPATH=/opt/homebrew/bin:$PATH pnpm --dir packages/router-core test:unit --run tests/build-location.test.ts -t "matched parent of a missing route template"PATH=/opt/homebrew/bin:$PATH pnpm --dir packages/router-core test:unit --run tests/build-location.test.tsPATH=/opt/homebrew/bin:$PATH pnpm --dir packages/router-core test:unitPATH=/opt/homebrew/bin:$PATH pnpm --dir packages/router-core test:types:ts70PATH=/opt/homebrew/bin:$PATH pnpm --dir packages/router-core test:eslintPATH=/opt/homebrew/bin:$PATH pnpm exec prettier --check packages/router-core/src/router.ts packages/router-core/tests/build-location.test.tsNote:
test:eslintexits 0 with existing warnings in unrelated router-core files.Summary by CodeRabbit
/articles/1/download.