fix(nuxt): normalize segment catchall pattern before checking for parent#32413
fix(nuxt): normalize segment catchall pattern before checking for parent#32413
Conversation
|
|
WalkthroughThe changes update the logic in the route generation utility to modify how child routes are identified, specifically by altering the comparison of route paths to account for catch-all or dynamic segments. In the test suite, a new file path representing a nested dynamic route under a catch-all route is added, and the expected route tree structure is updated accordingly to reflect this new child route. No changes were made to the declarations of exported or public entities. ✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/src/pages/utils.ts (1)
145-149: Consider using a global replacement to avoid edge-case mismatches
String.prototype.replacewithout a regex only replaces the first occurrence.
Although having more than one catch-all in a single route is uncommon, nothing strictly prevents a path like/:foo([^/]*)*/bar/:baz([^/]*)*from appearing in the future. Switching toreplaceAll(or a global regex) would guarantee consistent normalisation regardless of the number of occurrences.-const child = parent.find(parentRoute => - parentRoute.name === route.name && - parentRoute.path === path.replace('([^/]*)*', '(.*)*')) +const normalizedPath = path.replaceAll('([^/]*)*', '(.*)*') +const child = parent.find( + parentRoute => + parentRoute.name === route.name && + parentRoute.path === normalizedPath, +)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snapis excluded by!**/*.snappackages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (2)
packages/nuxt/src/pages/utils.ts(1 hunks)packages/nuxt/test/pages.test.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: codeql (javascript-typescript)
- GitHub Check: codeql (actions)
- GitHub Check: build
- GitHub Check: code
🔇 Additional comments (1)
packages/nuxt/test/pages.test.ts (1)
265-285: Good regression coverage for nested catch-all routesAdding
[...slug]/[id].vueand asserting the resultingslug-idchild route convincingly validates the new normalisation logic. This should guard against future regressions in routing hierarchy. 👍
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #32413 will not alter performanceComparing Summary
|
|
thank you ❤️ |
🔗 Linked issue
resolves #32365
📚 Description
When a catch-all route is the last segment, it uses the greedy regexp (#31528). However, if it is used in middle of a path, it uses a more performant regexp (see #31450).
This change normalizes segment paths to the greedy regexp during parent checks to handle cases where both might be present (eg. if
[...id].vueand[...id]/[slug].vueare pages) so that child routes are correctly nested.