supasate / connected-react-router

A Redux binding for React Router v4
MIT License
4.73k stars 593 forks source link

When moving to <Link>, LOCATION_CHANGE is called twice. #509

Open joyfuI opened 3 years ago

joyfuI commented 3 years ago

I am migrating a project that used react-router-redux to connected-react-router.

Looking through the console logs, I noticed that LOCATION_CHANGE was being called twice every time a page was navigated.

Here is the reproduction code.
https://codesandbox.io/s/connected-react-router-0tbdu

Is this the correct behavior?

Akiyamka commented 3 years ago

I see the same behavior (twice LOCATION_CHANGE) even when dispatch the push action. Relative issue: https://github.com/supasate/connected-react-router/issues/318

joyfuI commented 3 years ago

I found the cause. StrictMode is the cause.

After further searching, I found the following article: https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects

It's probably caused by two renderings in development mode with StrictMode.

cll123456 commented 3 years ago

@joyfuI you are right, thanks your useful advice

pr1ntr commented 2 years ago

So should we just not use this library in conjunction with Strict Mode? Surely Strict Mode has a lot of benefits. What exactly is the issue with history as per #318?