Skip to content

Conversation

danielroe
Copy link
Member

🔗 Linked issue

📚 Description

this improves catchall pattern to avoid polynomial/exponential backtracking when used in the middle of a route pattern (e.g. ~/pages/[...id]/other) which in any case is an anti-pattern I would strongly advise avoiding.

@danielroe danielroe requested a review from posva March 19, 2025 13:35
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

This pull request introduces changes to the getRoutePath function by adding a new boolean parameter, hasSucceedingSegment, which defaults to false. This parameter modifies the regex pattern for catch-all segments, allowing it to match differently based on the presence of succeeding segments. The generateRoutesFromFiles function is updated to pass this new parameter and replace the variable path with routePath, reflecting the updated logic for route path construction. Additionally, a new test case is added to validate the functionality of generating routes with catch-all parameters positioned in the middle of a path, ensuring performance optimisation. Lastly, a new entry for the temp directory is added to the .gitignore file to prevent it from being tracked by version control. No alterations were made to the declarations of exported or public entities.

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56212de and 9e1d0db.

⛔ Files ignored due to path filters (2)
  • packages/nuxt/test/__snapshots__/pages-override-meta-disabled.test.ts.snap is excluded by !**/*.snap
  • packages/nuxt/test/__snapshots__/pages-override-meta-enabled.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • packages/nuxt/src/pages/utils.ts (4 hunks)
  • packages/nuxt/test/pages.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxt/test/pages.test.ts
  • packages/nuxt/src/pages/utils.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: build
  • GitHub Check: code

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Mar 19, 2025

Open in Stackblitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@31450

nuxt

npm i https://pkg.pr.new/nuxt@31450

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@31450

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@31450

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@31450

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@31450

commit: 9e1d0db

Copy link

codspeed-hq bot commented Mar 19, 2025

CodSpeed Performance Report

Merging #31450 will not alter performance

Comparing fix/catchall-pattern (9e1d0db) with main (7a4cdbc)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe merged commit 726c029 into main Mar 19, 2025
46 checks passed
@danielroe danielroe deleted the fix/catchall-pattern branch March 19, 2025 15:05
@github-actions github-actions bot mentioned this pull request Mar 19, 2025
@github-actions github-actions bot mentioned this pull request Mar 19, 2025
@vsergiu93
Copy link

Hi @danielroe ,

TL;DR: After upgrading from Nuxt 3.15.4 to 3.17.5, nested catch-all routes are no longer being grouped as children but are instead being flattened into separate top-level routes, breaking our existing URL structure.

I'm not directly opening a new issue, because I first want to understand if this is really an issue that needs to be fixed on the Nuxt side.

We have the following structure:

pages/
├── [...layout].vue
├── [...layout]/
│ ├── index.vue
│ └── page-[page].vue

This would have generated something like this in 3.15.4 :

[
  {
    "children": [
      {
        "children": [],
        "file": "/[...layout]/index.vue",
        "name": "layout",
        "path": ""
      },
      {
        "children": [],
        "file": "/[...layout]/page-[page].vue",
        "name": "layout-page-page",
        "path": "page-:page()"
      }
    ],
    "file": "pages/[...layout].vue",
    "path": "/:layout(.*)*"
  }
]

Now in 3.17.5 it generates the following:

[
  {
    "children": [
      {
        "children": [],
        "file": "/[...layout]/index.vue",
        "name": "layout",
        "path": ""
      }
    ],
    "file": "/[...layout].vue",
    "path": "/:layout(.*)*"
  },
  {
    "children": [],
    "file": "/[...layout]/page-[page].vue",
    "meta": undefined,
    "name": "layout-page-page",
    "path": "/:layout([^/]*)*/page-:page()"
  }
]

As you can see, the page-[page].vue is not added as a child of [...layout].vue anymore. What I'm not really sure about is if this change was intentional or if only the regex pattern was supposed to be modified.

The issue: This breaks our existing route structure where /some-category/page-20 should match the catch-all parent with the page child, but now it tries to match the flattened route pattern instead.

Basically, as it stands now I can't upgrade. Changing the URL structure isn't possible since our URLs are dynamically controlled by a CMS where admins can configure arbitrary layout/page combinations. We rely on the flexible nested catch-all routing structure to handle these dynamic CMS-generated routes.

Please let me know if I should open an issue or if this was intended, thanks.

@danielroe
Copy link
Member Author

you are right, this is a bug

i believe there is an existing issue but it did not identify the cause, so it might be difficult to find

@vsergiu93
Copy link

vsergiu93 commented Jun 5, 2025

@danielroe I think the issue is here, I cloned the repo and I'm playing around, basically I added this lines to pages.test.ts:

[
  { path: `${pagesDir}/[...sub].vue` },
  { path: `${pagesDir}/[...sub]/index.vue` },
  { path: `${pagesDir}/[...sub]/route-[slug].vue` }
]

Then I run the test in debug mode, I allow the first two entries to be processed which seems to correctly group them as parent child routes

image

After a few steps we get here:

image

The Problem:
When processing [...sub]/route-[slug].vue, the algorithm tries to find a parent route to attach it to. However, it's looking for an exact path match between:

  • Expected parent path: /:sub([^/]*)*
  • Actual parent path: /:sub(.*)*

Since these don't match exactly, the algorithm fails to recognize the parent-child relationship and creates the route as a separate top-level route instead of nesting it under the catch-all parent.

I have no idea how to actually fix it though.

Thanks

@vsergiu93
Copy link

Hello @danielroe ,

Let me know if you want me to create a new issue (I searched through the currently open issues, but I was unable to find one where I can reference my comments).

Thanks

@danielroe
Copy link
Member Author

@vsergiu93 please do 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants