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]: useBlocker not prevent fetcher submits #11369

Closed
abustany opened this issue Mar 23, 2024 · 2 comments
Closed

[Bug]: useBlocker not prevent fetcher submits #11369

abustany opened this issue Mar 23, 2024 · 2 comments
Labels

Comments

@abustany
Copy link

What version of React Router are you using?

6.22.3

Steps to Reproduce

  1. Open https://stackblitz.com/edit/github-wxm49t?file=src%2Fapp.tsx
  2. Click the Go button

(note: I added a beforeunload handler to make 100% sure the issue is not linked to client vs. "real" navigation)

Expected Behavior

useBlocker prevents the fetcher from submitting

Actual Behavior

fetcher.submit() navigates way, potentially losing unsaved data on the page

@abustany abustany added the bug label Mar 23, 2024
@brophdawg11
Copy link
Contributor

This is intended - useBlocker prevents navigations and fetchers are explicitly not navigations. What you're seeing is the bubbling of a 404 on the fetcher call to the Error Boundary, and since you haven't specified one it's using the default which is blowing away your UI so it "feels" like it navigates elsewhere but it remains on / the whole time.

Here's an example of using an ErrorBoundary to capture those errors contextually in the UI: https://stackblitz.com/edit/github-wxm49t-jdqbwf

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2024
@abustany
Copy link
Author

Thanks for the detailed answer! My use case involves not a 404 but the loader returning a redirect, should that also be captured using an error boundary then?

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

2 participants