Next.JS + Hot Module Reload #3348
-
|
I am building an app with Next.JS (v13.3 using legacy pages model) and @reduxjs/toolkit (v 1.9.3). When I run in development mode, every change I make on the client (triggering a hot module reload HMR) causes my store to revert back to initial state. I thought reduxjs/toolkit would preserve the store state across HMR, what am I missing? Here is generally how my store looks: I found Confident that it is some configuration piece I am missing, can someone help point me to the err of my ways? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hmm. First note is that Second, where and how are you importing this file? At what component/page level? Also, is SSR (in the form of |
Beta Was this translation helpful? Give feedback.
-
|
SSR is not involved (not using any of getServerSideProps / getInitialProps) I think I have it narrowed down a little (but still very lost):
Here is the api slice: For reference, the base query used is essentially the axios base query example with the addition of some encryption (all payloads are encrypted) |
Beta Was this translation helpful? Give feedback.
If you modify a file that is required for your
configureStorecall, the file with yourconfigureStorecall will also reload - creating a new store. You can play around that withmodule.hot.acceptandstore.replaceReducers, but in the long run it's usually not worth doing do, as you probably won't be touching those files a lot, compared to your component files.