Rehydratation changes all store references on UPDATE_ACTION
See original GitHub issueWhen rehydrating store in lazy load feature, changes the references of all store object and this mean that all the subscriptions are fired without changes in the store. This subscriptions are fired several times if you have a preload strategy (such as feature modules are loaded).
I’ve created a minimal project to show this behaviour: https://stackblitz.com/github/jonnyprof/ngrx-localstorage-test
I’ve created the project with preloadingStragegy on PreloadAllModules to show that fires 2 times with 2 lazy loading feature modules, but it happens without this strategy when you load the featured module (change the route).
Steps to reproduce: 1.- Go to https://stackblitz.com/github/jonnyprof/ngrx-localstorage-test 2.- Open the console 3.- Click on “Load global data”. This fills the global state and save it on localStorage. 4.- Reload the page.
You can see on console that “receiving global data” is printed 3 times:
- First one by the initial rehydration from appModule
- Second and third by every lazy loaded feature (feature1 and feature2)
I think this is a serious bug, we have a production application with lots of lazy loaded modules and in some places the subscriptions are fired 10 times! If you dispatch actions that makes http request this is crazy
I’ve found that if we change the line
nextState = merge({}, nextState, rehydratedState);
with
nextState = merge(nextState, rehydratedState);
solves the problem, but I’m not sure if this can cause other issues.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:9 (1 by maintainers)
Top GitHub Comments
please @btroncone can you check this?
Yes, I know the historial lodash - deepmerge path, because of it I’ve used deepmerge in my solution. We have a large application with lazy load modules depending on the page and connection, and if every time that we load an async module all the async pipes to the store are emitted, the loose of performance is huge due to changeDetection is fired for all the components.