Skip to content

fix: remove componentless routes from routes in _RouteFileInfoMap #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Anoesj
Copy link
Contributor

@Anoesj Anoesj commented Aug 7, 2025

Fixes #685

We only checked if deep child routes had a name before adding them to routes in _RouteFileInfoMap. We should have checked whether the deep child route had any corresponding Vue components too.

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Improved variable naming and filtering logic in route mapping for enhanced clarity and reliability.
    • Added new test cases to ensure accurate handling of dynamic and nested routes.

No changes to visible features or user-facing functionality.

Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

Variable names in the route file info map generator were updated for clarity. Filtering logic for route names was tightened to exclude unnamed nodes and nodes without components. Type annotations for route names were added. No changes were made to function signatures or exported entities.

Changes

Cohort / File(s) Change Summary
Route Info Map Variable & Filter Updates
src/codegen/generateRouteFileInfoMap.ts
Renamed variables for clarity, refined route name filtering to exclude unnamed/componentless nodes, added type annotations.
Documentation Comment Update
src/codegen/generateDTS.ts
Updated comments to clarify typing support is provided by sfc-typed-router Volar plugin with formatting improvements.
Test Additions
src/codegen/generateRouteFileInfoMap.spec.ts
Added tests verifying handling of optional/repeatable dynamic segments and nested routes with respect to components and views.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Prevent non-existent route names from being included in _RouteFileInfoMap and _RouteNamesForFilePath (#685)

Suggested reviewers

  • posva

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 a53ecf9 and 0c20a46.

📒 Files selected for processing (2)
  • src/codegen/generateDTS.ts (2 hunks)
  • src/codegen/generateRouteFileInfoMap.spec.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/codegen/generateDTS.ts
🔇 Additional comments (2)
src/codegen/generateRouteFileInfoMap.spec.ts (2)

112-138: Test validates component filtering for dynamic routes.

Good coverage for optional and repeatable dynamic segments with components.


140-171: Test validates nested route aggregation with component filtering.

Properly tests that parent routes aggregate nested route paths while maintaining correct view types.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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 Aug 7, 2025

Open in StackBlitz

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

commit: 0c20a46

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.00%. Comparing base (2d20014) to head (0c20a46).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #686      +/-   ##
==========================================
+ Coverage   60.90%   61.00%   +0.10%     
==========================================
  Files          36       36              
  Lines        3379     3388       +9     
  Branches      618      620       +2     
==========================================
+ Hits         2058     2067       +9     
  Misses       1314     1314              
  Partials        7        7              

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

@Anoesj Anoesj force-pushed the fix/no-componentless-routes-in-route-file-info-map branch from 72882a3 to a53ecf9 Compare August 7, 2025 10:27
Copy link
Owner

@posva posva left a comment

Choose a reason for hiding this comment

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

Can you add a test?

@@ -108,4 +108,65 @@ describe('generateRouteFileInfoMap', () => {
}"
`)
})

it('does not contain routes without components', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@posva This test already passed before my change in generateRouteFileInfoMap.ts

`)
})

it('does not contain nested routes without components', () => {
Copy link
Contributor Author

@Anoesj Anoesj Aug 7, 2025

Choose a reason for hiding this comment

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

@posva But this one only passes after the change in generateRouteFileInfoMap.ts. I don't understand why in this case specifically, the output was wrong. Maybe you can double check if the problem lies elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I think I get it! In generateRouteFileInfoLines(), when running node.getChildrenDeepSorted() for the parent route, that also returns the following routes during this particular test:

  • '/parent/optional'
  • '/parent/optional-repeatable'
  • '/parent/repeatable'

Only after the change I made, those componentless routes are not included in the parent route's routes union in _RouteFileInfoMap.

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.

TS errors in some page components when using auto-typed $route and useRoute (with unplugin-vue-router/volar/sfc-typed-router)
2 participants