-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Redux.replaceReducer throw warning "Unexpected key found" #1636
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
Comments
Basically, i cannot remove a 'sub state' once it is added to the store :( |
Technically this is a warning rather than an error so you can. But it is annoying. I think we should fix this. |
I'm running into this warning after adding serialized state from a server handoff whilst routing into a route with a dynamically added reducer. Only happens on initial load as my routes initialize on the client after the store. Wondering if there's a good workaround here... |
I think after changing |
Also @gaearon, although this is a warning, it seemed to me that the state doesn't necessarily changed. I still got 'registration' as one of my root state. Or is it expected? But if it is expected, then my 'registration' state will gonna be a dead meat right there, right? The reducer's gone but the state remains. |
I would suggest removing that warning in the source and checking which tests fail. They likely show reasonable ideas or why this warning was added. Then we can consider how to make it works well for all use cases. |
Hi, I came across same issue when I am trying to build modular application. The basic idea is that once module is loaded it will inject its own reducers and once module is unloaded it should remove its own reducers. @edit Thanks. |
I've been messing around with updating, and in some cases replacing the reducers based on dynamic routes. I posted a comment in response to @gaearon answer on stack overflow. I followed his answer for getting the reducers injected into the store, but I ran into a problem when I wanted to inject more reducers dealing with the same branch on the state tree on a different route. I couldn't figure out a way to combine the reducers that were already present and the new reducers. I don't want to combine these sooner as it allows me to code split the reducers down to what each page actually needs. |
@QuietOmen Please post your question on SO, doesn’t look like this thread would be very helpful 😉 |
Thanks, I posted it here in case anyone stumbles upon this thread and becomes curious. |
Ran in this issue, when writing a test for the store |
CombineReducer only show this warning on non-production environment, so a workaround could be:
|
These two tests fail. Specifically, lines 237 and 285. The 2nd test is just checking that the warning only fires once. But the 1st test is the interesting one: It's ensuring the provided initial state matches the state the current reducer provides. This makes sense for SSR; you want to make sure you're using the same reducer(s) for generating the page on the server as are running in the client. It would seem we need to handle the special case of replacing a reducer separately from a initial store creation. So, I'd like to propose that the action dispatched after replaceReducers is a new type called "REPLACE" that is also special like INIT. Just some quick fiddling around proves this still passes all tests. Since it's a breaking behavior (even though it should be private...), I'll put it on the |
I can confirm that if this warning appears, it seems to break clientside tree rehydration when using SSR:
|
@gaearon So full state came to client and when store is created in the first time - store looses piece of state of the current page - because it's not loaded yet. Is there a way to restore state with injecting reducers? |
Uh oh!
There was an error while loading. Please reload this page.
This issue was moved from reduxjs/react-redux#360
The text was updated successfully, but these errors were encountered: