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

@@router/LOCATION_CHANGE fires twice #4

Closed
bazalev opened this issue Dec 16, 2016 · 12 comments
Closed

@@router/LOCATION_CHANGE fires twice #4

bazalev opened this issue Dec 16, 2016 · 12 comments
Assignees
Labels

Comments

@bazalev
Copy link

bazalev commented Dec 16, 2016

The first listener subscribes in syncHistoryWithStore and the second in ConnectedRouter constructor.
Is it correct to fire this action twice on each transition?

@bazalev
Copy link
Author

bazalev commented Dec 16, 2016

Actually, I don't understand the purpose of calling syncHistoryWithStore(history, store).
We do the same thing in ConnectedRouter's constructor.
I didn't see any changes in behavior after deleting this syncHistoryWithStore call.

@supasate
Copy link
Owner

Yes. You're right. syncHistoryWithStore is useless now. I'll remove it in the next release.

@bazalev
Copy link
Author

bazalev commented Dec 16, 2016

Thanks!

@supasate
Copy link
Owner

@bazalev Already fixed in v1.0.0-alpha.5!

@bazalev
Copy link
Author

bazalev commented Dec 16, 2016

Awesome!
Thank you!

@antonjohanssonse
Copy link

Hello @supasate , sorry for taggin in such an old issue. But I am migrating from react-router-redux to connected-react-router and I don't understand what I should replace syncHistoryWithStore with?

How do I convert this part to work?
const history = syncHistoryWithStore(browserHistory, store);

@ruchirV
Copy link

ruchirV commented Jan 7, 2021

I still see this issue. I have bootstrapped application using redux-toolkit and eventually added connected-react-router for syncing redux store with router location. I see LOCATION_CHANGE firing twice every time Link is clicked. I tried "push" also by converting Link to a Button, but that also fired it twice. Is this an issue?

@ibocon
Copy link

ibocon commented Jan 10, 2021

I am having this issue...

@pranjul-sharma
Copy link

I am also having the same issue, LOCATION_CHANGE is getting fired twice with the connected-react-router v6.8.0

@xmd5a
Copy link

xmd5a commented Jan 28, 2021

@ruchirV @ibocon @pranjul-sharma guys you probably wrapped your code inside index.js/tsx using <React.StrictMode> (which is default if you're using CRA). And this behaviour is totally fine - after builidng production version of your app this situation should not appear. You can do small proof of concept by temporary removing <React.StrictMode> wrapper.

@TomTomB
Copy link

TomTomB commented Jan 31, 2021

@ruchirV @ibocon @pranjul-sharma guys you probably wrapped your code inside index.js/tsx using <React.StrictMode> (which is default if you're using CRA). And this behaviour is totally fine - after builidng production version of your app this situation should not appear. You can do small proof of concept by temporary removing <React.StrictMode> wrapper.

This is right. I've also noticed that reverting an @@router/LOCATION_CHANGE action via redux devtools fires an additional two new @@router/LOCATION_CHANGE actions. This also only applies if <React.StrictMode> is enabled. Is there maybe a better solution than removing StrictMode?

@jackdh
Copy link

jackdh commented Jul 1, 2021

I've found that moving <React.StrictMode> inside the connected router resolves the issue.

It's not perfect but better than before.

<Provider store={store}>
  <ConnectedRouter history={history}>
	<React.StrictMode>
		<App />
	</React.StrictMode>
  </ConnectedRouter>
</Provider>

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

No branches or pull requests

9 participants