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(remix-react): Handle revalidations across multi-redirects #3460

Merged
merged 4 commits into from
Jun 21, 2022

Conversation

brophdawg11
Copy link
Contributor

There is some stateful information driving whether or not we revalidate inside transition manager which was getting lost across a redirect boundaries in certain scenarios. This PR fixes two potential flows:

  1. action submission redirects, then loader redirects
    1. We go actionRedirect -> normalRedirect and the second loader execution skips reused parent routes
    2. This is fixed by keeping subsequent redirects marked as actionRedirect
  2. loader redirects with a cookie
    1. We go normalRedirect -> normalRedirect but we lose the location.state.setCookie flag on the second redirect
    2. This is fixed by carrying forth the setCookie flag from the current navigation when kicking off a new normalRedirect

Closes: #3302

  • Tests

Testing Strategy:

}

export async function loader({ request }) {
return { count: ++global.actionCount };
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 use a count to confirm how many times this parent loader runs on the redirects

return (
<Form method="post">
<button type="submit">Submit</button>
</Form>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submit the form, which redirects to /action/1 and then to /action/2

"app/routes/loader/link.jsx": js`
import { Link } from "@remix-run/react";
export default function Parent() {
return <Link to="/loader/redirect">Redirect</Link>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Click this link, which redirects to /loader/1 then to /loader/2

state.transition.type === "actionReload" ||
((location.state as any)?.isRedirect &&
(location.state as any)?.type === "action")
) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stay on the actionRedirect path if the current load is an action redirect

state.transition.type === "actionReload",
state.transition.type === "actionReload" ||
// loader redirected during action redirect
state.transition.type === "actionRedirect",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allow actionRedirect to kick off actionRedirect as well

// If we're in the middle of a setCookie redirect, we need to preserve
// the flag so we handle revalidations across multi-redirect scenarios
setCookie:
redirect.setCookie || (location.state as any)?.setCookie === true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Preserve the setCookie flag on back to back normalRedirects

@ryanflorence ryanflorence merged commit 79969f0 into dev Jun 21, 2022
@ryanflorence ryanflorence deleted the brophdawg11/multi-redirects branch June 21, 2022 22:03
@MichaelDeBoey MichaelDeBoey changed the title fix: Handle revalidations across multi-redirects fix(remix-react): Handle revalidations across multi-redirects Jun 21, 2022
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-1e32bfa-20220622 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirects cause root route loader invocation but root route component does not receive loader data
3 participants