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

fix: Ignore pathless layout routes when matching actions #4376

Merged
merged 5 commits into from
Oct 20, 2022

Conversation

brophdawg11
Copy link
Contributor

Same fix as remix-run/react-router#9455 in react router

If you have a route tree of:

<Route path="parent" action={...} element={<Parent />}>
  <Route element={<Pathless />}>
    <Route index element={<Index />} />
  </Route>
</Route>

And a <Form method="post"> in <Parent /> submits, then it should ignore the pathless layout route in the middle and walk upwards to the last path-contributing matches action.

Closes: #2498

  • Docs
  • Tests

Testing Strategy: Added integration tests

@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2022

🦋 Changeset detected

Latest commit: e88ce64

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/react Patch
@remix-run/server-runtime Patch
@remix-run/cloudflare Patch
@remix-run/deno Patch
@remix-run/dev Patch
@remix-run/node Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
create-remix Patch
@remix-run/architect Patch
@remix-run/express Patch
@remix-run/netlify Patch
@remix-run/vercel Patch
@remix-run/serve Patch
remix Patch
@remix-run/eslint-config Patch

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

Comment on lines +643 to +648
function getPathContributingMatches(matches: ClientMatch[]) {
return matches.filter(
(match, index) =>
index === 0 ||
(!match.route.index && match.route.path && match.route.path.length > 0)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

if (!isIndexRequestUrl(url) && match.route.index) {
return matches.slice(-2)[0];
if (isIndexRequestUrl(url) && match.route.index) {
return match;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same change on the server

@@ -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(
Copy link
Contributor Author

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

@brophdawg11 brophdawg11 merged commit cd2e256 into dev Oct 20, 2022
@brophdawg11 brophdawg11 deleted the brophdawg11/ignore-pathless-routes branch October 20, 2022 21:40
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Oct 20, 2022
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-9868b20-20221021 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

kentcdodds pushed a commit that referenced this pull request Dec 15, 2022
* fix: Ignore pathless layout routes when matching actions

* Add changeset

* Add comment

* Remove deuped function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Action in root.tsx not executed when pathless index route present
2 participants