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: Wait for restore url navigation to complete before proceeding #11620

Closed
wants to merge 16 commits into from

Conversation

Artur-
Copy link

@Artur- Artur- commented Jun 6, 2024

Fixes #11613

Copy link

changeset-bot bot commented Jun 6, 2024

🦋 Changeset detected

Latest commit: 6071fb1

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

This PR includes changesets to release 9 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/remix-v2-routes 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 Jun 6, 2024

Hi @Artur-,

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 Jun 6, 2024

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

@Artur-

This comment was marked as outdated.

@Artur-
Copy link
Author

Artur- commented Jun 11, 2024

Any chance of getting this reviewed and into v6?

@Artur-
Copy link
Author

Artur- commented Jun 17, 2024

@brophdawg11?

@Artur-
Copy link
Author

Artur- commented Jul 23, 2024

The test in 82d4344 is for this case and fails in the dev branch

@Artur-
Copy link
Author

Artur- commented Jul 31, 2024

@markdalgleish any comment on this? Is there a way to get this moving forward instead of collecting dust and conflicts?

reset: undefined,
location: undefined,
})
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we revert these unrelated changes to the tests and do them in a standalone PR? I'm not against changing the approach but I'd prefer to keep the functional bug fix changes separate from the unrelated test cleanup changes. Bug fix PRs like this are, IMO, best when they are 1 or more net-new tests demonstrating the bug and the code changes to make those test pass

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I really do not want to make any changes to any other tests but this was needed, at least originally, to get tests to pass with the fix. I now reverted all these changes and included one commit with the test that fails in current dev and another commit with the fix. Let's see if tests pass or not, and if not, I can create a separate PR first with the test changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok let me take a look at those locally. I noticed this was off dev too but we'll need it to be off v6 if we want to release a fix in 6.x so I'll probably re-open a new PR against v6 and will include you as a coauthor on that one

@@ -1007,7 +1007,7 @@ export function createRouter(init: RouterInit): Router {

// Flag to ignore the next history update, so we can revert the URL change on
// a POP navigation that was blocked by the user without touching router state
let ignoreNextHistoryUpdate = false;
let ignoreNextHistoryUpdate: (() => void) | undefined = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename this to something like unblockBlockerHistoryUpdate to align with the new approach?

Copy link
Author

Choose a reason for hiding this comment

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

Done

); // This awaits the navigation
router.getBlocker("KEY", fn).proceed!();
await waitFor(() =>
expect(router.state.location.pathname).toBe("/about")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure this test exhibits the actual bug? I see this failure when run against dev:

● navigation blocking › proceeds from blocked state using browser history › proceeds after quick block of back navigation

    expect(received).toBe(expected) // Object.is equality

    Expected: "/about"
    Received: "/"

The reproduction for the original issue leaves you on the original blocked page (/three) but this test, without the fix, actually ends up going back 2 history locations?

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure why it behaves differently here. My assumption was that maybe JSDOM (or whoever emulates browser navigation here) behaves differently in the case where navigation is in progress and you navigate again. I think it still covers the issue though, which is that if you navigate during navigation, you will end up somewhere else than you would expect.

If you have ideas on how to improve the test, I am all ears

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok yeah this is probably a JSDOM issue. I'm going to test this through an integration test in a real browser in remix-run/remix#9914 instead of trying to hack JSDOM into behaving correctly

@brophdawg11
Copy link
Contributor

Superseded by #11930

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.

[Bug]: useBlocker fails when blocking function is quick to proceed
2 participants