Skip to content

fix(unplugin): generate param types from override paths and stop inheritance on absolute overrides#2646

Open
G100my wants to merge 2 commits into
vuejs:mainfrom
G100my:main
Open

fix(unplugin): generate param types from override paths and stop inheritance on absolute overrides#2646
G100my wants to merge 2 commits into
vuejs:mainfrom
G100my:main

Conversation

@G100my

@G100my G100my commented Feb 27, 2026

Copy link
Copy Markdown

I discovered this problem while migrating from vite-plugin-pages.

Problem

When overriding route path via <route> or definePage():

  1. Params from the override path are not always reflected in generated types.
  2. Absolute override paths (/-prefixed) can still inherit ancestor params/query in types, producing invalid keys.

Solution

  1. Infer path params directly from override path, including:
    • optional: :id?
    • repeatable: :id+ / :id*
    • splat: :id(.*)
  2. Apply params.path parser overrides to inferred params.
  3. Treat absolute override paths as inheritance boundaries:
    • stop inheriting ancestor params/query above that node.
  4. Keep relative override paths inheriting parent params/query as-is.

Summary by CodeRabbit

  • Tests

    • Added tests for path override behavior and parameter extraction, including optional/repeatable/splat cases.
  • Bug Fixes

    • Absolute path overrides no longer inherit parent params; relative overrides continue to inherit.
    • Stopping inheritance at the nearest absolute override boundary.
    • Improved extraction and application of path param metadata when overrides are combined.

@coderabbitai

coderabbitai Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f48d8bec-2608-4051-94c4-dfffc0165c20

📥 Commits

Reviewing files that changed from the base of the PR and between 0d92139 and 3ae6443.

📒 Files selected for processing (3)
  • packages/router/src/unplugin/core/tree.spec.ts
  • packages/router/src/unplugin/core/tree.ts
  • packages/router/src/unplugin/core/treeNodeValue.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/router/src/unplugin/core/treeNodeValue.ts
  • packages/router/src/unplugin/core/tree.spec.ts

📝 Walkthrough

Walkthrough

Adds parsing and merging of path params when a route provides an explicit overrides.path, applies per-param parser overrides, and enforces inheritance semantics where absolute overrides.path values stop parent param inheritance while relative overrides continue inheriting.

Changes

Path override and params extraction

Layer / File(s) Summary
Data Shape / Helper
packages/router/src/unplugin/core/treeNodeValue.ts
Adds _TreeNodeValueBase.getPathParams() and changes params to build from getPathParams() + queryParams. getPathParams() parses overrides.path segments into TreePathParam[] and applies per-param overrides.params?.path parser overrides.
Core Logic
packages/router/src/unplugin/core/tree.ts
Imports isTreePathParam. TreeNode.params and TreeNode.pathParams now derive path params via filtered isTreePathParam, early-return when the node has an absolute overrides.path (starts with /), and stop parent traversal at an ancestor with an absolute override.
Tests
packages/router/src/unplugin/core/tree.spec.ts
Adds path override and params extraction test suite with cases for: recreating missing params from overrides.path; preserving parser/optional/repeatable/splat metadata including parser overrides; and verifying absolute vs relative override inheritance boundaries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • posva

Poem

🐰 I nibble path strings, parse each little part,

Absolute roots stand firm, relatives share their heart.
Parsers tucked and labeled, params hop in line,
Inherited or overridden, each segment does shine.
Hop on, tidy routes — the tree grows by design.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: generating param types from override paths and stopping inheritance on absolute overrides, which directly addresses both problems and solutions outlined in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@netlify

netlify Bot commented Feb 27, 2026

Copy link
Copy Markdown

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 3ae6443
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/69f9779de4d8560008090ddc

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/router/src/unplugin/core/treeNodeValue.ts (1)

171-178: Cache merged overrides once inside getPathParams().

this.overrides is recomputed on each access (sort + merge). Reusing one local object avoids duplicate work and clarifies intent.

Proposed refactor
   getPathParams(): TreePathParam[] {
-    const overridePath = this.overrides.path
+    const overrides = this.overrides
+    const overridePath = overrides.path

     if (!overridePath) {
       return this.isParam() ? [...this.pathParams] : []
     }

-    const overrideParsers = this.overrides.params?.path ?? {}
+    const overrideParsers = overrides.params?.path ?? {}
     const params: TreePathParam[] = []
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/router/src/unplugin/core/treeNodeValue.ts` around lines 171 - 178,
In getPathParams(), avoid re-evaluating the costly computed property
this.overrides multiple times: cache it into a local const (e.g., const
overrides = this.overrides) at the top of the method and then use overrides.path
and overrides.params?.path instead of re-accessing this.overrides; keep existing
logic that checks overridePath and builds params (referencing overridePath,
overrideParsers, TreePathParam, and this.pathParams) but read from the cached
overrides to prevent duplicate sort/merge work.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/router/src/unplugin/core/treeNodeValue.ts`:
- Around line 171-178: In getPathParams(), avoid re-evaluating the costly
computed property this.overrides multiple times: cache it into a local const
(e.g., const overrides = this.overrides) at the top of the method and then use
overrides.path and overrides.params?.path instead of re-accessing
this.overrides; keep existing logic that checks overridePath and builds params
(referencing overridePath, overrideParsers, TreePathParam, and this.pathParams)
but read from the cached overrides to prevent duplicate sort/merge work.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d11a7de and a4a206c.

📒 Files selected for processing (3)
  • packages/router/src/unplugin/core/tree.spec.ts
  • packages/router/src/unplugin/core/tree.ts
  • packages/router/src/unplugin/core/treeNodeValue.ts

@G100my G100my changed the title unplugin: generate param types from override paths and stop inheritance on absolute overrides fix(unplugin): generate param types from override paths and stop inheritance on absolute overrides Feb 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Mar 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/vue-router@2646

commit: 0d92139

@codecov

codecov Bot commented Mar 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.62%. Comparing base (71fdbf3) to head (0d92139).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2646      +/-   ##
==========================================
+ Coverage   85.58%   85.62%   +0.04%     
==========================================
  Files          86       86              
  Lines        9960     9989      +29     
  Branches     2285     2304      +19     
==========================================
+ Hits         8524     8553      +29     
  Misses       1423     1423              
  Partials       13       13              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

} satisfies Partial<TreePathParam>)
})

describe('path override and params extraction', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy pasted these tests in main and they all pass. Could you provide one failing test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried copy-pasting the tests directly onto main, but they fail on my end.

I force-pushed an updated version that splits the changes into two commits:

  • the first one only adds the tests,
  • and the second one contains the actual code changes.

Hopefully this makes it easier to verify without having to copy and paste the tests manually.
I also reworked the tests a bit to make them more focused.

@github-project-automation github-project-automation Bot moved this to 🆕 Triaging in Vue Router Roadmap May 5, 2026
@posva posva moved this from 🆕 Triaging to 📆 Planned in Vue Router Roadmap May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📆 Planned

Development

Successfully merging this pull request may close these issues.

2 participants