question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HYDRATE and redux-dynamic-modules

See original GitHub issue

Hi,

I work on a pretty complex next.js app that uses redux-dynamic-modules. Since I’ve updated next.js to 9.3 (now 9.4) I wanted to migrate from getInitialProps to getServerSideProps but I’m a bit confused about the requirement of the HYDRATE action. Does every reducer (my app has like 50+ of them) need do be able to handle that action? Is there any way to abstract it? My global redux state stores deeply nested objects so having each reducer spread through each and every field and update them with payload would be quite annoying.

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kirill-konshincommented, May 13, 2020

Yes, you’ve pinpointed the exact reason why action constants are residing in separate files, although it’s quite tempting to put reducer, constants and action dispatchers all in one file, there are reasons not to do it.

Like I said, I am really against anything that can lead to inconsistent state, and dynamically loaded reducers is the number one reason to end up in endless debugging.

1reaction
kirill-konshincommented, May 13, 2020

I’m not sure. Like I said previously, top level hydration handler is the best bet. To be completely honest, I don’t see a value to code split reducers, as it ruins the state consistency (just like in your case). Potentially actions may be handled anywhere and if the needed reducer was not loaded the action won’t be handled. Reducers are small, so what’s the point to code split them?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strategies for hydrating a store from SSR #47 - GitHub
The set of loaded modules is effectively part of the Redux store's state, but one that hasn't been serialized from server to client....
Read more >
Redux Dynamic Modules
redux -dynamic-modules is a library that aims to make Redux Reducers and middleware easy to modular-ize and add/remove dynamically.
Read more >
Redux store code splitting with sagas - Scite
The Redux documentation mentions that you can dynamically inject reducers using the built in replaceReducer function, and includes some ...
Read more >
React 18: Hydration failed because the initial UI does not ...
I am using the react-use-cart module and it seems it has issues with react @18.0.0 . I am not sure how this is...
Read more >
Redux Store | Shakacode
This redux API is no longer recommended as it prevents dynamic code splitting ... function appStore(props, railsContext) { // Create a hydrated redux...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found