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

[v5] Not compatible with React 18 StrictMode #7870

Closed
Tracked by #1365
Jack-Works opened this issue Jun 11, 2021 · 14 comments
Closed
Tracked by #1365

[v5] Not compatible with React 18 StrictMode #7870

Jack-Works opened this issue Jun 11, 2021 · 14 comments

Comments

@Jack-Works
Copy link

Version

v5.2.0

React 18 with StrictMode, see reactwg/react-18#19

Test Case

https://codesandbox.io/s/react-router-forked-1s3zi

Steps to reproduce

Click around

Expected Behavior

Works

Actual Behavior

Not working

@Jack-Works
Copy link
Author

Tested with v6, seems OK

@patrikniebur
Copy link

I had the same issue. It's not working when used in React.StrictMode

@popuguytheparrot
Copy link

@popuguytheparrot
Copy link

In my case, updating to version 6 is impossible, because there is no way to control history outside of react

@DeividasBakanas
Copy link

Just to clarify the issue: with React 18 StrictMode, react-router does not perform the transition when navigation occurs. The route is stale when the path is changed: https://codesandbox.io/s/dreamy-andras-hbuco1?file=/src/index.tsx

The behavior occurs in v5.3.0 too.

As React 18 is officially released and the StrictMode is preferred in many cases as default in a development environment, this issue should become more relevant.

As there is still no backwards compatibility package, can we expect the patch release of v5 for the issue?

jeron-diovis added a commit to jeron-diovis/redux-typescript that referenced this issue Apr 1, 2022
@timdorr
Copy link
Member

timdorr commented Apr 2, 2022

If someone wants to make a PR, I'd be happy to do a patch release for v5.

@rahulppatidar
Copy link

rahulppatidar commented Apr 15, 2022

It is not working if BrowserRouter is a child of StrictMode. So, to make it work we can put StrictMode as child of BrowserRouter.
i.e. Instead of <React.StrictMode><BrowserRouter>...</BrowserRouter></React.StrictMode>
we can <BrowserRouter><React.StrictMode>...</React.StrictMode></BrowserRouter>
That way it worked for me.

@jgoz
Copy link

jgoz commented May 1, 2022

I think I've got a fix for this in #8831

@yoerivdm
Copy link

yoerivdm commented May 3, 2022

This solves it BUT we are experiencing mout-unmounts-mount cycles for each component. This rerender behaviour is solved when removing the strictmode.

@awreese
Copy link
Contributor

awreese commented May 11, 2022

Following this issue: https://stackoverflow.com/a/71833424/8690857

Eddcakes added a commit to Eddcakes/beer-pong that referenced this issue May 29, 2022
Description: update to createRoot, update dependencies to new versions that work with v18 (xstate/testing lib), tailwind no longer needs postcss compat so removed craco, update tailwind config to new format + flex-grow > grow, CURRENT ISSUE, react-router5 has issues with new strict mode remix-run/react-router#7870
Eddcakes added a commit to Eddcakes/beer-pong that referenced this issue May 31, 2022
* update to react 18, update tailwind, remove craco

Description: update to createRoot, update dependencies to new versions that work with v18 (xstate/testing lib), tailwind no longer needs postcss compat so removed craco, update tailwind config to new format + flex-grow > grow, CURRENT ISSUE, react-router5 has issues with new strict mode remix-run/react-router#7870

* add server validation for string ids

* refactor to new react-router syntax

* update react router

* audit fix

* update markdown packages, needed to add setting to run tests because of jest /module support wonky

* update markdown packages, needed to add setting to run tests because of jest /module support wonky

* typos in versus path

* fix passing RequireRole element instead of child

* (fix) sign out was broken on fast connection because redirect happened before request completed

* (chore) update joi

* (chore) update xstate

* (chore) update react-query
@timdorr timdorr closed this as completed Aug 1, 2022
@phanimurari
Copy link

I had the same issue. It's not working when used in React.StrictMode

Thanks for the help

@fajria96
Copy link

Omg big thanks. I was so stressed out for few days cause of it

@chollid

This comment has been minimized.

@altyaper
Copy link

It is not working if BrowserRouter is a child of StrictMode. So, to make it work we can put StrictMode as child of BrowserRouter. i.e. Instead of <React.StrictMode><BrowserRouter>...</BrowserRouter></React.StrictMode> we can <BrowserRouter><React.StrictMode>...</React.StrictMode></BrowserRouter> That way it worked for me.

The problem seems a little bit complicated for this approach because the issue also appears in the component, so StrictMode would be wrapping the routes.

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

No branches or pull requests