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

Read initial state from server #32

Closed
stoope opened this issue Nov 15, 2018 · 7 comments
Closed

Read initial state from server #32

stoope opened this issue Nov 15, 2018 · 7 comments
Assignees
Labels
How to Issues that ask How to do something in redux-dynamic-modules

Comments

@stoope
Copy link

stoope commented Nov 15, 2018

I want to pass preloaded state from server

createStore(window.__PRELOADED_STATE__, [], [sagaMiddleware])

(https://redux.js.org/recipes/serverrendering#client-js)
Problem is initial state passed to createStore overwrites by initial state from each dynamically loaded reducer. How can I apply preloaded state to them?

@navneet-g
Copy link
Contributor

@stoope We don't overwrite any state intentionally, I will try it out and see if I can get a repro.

@navneet-g navneet-g self-assigned this Nov 15, 2018
@stoope
Copy link
Author

stoope commented Nov 16, 2018

@navneet-g Have made playground https://codesandbox.io/s/k917m5ppjv. If you remove defaultModule from createStore app works as expected.

@navneet-g
Copy link
Contributor

Awesome ... thanks for doing it @stoope ... I will take a look tonight or over the weekend.

@navneet-g
Copy link
Contributor

@stoope I took a look, this is happening as the keys in initialState are ignored by combinedReducer, as the defaultModule does not contain any reducers for those keys. If the defaultModule can contain the

Notice line 163 onwards in following file in redux code.
https://github.com/reduxjs/redux/blob/3f93d6bb21fd104263bc83da87bd2e113e82bd9f/src/combineReducers.js

I have modified the playground to illustrate it
https://codesandbox.io/s/xj49x173kz

Please let me know if you have any question.

@stoope
Copy link
Author

stoope commented Nov 17, 2018

@navneet-g Thanks, I see... This is a problem since I don't know about other reducers at initial stage, they will be added later with react-loadable. Best solution is to read window.__PRELOADED_STATE__.somereducer state in each module's reducer, right?

@navneet-g
Copy link
Contributor

Yes ... That is an alternative, I don't know though, when does the library overwrites the state in window object.

@navneet-g
Copy link
Contributor

Closing as hopefully the above answered the question, please reopen if you still need help with this.

@navneet-g navneet-g added the How to Issues that ask How to do something in redux-dynamic-modules label Dec 21, 2018
@navneet-g navneet-g pinned this issue Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
How to Issues that ask How to do something in redux-dynamic-modules
Projects
None yet
Development

No branches or pull requests

2 participants