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

feat: add replace option to loader redirect function #11100

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

Brendonovich
Copy link

This PR adds the ability to REPLACE the current history entry rather than always using POP when redirecting in route loaders.

This is useful for how we manage navigation in Spacedrive:

  • Our desktop app supports having multiple tabs, with each tab being its own MemoryRouter instance and history stack
  • index routes contain loaders for going from / to /{libraryId} to /{libraryId}/{defaultSegment}, where libraryId is loaded asynchronously and defaultSegment is determined based on the result of another asynchronous operation
    • loaders are used so we can rely on Suspense to show the current tab until the new tab's redirects are complete, since loaders + their redirects all run in a single transition
  • The traversal of those index routes shouldn't append to the history stack, so that /{libraryId}/{defaultSegment} is the 0th history entry
  • Each new tab starts at /{libraryId}, so one loader run + one redirect is guaranteed to happen
  • Currently, each tab automatically has a history stack of length 2 since the redirect that happens is a PUSH, not a REPLACE
  • Our in-app back button can't disable itself properly as history stack length is always > 1

Allowing loader redirects to REPLACE rather than PUSH easily fixes our navigation button problem

Copy link

changeset-bot bot commented Dec 7, 2023

🦋 Changeset detected

Latest commit: ca48463

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

This PR includes changesets to release 5 packages
Name Type
@remix-run/router Minor
react-router Patch
react-router-dom Patch
react-router-dom-v5-compat Patch
react-router-native 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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Dec 7, 2023

Hi @Brendonovich,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Dec 7, 2023

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@Londeren
Copy link

Londeren commented Apr 3, 2024

Any updates here, guys? @Brendonovich

@Brendonovich
Copy link
Author

@Londeren if it was up to me this would have been merged last year haha

@DreierF
Copy link

DreierF commented Apr 19, 2024

@brookslybrand Any chance you could give this some more visibility within the Remix team to push this over the finish line? This seem to trip up a bunch of people as you can see in #10606

@oliver-wymer
Copy link

Would be amazing to get this merged 🙏

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.

None yet

4 participants