Skip to content

fix(unplugin): apply definePage path-param parser overrides#2699

Merged
posva merged 5 commits into
mainfrom
worktree-greedy-enchanting-eagle
May 6, 2026
Merged

fix(unplugin): apply definePage path-param parser overrides#2699
posva merged 5 commits into
mainfrom
worktree-greedy-enchanting-eagle

Conversation

@posva

@posva posva commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix: definePage({ params: { path: { when: 'date' } } }) now applies the parser, matching the filename convention [when=date].vue.
  • Set a path param to null in the override to remove a filename-based parser.
  • TreeNodeValueParam.pathParams is now a getter that overlays the leaf node's params.path override on top of the filename-parsed params.

Test plan

  • New tests in tree.spec.ts under Path param parsers from definePage:
    • Override applies a parser to a plain [when] path param.
    • Override beats the filename parser ([when=int]date).
    • Override on one param leaves siblings untouched.
    • null override removes the filename parser.
  • All 320 unplugin tests pass (pnpm exec vitest run src/unplugin/).

Summary by CodeRabbit

  • New Features

    • Route path parameters can now be explicitly cleared (null) and override filename-derived params; public path params are computed by applying overrides atop filename defaults.
  • Tests

    • Added tests covering path parameter parser overrides, including applying, overriding, and removing filename parsers.

@netlify

netlify Bot commented May 6, 2026

Copy link
Copy Markdown

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 7eaa498
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/69fb42143c00ff00087cd607

@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b2e6b9d-9464-4458-babf-85be253b24a0

📥 Commits

Reviewing files that changed from the base of the PR and between 826efd2 and 7eaa498.

📒 Files selected for processing (2)
  • packages/router/src/unplugin/core/customBlock.ts
  • packages/router/src/unplugin/core/treeNodeValue.ts

📝 Walkthrough

Walkthrough

Path parameter overrides now accept null values to remove filename-derived parsers. The route override type is unified to CustomRouteBlock, and TreeNodeValueParam exposes a computed pathParams getter that overlays definePage overrides onto filename-derived params. Tests validating override and removal behavior were added.

Changes

Path Parameter Override System

Layer / File(s) Summary
Data Shape
packages/router/src/unplugin/core/customBlock.ts
CustomRouteBlock.params.path type changed to Record<string, string | null> and documented to allow null to remove filename parsers.
Public Type / Alias
packages/router/src/unplugin/core/treeNodeValue.ts
RouteRecordOverride replaced by a type alias to CustomRouteBlock, removing the previous interface and related imports/types.
Core Implementation
packages/router/src/unplugin/core/treeNodeValue.ts
TreeNodeValueParam no longer stores public pathParams directly; constructor now takes private filenamePathParams and exposes a getter pathParams() that overlays override values (overrides.params?.path) onto filename-derived params.
Tests
packages/router/src/unplugin/core/tree.spec.ts
Added "Path param parsers from definePage" tests covering applying definePage parsers, overriding filename parsers, partial overrides, and removing filename parsers via null overrides.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through params with care,

nulls cleared paths laid out before,
Overrides stitched atop the file,
Getters show the path awhile,
A tidy route — hop, explore!

🚥 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 clearly and accurately summarizes the main change: applying definePage path-param parser overrides as intended by the pull request.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree-greedy-enchanting-eagle

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.

@pkg-pr-new

pkg-pr-new Bot commented May 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 7eaa498

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.15%. Comparing base (fb818d3) to head (7eaa498).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2699      +/-   ##
==========================================
+ Coverage   86.13%   86.15%   +0.01%     
==========================================
  Files          90       90              
  Lines       10173    10182       +9     
  Branches     2354     2360       +6     
==========================================
+ Hits         8763     8772       +9     
  Misses       1399     1399              
  Partials       11       11              

☔ 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.

@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.

Actionable comments posted: 1

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

1203-1258: ⚡ Quick win

Solid coverage of the new override semantics.

