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

[Bug]: Use with single-spa, useBlocker may cause unnessesary reload #11621

Open
cyrilluce opened this issue Jun 6, 2024 · 0 comments
Open

[Bug]: Use with single-spa, useBlocker may cause unnessesary reload #11621

cyrilluce opened this issue Jun 6, 2024 · 0 comments
Labels

Comments

@cyrilluce
Copy link

cyrilluce commented Jun 6, 2024

What version of React Router are you using?

6.23.1

Steps to Reproduce

sandbox: https://stackblitz.com/edit/github-yc7ha4?file=index.html

Click go test > proceed

Expected Behavior

Redirect success without reload page

Actual Behavior

Page will reload due to this code:
https://github.com/remix-run/react-router/blob/main/packages/router/router.ts#L1004
image

Actually I had trace the reason, single-spa will inject history api, which make history.pushState/replaceState fire extra synthetic popstate event( BY DESIGN, see: https://single-spa.js.org/docs/api/#popstateevent and single-spa/single-spa#528)

If createBrowserRouter after single-spa injected, it will be affected.

At the time, useBlocker's disposer haven't executed, and blocker.state === 'unblock', single-spa's popstate will trigger another history restore, which delta is 0, and try to execute history.go(0), finally cause reload.

Possible fix is ignore delta === 0

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

No branches or pull requests

1 participant