Skip to content

feat(unplugin): allow null filePath for editable tree routes - #2748

Open
Anoesj wants to merge 2 commits into
vuejs:mainfrom
Anoesj:feat/nullable-filepath-editable-tree
Open

feat(unplugin): allow null filePath for editable tree routes#2748
Anoesj wants to merge 2 commits into
vuejs:mainfrom
Anoesj:feat/nullable-filepath-editable-tree

Conversation

@Anoesj

@Anoesj Anoesj commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Ported from posva/unplugin-vue-router#607

It seems that, when we only allow filePath to be null on a route added in an editable tree, that shouldn't cause any problems.

In Nuxt, we don't use file scanning and add routes by modifying the EditableTreeNode of the root page in the beforeWriteFiles callback. It's possible for a NuxtPage not to have a corresponding file: modules can push routes through the pages:extend hook without one (virtual, grouping, or redirect routes), and Nuxt's own type fixtures do this. So where we run parent.insert(path, page.file), page.file can be missing, and we currently use a @ts-expect-error before that line to suppress TS errors.

Nuxt follow-up (not part of this PR)

  • Pass page.file ?? null in addPage, then remove the @ts-expect-error.

Summary by CodeRabbit

  • New Features

    • Route tree entries can now be created without an associated file path.
    • Such entries are correctly recognized as pass-through routes.
  • Bug Fixes

    • Improved route metadata handling when no component file is provided.
  • Tests

    • Added coverage verifying pass-through route creation, path assignment, and child node behavior.

Port posva/unplugin-vue-router#607. `EditableTreeNode.insert()` and
`TreeNode.insertParsedPath()` now accept `filePath: string | null`, and a
default component is only registered when `filePath != null`. This allows
creating pass-through routes via the editable tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 252dea5
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/6a58b7f215bf390008b6ea3a

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 252dea5

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Route tree insertion now accepts null file paths, represents those nodes as non-components, and adds coverage for inserting a route without a file path.

Changes

Nullable route file paths

Layer / File(s) Summary
Route tree insertion support
packages/router/src/unplugin/core/tree.ts, packages/router/src/unplugin/core/extendRoutes.ts, packages/router/src/unplugin/core/extendRoutes.spec.ts
insertParsedPath and EditableTreeNode.insert accept string | null; null file paths produce non-component nodes, with a test confirming route creation.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: allowing null filePath values for editable tree routes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

@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/extendRoutes.spec.ts (1)

38-45: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert that the nullable route is non-component.

This test currently verifies only insertion and path creation; it would still pass if null were incorrectly registered as a component. Add an assertion for the intended pass-through behavior.

Proposed test addition
     editable.insert('foo', null)
     expect(editable.children).toHaveLength(1)
     expect(editable.children[0]?.path).toBe('/foo')
+    expect(editable.children[0]?.isPassThrough).toBe(true)
🤖 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/extendRoutes.spec.ts` around lines 38 - 45,
Extend the test for EditableTreeNode.insert with a null filePath to assert that
the created route is non-component, using the route/component property exposed
by editable.children[0]. Preserve the existing child-count and path assertions
while verifying null passes through without component registration.
🤖 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.

Nitpick comments:
In `@packages/router/src/unplugin/core/extendRoutes.spec.ts`:
- Around line 38-45: Extend the test for EditableTreeNode.insert with a null
filePath to assert that the created route is non-component, using the
route/component property exposed by editable.children[0]. Preserve the existing
child-count and path assertions while verifying null passes through without
component registration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 532d7142-84de-4fa7-9d07-33b8cb7e26be

📥 Commits

Reviewing files that changed from the base of the PR and between 1653533 and a7e71c0.

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

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.93%. Comparing base (1653533) to head (252dea5).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2748      +/-   ##
==========================================
+ Coverage   86.91%   86.93%   +0.01%     
==========================================
  Files          93       93              
  Lines       10715    10715              
  Branches     2474     2476       +2     
==========================================
+ Hits         9313     9315       +2     
+ Misses       1396     1394       -2     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 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.

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