connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

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

Open joyfuI opened this issue 3 years ago • 4 comments

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?

joyfuI avatar May 12 '21 14:05 joyfuI

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

Akiyamka avatar May 28 '21 15:05 Akiyamka

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.

joyfuI avatar Jun 06 '21 08:06 joyfuI

@joyfuI you are right, thanks your useful advice

cll123456 avatar Jun 28 '21 08:06 cll123456

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?

pr1ntr avatar Nov 18 '21 05:11 pr1ntr