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

Remove support for warnWhenUnsavedChange when react-router doesn't allow it #8272

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Oct 17, 2022

Problem

React-router 6.4.0 removed support for navigator.block, which is necessary for the warnWhenUnsavedChanges feature (see remix-run/react-router#9262).

This breaks existing applications using react-router >= 6.4 and a custom router.

Solution

The warnWithUnsavedChanges feature fails silently when using with react-router >= 6.4

Closes #8163

@fzaninotto fzaninotto added the RFR Ready For Review label Oct 17, 2022
@crates
Copy link

crates commented Oct 17, 2022

Is it possible to preempt the user's own onSubmit method (or alternatively, fired subsequent to the user's one) with one created by React Admin, so that when the warning prop is in use, it's that interstitial method that triggers first, thereby calling the warning up instead of submitting the form? That would not require any use of navigator.block, but would result in a similar outcome.

@fzaninotto
Copy link
Member Author

@crates I'm not sure I understand. Are you suggesting that warnWhenUnsavedChange auto-submits the form when the user leaves the page without submitting? That would be very unexpected for most users.

@crates
Copy link

crates commented Oct 17, 2022

No, you are totally right. That suggestion made no sense.

How about a custom router component provided by React Admin? Something like what they are discussing on this thread?

https://stackoverflow.com/questions/69953377/react-router-v6-how-to-use-navigate-redirection-in-axios-interceptor

@TrejGun
Copy link

TrejGun commented Oct 17, 2022

that actually still works with
remix-run/react-router#8139 (comment)

and custom history

import { FC } from "react";
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import { history } from "history";


const App: FC = () => {
  return (
    <HistoryRouter history={history}>
      <YOUR CODE HERE>
    </HistoryRouter>
  );
};

export default App;

@crates
Copy link

crates commented Oct 18, 2022

@TrejGun - Agreed; that's what we're using on our project also, with React Router 6.4

@fzaninotto
Copy link
Member Author

How about a custom router component provided by React Admin? Something like what they are discussing on this thread?

https://stackoverflow.com/questions/69953377/react-router-v6-how-to-use-navigate-redirection-in-axios-interceptor

@crates reimplementing a custom router is outside of the scope of react-admin. We have enough work without it ;)

that actually still works with
remix-run/react-router#8139 (comment)

and custom history

@TrejGun You're right, that's why the PR description says

This breaks existing applications using react-router >= 6.4 and a custom router.

So we have to prevent the app from breaking in that case, and that's why this PR is necessary.

@slax57 slax57 added this to the 4.4.4 milestone Oct 18, 2022
@slax57 slax57 merged commit 6a8e64f into master Oct 18, 2022
@slax57 slax57 deleted the warnwhenunsavedchange branch October 18, 2022 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: navigator.block using the warnWhenUnsavedChanges prop in Form
5 participants