Skip to content
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

test: earlier routes should have matching priority #2138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

skirtles-code
Copy link
Contributor

My initial attempt at #2137 passed all the existing unit tests, but with hindsight it fails to take account of various important cases.

This PR attempts to add test cases for one of those problem cases. e.g. Consider the following code:

routes: [
  {
    path: '/user/:id(1\\d*)',
    component: {}
  }, {
    path: '/user/:id(\\d+)',
    component: {}
  }
]

The path ranking gives these routes the same score. For a path of /user/1234, both would be eligible to match, but we would want the first route to match. The ordering matters, the earlier route needs to be given priority.

I'm not clear whether this is documented anywhere, but I think it's a reasonable assumption and something that people are likely to be relying upon, even though they may not realise it.

My attempt at using a binary search in #2137 to sort the routes broke this assumption, leading to routes with equal scores being in an essentially random order. I believe that PR is fixable, but these extra tests can be merged independently.

Copy link

netlify bot commented Feb 11, 2024

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 985e1f1
🔍 Latest deploy log https://app.netlify.com/sites/vue-router/deploys/65c8d4fbf9bc860008043d92

@codecov-commenter
Copy link

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (2df32af) 90.85% compared to head (985e1f1) 90.88%.
Report is 9 commits behind head on main.

Files Patch % Lines
packages/router/src/navigationGuards.ts 88.88% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2138      +/-   ##
==========================================
+ Coverage   90.85%   90.88%   +0.03%     
==========================================
  Files          24       24              
  Lines        1115     1119       +4     
  Branches      347      347              
==========================================
+ Hits         1013     1017       +4     
  Misses         63       63              
  Partials       39       39              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@posva
Copy link
Member

posva commented Feb 13, 2024

I'm not clear whether this is documented anywhere, but I think it's a reasonable assumption and something that people are likely to be relying upon, even though they may not realise it.

It's reasonable, but I also think one should never have this kind of routes (conflicting routes) precisely because the behavior can be unpredictable. So, I intentionally never documented it. The current sorting order is indeed stable, but I would say one should not rely on this so I feel reluctant to add such test cases.

I think there are safer paths to not change the current matcher behavior. I should post these thoughts on the other PRs

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.

None yet

3 participants