-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
fix: place root route at the end #5645
Conversation
✔️ [V2] 🔨 Explore the source changes: 7e866d0 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/615d8949bdbba200073e46a8 😎 Browse the preview: https://deploy-preview-5645--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-5645--docusaurus-2.netlify.app/ |
Size Change: -4 B (0%) Total Size: 834 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test snapshot highlights the sort algo is wrong.
I suggest improving test case to ensure "/" with subroute is the very last item after sorting
}, | ||
Object { | ||
"component": "", | ||
"path": "/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not in the correct place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is intentional, sorting by root routes first makes it easier to sort by root routes. After all, it doesn't really matter where just root route is, as long as root route with subroutes is placed at the last. But I moved new sorting to the beginning as you asked, probably it is better for consistency as well.
@@ -47,6 +47,11 @@ export function sortConfig(routeConfigs: RouteConfig[]): void { | |||
} | |||
} | |||
|
|||
// Root route should get placed last. | |||
if (a.path === '/' || b.path === '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is probably good enough, cf snapshot order.
If a !== "/" && b === "/" it should rather return +1
It should work better to do this test at the very beginning of the sort algo instead of the end.
Note if both are "/", we should not return because the route with "/" + subroutes should be the very last
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, done.
Thanks, that seems good enough to fix the issue above. modified the test for a better coverage of a edge case IMHO we still have a problem that we should try to solve: if blog and docs both use We should probably implement our own This logic may not be good enough in our case: |
Not urgent, but created an issue: #5651 |
Motivation
Should fix #3810
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
See snapshot.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)