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
Browser history not synched anymore with new router location starting from 6.6.0 #395
Comments
Time travelling is only intended for debugging with redux-devtools. Normally you should never write to the router's state from your app reducer. If this was working for you previously, I don't think it's how connected-react-router is intended to be used. If you want to modify the location bar along with some of your own actions, you have a few choices:
What you have in the description is kind of like the last option, but you tried to do it in a reducer, which only worked by chance. |
Okay, I have worked around it, thanks for the info. This does feel strange to me, the whole idea of Redux is that you have a state, and the view renders the state. I guess this paradigm breaks appart for browser history, since it is a stack, and can't just be "rendered". |
I'm reopening this issue, since I'm running circles with the proposed solutions, I guess I'm tackling this incorrectly. The situation is as follows:
This works fine. However, a Setting the history location before Setting the history location after So basically, I need to change the game state and the router state atomically, something that worked fine pre 6.6.0, even though it wasn't designed for this. I could make different actions, but that doesn't seem to solve the problem. I could pass the game state as the router location state, but that feels wrong, it should be independent... This feels such a common scenario that a solution must exist for this? For now I will revert to 6.5.2, since that solved all my problems ;-) |
Instead of |
Yes, my example was simplified too much. I could solve my issue if I could detect if a page was rendered because a user navigated to it, because in all other cases, the program controls the state, and the page shouldn't alter it. Like the HTML Maybe I could use the location state to detect the above? So when my middleware pushes the URL that corresponds to the next new game state that will be set, I pass a location state that says Thanks for the feedback! |
Yes, that seems to work! EDIT: No it doesn't, it seems a page refresh keeps the router location state somehow? One small problem remains (independently from this): when replaying actions with the redux devtools, the initial page render doesn't realize it is being played back, and it will fetch the state from the server, dispatching a new action... This is another issue: IMHO fetching state should rarely be done in a view, instead it should always be the result of a user or external event (e.g. the user clicking a button, the user navigating to a page). But I can't find an event on the |
It seems I was just using the wrong library for my architecture, https://github.com/faceyspacey/redux-first-router might suit me better? |
When reducing a state on some of our actions, we also output a new router location state using the following TS code:
This code doesn't always work anymore with V6.6.0 and newer, the browser is sometimes not navigating to the new page (it depends on the starting page), I'm trying to find out what version broke it.
Our maybe our function above is just wrong, do we need to include other properties in the state? Do you have a helper function for this?
I guess it is this line that breaks our code, but just adding
action: "PUSH"
to the state doesn't seem to fix it.What is the correct way to reduce the router location as a "side effect" in our own reducers?
The text was updated successfully, but these errors were encountered: