Skip to content

feat: add children route names generic to generated RouteNamedMap and adjust docs and tests #602

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

Merged
merged 13 commits into from
Jun 4, 2025

Conversation

Anoesj
Copy link
Contributor

@Anoesj Anoesj commented Mar 13, 2025

Description

Note

This PR is intended to be paired with the following vue-router PR: vuejs/router#2475.
This PR itself contains a temporary pnpm patch file that applies the changes in above-mentioned PR to work on this feature and make sure you can run tests and generate docs properly. Before merging, this patch needs to be removed and vue-router should be updated if the vue-router PR is merged.

This extends generated RouteRecordInfo objects in RouteNamedMap to make sure every route defines the route names of their children routes. Now useRoute('/parent') can return the typings of both the parent route and its children routes, as can be seen in the example in the adjusted docs:
image

Summary by CodeRabbit

  • New Features

    • Added a preview command for documentation.
    • Improved documentation with expanded TypeScript usage examples and clearer comments.
    • Enhanced route typing to support nested and dynamic child routes.
  • Bug Fixes

    • Corrected route key and path string formats in documentation for accuracy.
  • Refactor

    • Updated route type generation to include child route names as a generic parameter for better type support.
    • Improved internal methods for retrieving and sorting route tree descendants.
  • Tests

    • Added and updated test cases to verify correct handling of nested and dynamic child routes in route maps.

Copy link

pkg-pr-new bot commented Mar 13, 2025

Open in StackBlitz

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

commit: 3b25ce4

Copy link

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.60%. Comparing base (871b304) to head (3b25ce4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #602      +/-   ##
==========================================
+ Coverage   62.36%   62.60%   +0.23%     
==========================================
  Files          32       32              
  Lines        3141     3161      +20     
  Branches      586      592       +6     
==========================================
+ Hits         1959     1979      +20     
  Misses       1177     1177              
  Partials        5        5              

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

Copy link
Contributor Author

@Anoesj Anoesj left a comment

Choose a reason for hiding this comment

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

Just some extra info 😄

@posva posva moved this from 🆕 New to 🏗 In progress in unplugin-vue-router Apr 22, 2025
Copy link

coderabbitai bot commented Apr 24, 2025

Walkthrough

The updates introduce a fifth generic parameter to RouteRecordInfo in the RouteNamedMap interface, representing child route names as a union type where applicable. Type generation logic, TypeScript examples, and related documentation are updated to reflect this. Additional test cases, new routes, and supporting methods for deep child collection are included.

Changes

Files/Groups Change Summary
docs/.vitepress/twoslash-files.ts
docs/.vitepress/twoslash/code/typed-router.ts
Updated RouteNamedMap to add a fifth generic parameter to RouteRecordInfo, denoting child route names or never.
docs/guide/typescript.md
playground/src/router.ts
Expanded RouteNamedMap for dynamic/nested routes with new child route entries and updated usage examples.
docs/introduction.md Moved type imports inside module declaration; updated route keys/paths; added fifth generic parameter as never.
playground/typed-router.d.ts Added fifth generic parameter for child routes; added new routes with corresponding RouteRecordInfo types.
package.json Added docs:preview script, bumped vue-router version, and added pnpm.onlyBuiltDependencies config.
src/codegen/generateRouteMap.ts Refactored to conditionally add a fifth generic parameter for children; logic now collects deep children with names.
src/core/tree.ts Added getSortedChildrenDeep() method; explicitly typed getSortedChildren() return value.
src/codegen/generateRouteMap.spec.ts Added tests for children union in parent route generics; updated snapshots for consistency.
src/utils/index.ts Removed extraneous comment line; no functional changes.

📜 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 16ac1ec and c107ace.

📒 Files selected for processing (2)
  • playground/typed-router.d.ts (2 hunks)
  • src/utils/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/utils/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • playground/typed-router.d.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@posva posva force-pushed the feat/add-child-route-names-in-generated-dts branch from 3696626 to 13706a2 Compare April 25, 2025 13:22
@posva posva moved this from 🏗 In progress to 👀 In review in unplugin-vue-router Jun 4, 2025
@posva posva force-pushed the feat/add-child-route-names-in-generated-dts branch from 13706a2 to d56f127 Compare June 4, 2025 12:13
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.

It took me a while but we are getting there!

>
'custom-dynamic-child-name': RouteRecordInfo<
'custom-dynamic-child-name',
'/added-during-runtime/[...path]/child',
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should improve this example:

  • keep the original [...path] route
  • Add a new one that makes more sense in a nested fashion like /users/[id]/edit
    • Omit /users
    • /users/[id] should have edit as a child

@posva posva merged commit f2fb721 into posva:main Jun 4, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in unplugin-vue-router Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants