-
Notifications
You must be signed in to change notification settings - Fork 34
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
<Navigate> with React 18 causes "Maximum update depth exceeded" #88
Comments
Same is happening to me... Regarding Your Solutions / Modifications :
Still, |
demo ok -> https://codesandbox.io/s/sweet-einstein-u8gi6r?file=/src/App.tsx TL;DR createReduxHistoryContext({
history: createBrowserHistory(),
batch: (fn) => Promise.resolve().then(fn)
}); |
Hello. Just tried this in my app:
Results:
|
@arnriu can you provide a codesandbox? |
Sorry, didn't have time to reproduce it in a code sandbox so far, I have a huge bug in my service worker in production and I have to deal with it asap. I still need to work more on it to be able to reproduce in a code sandbox and find out more about what's happening, and be sure this is the problem and not anything else. |
@arnriu no worries. feel free to update the issue if need to. |
@salvoravida Why does adding this batch resolve this issue? I just ran into this and it did indeed work, but still not sure why. One thing I did notice though is that using is substantially slower, but no longer crashes with "Maximum update depth exceeded". Thanks |
This error seems to occur under very specific circumstances: CodeSandbox example
<NavLink/>
useNavigate()
hookdispatch(push(..))
will crash the App and display
Modifications to the Example that will stop the App from crashing
render
from "react-dom" instead ofcreateRoot()
in index.tsx, the app will behave as if it's running React 17useNavigate()
instead of<Navigate/>
(swap the<Route/>
for /redirect in MainContent.tsx with the commented one, which uses<NavigateWithHook/>
)redux-first-history
, for example by replacing<HistoryRouter>
with<BrowserRouter/>
in App.tsx fromreact-router-dom
useLocation()
instead ofuseSelector()
in MainContent.tsx with the state of the routerModifications to the Example that will NOT stop the App from crashing
<StrictMode/>
in React 18 unmounts and remounts every component once after the initial render in dev mode. But disabling Strict Mode in index.tsx will still cause the app to crashThe text was updated successfully, but these errors were encountered: