Skip to content

feat(extendRoutes): allow relative path overrides #519

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 21 commits into
base: main
Choose a base branch
from

Conversation

robertmoura
Copy link

@robertmoura robertmoura commented Oct 4, 2024

BREAKING CHANGE: allow relative path overrides

Closes #341

  • Support relative paths for EditableTreeNode
  • Require absolute paths at the base of the tree and the root's children
  • Support relative paths in definePage and <route> block

Includes changes from #431

Description

Relative paths in definePage and route block

Relative paths are converted to absolute paths. Here is an example:

src/pages/
├─ custom-root.vue
├─ layout.vue
└─ layout/
	└─ folder-without-layout/
		└─ custom-child.vue

custom-root.vue

// Absolute path is '/i-am-custom'
definePage({
    path: 'i-am-custom',
});

custom-child.vue

// Absolute path is '/layout/i-am-custom'
definePage({
    path: 'i-am-custom',
});

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of relative and absolute custom route paths, ensuring that manual path overrides are resolved correctly in nested routes.
    • Adjusted warnings so that only root-level routes require absolute paths, reducing unnecessary alerts for non-root nodes.
  • Tests
    • Added new test cases to verify correct propagation and computation of overridden paths for both relative and absolute values in nested routes.

Copy link

codecov bot commented Oct 5, 2024

Codecov Report

Attention: Patch coverage is 64.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 68.15%. Comparing base (5741b2a) to head (a930a2d).
Report is 127 commits behind head on main.

Files with missing lines Patch % Lines
src/core/context.ts 35.71% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
+ Coverage   67.56%   68.15%   +0.59%     
==========================================
  Files          31       31              
  Lines        3074     3084      +10     
  Branches      601      611      +10     
==========================================
+ Hits         2077     2102      +25     
+ Misses        991      976      -15     
  Partials        6        6              

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

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

coderabbitai bot commented Apr 22, 2025

Walkthrough

The changes revise how route path overrides are handled in the routing core. The logic for setting and validating custom route paths is updated to allow non-absolute (relative) paths for non-root nodes, and to propagate relative path overrides correctly through the route tree. The warning for non-absolute paths is now limited to root nodes only. Test coverage is added to verify correct path resolution for both relative and absolute overrides in nested routes. Some validation and warning logic is removed or relocated, and internal getters are updated to reflect the new path resolution behavior.

Changes

Files/Areas Changed Change Summary
src/core/context.ts Updates logic to normalize and resolve relative custom route paths against the nearest ancestor route path.
src/core/customBlock.ts Simplifies getRouteBlock by removing path validation and warnings for non-absolute paths.
src/core/extendRoutes.ts Restricts warnings about non-absolute paths to root nodes only; updates warning message accordingly.
src/core/treeNodeValue.ts Updates path getter to prioritize absolute override paths and resolve others relative to parent using joinPath.
src/core/tree.ts Changes fullPath getter to always return the computed path, ignoring any override.
src/core/extendRoutes.spec.ts Adds tests verifying correct handling and propagation of relative and absolute path overrides in nested route structures.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Allow non-absolute (relative) paths in EditableTreeNode (#341)
Restrict warnings about non-absolute paths to root nodes only (#341)
Ensure correct path resolution and propagation for relative overrides (#341)
Remove or relocate unnecessary validation/warnings for non-root nodes (#341)

📜 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 a0b6c27 and 53b21b3.

📒 Files selected for processing (6)
  • src/core/context.ts (2 hunks)
  • src/core/customBlock.ts (1 hunks)
  • src/core/extendRoutes.spec.ts (1 hunks)
  • src/core/extendRoutes.ts (1 hunks)
  • src/core/tree.ts (1 hunks)
  • src/core/treeNodeValue.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/core/extendRoutes.ts (3)
src/core/treeNodeValue.ts (1)
  • path (73-85)
src/core/tree.ts (1)
  • path (187-192)
src/core/utils.ts (1)
  • warn (10-15)
src/core/customBlock.ts (3)
src/core/treeNodeValue.ts (1)
  • path (73-85)
src/core/extendRoutes.ts (2)
  • path (137-139)
  • path (144-155)
src/core/tree.ts (1)
  • path (187-192)
src/core/context.ts (2)
src/core/extendRoutes.ts (1)
  • parent (63-65)
src/core/utils.ts (1)
  • joinPath (111-120)
🔇 Additional comments (7)
src/core/tree.ts (1)

197-199: Path resolution simplified.

The getter now delegates path resolution logic to the path getter in TreeNodeValue class, which handles both absolute and relative paths appropriately.

src/core/customBlock.ts (1)

16-16: Path validation simplified appropriately.

The function now directly returns the parsed route block without validating that paths start with a slash, supporting the relative path feature.

src/core/extendRoutes.ts (1)

144-155: Warning correctly restricted to root-level routes.

This change enforces absolute paths only at the root level while allowing relative paths for child routes. The validation condition has been updated to check if the node has no parent or if its parent is the root node.

src/core/context.ts (2)

4-4: Added joinPath import for path manipulation.

The import is now used to properly join parent paths with relative paths.


118-138: Added support for relative path resolution.

The implementation correctly:

  1. Merges route overrides from multiple sources
  2. Detects relative paths (those not starting with /)
  3. Finds the nearest ancestor with components
  4. Joins the parent path with the relative path to create a properly resolved absolute path

This implementation aligns with the PR objective of supporting relative path overrides.

src/core/treeNodeValue.ts (1)

73-85: Improvement: Enhanced path resolution logic supports absolute and relative overrides

The updated path getter now correctly prioritizes absolute paths (starting with /) from overrides while maintaining support for relative paths. This change enables the relative path override feature mentioned in the PR objectives.

src/core/extendRoutes.spec.ts (1)

255-272: Good test for path override functionality

This test confirms that:

  1. Root-level routes maintain absolute paths
  2. Child routes can use relative paths that resolve against their parent
  3. Absolute paths in child nodes override their location in the hierarchy

The test correctly verifies both the relative and absolute path override behaviors.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

Support non absolute paths in EditableTreeNode
2 participants