-
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: Ignore pathless layout routes when matching actions #4376
Changes from all commits
2fee450
127437b
acf8fce
a201fba
e88ce64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@remix-run/react": patch | ||
"@remix-run/server-runtime": patch | ||
--- | ||
|
||
Ignore pathless layout routes in action matches |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,7 +590,7 @@ export function createTransitionManager(init: TransitionManagerInit) { | |
invariant(matches, "No matches found"); | ||
if (fetchControllers.has(key)) abortFetcher(key); | ||
|
||
let match = getFetcherRequestMatch( | ||
let match = getRequestMatch( | ||
new URL(href, window.location.href), | ||
matches | ||
); | ||
|
@@ -644,17 +644,28 @@ export function createTransitionManager(init: TransitionManagerInit) { | |
return false; | ||
} | ||
|
||
function getFetcherRequestMatch( | ||
url: URL, | ||
matches: RouteMatch<ClientRoute>[] | ||
) { | ||
// Return the correct single match for a route (used for submission | ||
// navigations and and fetchers) | ||
// - ?index should try to match the leaf index route | ||
// - otherwise it should match the deepest "path contributing" match, which | ||
// ignores index and pathless routes | ||
function getRequestMatch(url: URL, matches: ClientMatch[]) { | ||
let match = matches.slice(-1)[0]; | ||
|
||
if (!isIndexRequestUrl(url) && match.route.index) { | ||
return matches.slice(-2)[0]; | ||
if (isIndexRequestUrl(url) && match.route.index) { | ||
return match; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return the leaf for index requests, otherwise return the lowest path contributing match |
||
} | ||
|
||
return match; | ||
return getPathContributingMatches(matches).slice(-1)[0]; | ||
} | ||
|
||
// Filter index and pathless routes when looking for submission targets | ||
function getPathContributingMatches(matches: ClientMatch[]) { | ||
return matches.filter( | ||
(match, index) => | ||
index === 0 || | ||
(!match.route.index && match.route.path && match.route.path.length > 0) | ||
); | ||
Comment on lines
+663
to
+668
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from what we use in react-router to trim routes that do not contribute to the path |
||
} | ||
|
||
async function handleActionFetchSubmission( | ||
|
@@ -1071,14 +1082,10 @@ export function createTransitionManager(init: TransitionManagerInit) { | |
// to run on layout/index routes. We do not want to mutate the eventual | ||
// matches used for revalidation | ||
let actionMatches = matches; | ||
if ( | ||
!isIndexRequestUrl(createUrl(submission.action)) && | ||
actionMatches[matches.length - 1].route.index | ||
) { | ||
actionMatches = actionMatches.slice(0, -1); | ||
} | ||
|
||
let leafMatch = actionMatches.slice(-1)[0]; | ||
let leafMatch = getRequestMatch( | ||
createUrl(submission.action), | ||
actionMatches | ||
); | ||
let result = await callAction(submission, leafMatch, controller.signal); | ||
|
||
if (controller.signal.aborted) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -708,11 +708,19 @@ function isIndexRequestUrl(url: URL) { | |
function getRequestMatch(url: URL, matches: RouteMatch<ServerRoute>[]) { | ||
let match = matches.slice(-1)[0]; | ||
|
||
if (!isIndexRequestUrl(url) && match.route.id.endsWith("/index")) { | ||
return matches.slice(-2)[0]; | ||
if (isIndexRequestUrl(url) && match.route.id.endsWith("/index")) { | ||
return match; | ||
} | ||
|
||
return match; | ||
return getPathContributingMatches(matches).slice(-1)[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same change on the server |
||
} | ||
|
||
function getPathContributingMatches(matches: RouteMatch<ServerRoute>[]) { | ||
return matches.filter( | ||
(match, index) => | ||
index === 0 || | ||
(!match.route.index && match.route.path && match.route.path.length > 0) | ||
); | ||
} | ||
|
||
function getDeepestRouteIdWithBoundary( | ||
|
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.
We now use the same util for action
submissions
and fetchers - so we only do this?index
/pathless
logic once