Tests cleanly cover apply, override, partial override, and null-removal. One gap worth considering: none of these tests exercise interaction with another override source (e.g., a convention override applied before a definePage override on the same param). Given the new null sentinel relies on mergeRouteRecordOverride preserving it through multi-source merges, a small test that registers two overrides for the same param via setOverride(CONVENTION_OVERRIDE_NAME, ...) and setOverride('@@edits', ...) would lock down that interaction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/router/src/unplugin/core/tree.spec.ts` around lines 1203 - 1258, Add
a test that verifies a definePage override with null survives when another
override from conventions exists: create a PrefixTree and insert a node (use
PrefixTree and node.insert), call node.setOverride(CONVENTION_OVERRIDE_NAME, {
params: { path: { when: 'int' } } }) to simulate the convention override, then
call node.setCustomRouteBlock(file, { params: { path: { when: null } } }) to
apply the definePage override, and finally assert node.pathParams contains {
paramName: 'when', parser: null }; this ensures mergeRouteRecordOverride
preserves the null sentinel across multi-source merges.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/router/src/unplugin/core/treeNodeValue.ts`:
- Around line 429-437: The constructor signature was changed to a private
filenamePathParams which breaks external instantiation and drops the public
pathParams field; restore compatibility by reverting the third parameter to
public pathParams: TreePathParam[] (match original position/order) and if
internal code needs the filename-named field, assign it inside the constructor
(e.g. this.filenamePathParams = pathParams) or add a getter that returns
pathParams; update the constructor in the class containing constructor(...) and
ensure createTreeNodeValue still supplies the same arguments.

---

Nitpick comments:
In `@packages/router/src/unplugin/core/tree.spec.ts`:
- Around line 1203-1258: Add a test that verifies a definePage override with
null survives when another override from conventions exists: create a PrefixTree
and insert a node (use PrefixTree and node.insert), call
node.setOverride(CONVENTION_OVERRIDE_NAME, { params: { path: { when: 'int' } }
}) to simulate the convention override, then call node.setCustomRouteBlock(file,
{ params: { path: { when: null } } }) to apply the definePage override, and
finally assert node.pathParams contains { paramName: 'when', parser: null };
this ensures mergeRouteRecordOverride preserves the null sentinel across
multi-source merges.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2182abe6-070d-46a8-87b4-4c75043f62c4

📥 Commits

Reviewing files that changed from the base of the PR and between b6346bd and 826efd2.

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

Comment on lines 429 to 437
constructor(
rawSegment: string,
parent: TreeNodeValue | undefined,
public pathParams: TreePathParam[],
private filenamePathParams: TreePathParam[],
pathSegment: string,
subSegments: SubSegment[]
) {
super(rawSegment, parent, pathSegment, subSegments)
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find any other constructor calls or assignments to pathParams on TreeNodeValueParam
ast-grep --pattern 'new TreeNodeValueParam($$$)'
rg -nP '\.pathParams\s*=' --type=ts

Repository: vuejs/router

Length of output: 566


🏁 Script executed:

#!/bin/bash
# Check if TreeNodeValueParam is exported from the package
echo "=== Checking for TreeNodeValueParam exports ==="
rg -n "export.*TreeNodeValueParam" --type=ts

echo -e "\n=== Checking what's in the main entry points ==="
git ls-files | grep -E "(index\.(ts|js|d\.ts)|package\.json)" | head -20

echo -e "\n=== Check if TreeNodeValueParam appears in type definitions ==="
rg -n "TreeNodeValueParam" --type=ts | head -30

Repository: vuejs/router

Length of output: 1616


Constructor signature change — confirm no other call sites.

Switching the third positional parameter from public pathParams to private filenamePathParams is a breaking change for any external code constructing TreeNodeValueParam directly, since this class is exported as part of the public API. The only in-repo caller is createTreeNodeValue (line 615-621), and no other instantiation paths or .pathParams assignments exist in the repository. However, external consumers could be affected by the parameter order change and the field visibility change (now getter-only).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/router/src/unplugin/core/treeNodeValue.ts` around lines 429 - 437,
The constructor signature was changed to a private filenamePathParams which
breaks external instantiation and drops the public pathParams field; restore
compatibility by reverting the third parameter to public pathParams:
TreePathParam[] (match original position/order) and if internal code needs the
filename-named field, assign it inside the constructor (e.g.
this.filenamePathParams = pathParams) or add a getter that returns pathParams;
update the constructor in the class containing constructor(...) and ensure
createTreeNodeValue still supplies the same arguments.

@posva posva merged commit c807486 into main May 6, 2026
9 of 10 checks passed
@posva posva deleted the worktree-greedy-enchanting-eagle branch May 6, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant