Skip to content

Rehydratation changes all store references on UPDATE_ACTION #128

@Jonnyprof

Description

@Jonnyprof

When 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions