-
Notifications
You must be signed in to change notification settings - Fork 2.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(remix-dev): adjust conventional routes logic for pathless layout routes #4421
Conversation
🦋 Changeset detectedLatest commit: fc33f83 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -188,6 +240,8 @@ export function createRoutePath(partialRouteId: string): string | undefined { | |||
|
|||
if (rawSegmentBuffer === "index" && result.endsWith("index")) { | |||
result = result.replace(/\/?index$/, ""); | |||
} else { | |||
result = result.replace(/\/$/, ""); |
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.
Align route paths so we never include trailing slashes on <Route path>
entries, which messes with ranking since /-delimited segments count in ranking
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.
Fixes #3014
* routes/parent/__pathless/index.tsx | ||
* routes/parent/__pathless2/index.tsx | ||
*/ | ||
if (uniqueRouteId && !isPathlessLayoutRoute) { |
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.
Fixes #3327
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 looks awesome. Just a minor request for the changeset. Also, should we add similar tests for flat route conventions?
yeah I can look into the same tests/logic for flat routes 👍 |
Hey, any update on this? I have to patch-package and apply this hotfix each time I upgrade Remix. It would be awesome to finally merge this fix. |
@sixers This is on hold since I'm unsure if it's needed when using new route convention. The code this PR is fixing will be removed in v2 but made available through another package so you can continue using the nested folder structure via the |
@brophdawg11 Yes, it's needed, the issue also exists in V2 route convention. |
@brophdawg11 Just so it's on your radar, you probably want to keep the v1 compat package in sync with these kind of fixes. https://github.com/remix-run/v1-compat-utils |
* fix: avoid collisions on pathless routes with indices * Add changeset * Remove unused import from e2e test
182cd3a
to
a41fd13
Compare
63400c6
to
5f07ba7
Compare
Chance is no longer part of the team 😢
5f07ba7
to
63400c6
Compare
Added PR for |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
tl;dr;
This fixes 2 issues ion our conventional routes logic:
path
values since # of slash-delimited segments counts towards route ranking so the trailing slash incorrectly increases the scoring for routes.Closes #3014 #3327
Deets
#4355 had an integration test failure once merged to dev due to conflicts with an unrelated PR that merged an integration tests with an index file inside a pathless layout route folder. This uncovered a bit of a rabbit hole into some details around our path collision detection in
conventionalRoutes.ts
.Before #4355, index routes inside pathless layout routes were fine because they had a trailing slash hanging around on the "path", so our
uniqueRouteIds
structure looked like:Once we got rid of the trailing slash in #4355 (to fix #3014) we now start failing the build on the above since the "path" (the key in the Map) is identical for both matches.
This turns out to also be the reason that sibling pathless layout routes fail - even though the following is valid in React Router:
With the current logic, we end up reporting a path collision on
/parent
betweenroutes/parent/__a.jsx
androutes/parent/__b.jsx
even though they have mutually exclusive children routes.What I ended up doing in here is just ignoring path collision detection only for pathless-layout route files, since by definition they sort of introduce potential path collisions that the user should be aware of and accounting for (we even warn them in the docs!). We still check for collisions on any children route files inside a
__pathless/
directory - which lets us detect if they include non-mutually-exclusive route paths beneath a pathless layout route folder.So at the end of the day we get 2 things from this PR: