-
Notifications
You must be signed in to change notification settings - Fork 121
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
Bug with Lazy Loaded feature modules #93
Comments
I’ve just hit this too |
@philjones88 Possible solution that works for my usage: #94 |
@bmalinconico Do you want to take the lead on this? I can make you a collaborator to this project. I am not able to put much time into this right now and do not want to be a bottleneck. |
@btroncone Sure, I think the biggest risk of my PR is the kinda "stupid" way it determines the state key name |
@bmalinconico Really looking for another extra set of eyes that is using this library every day. Need help determining priority and impact of some of the proposed PR's / issues. |
I pulled it down but had problems getting the tests running. I'm also hesitant to merge anything that's untested cos I'm not a "regular" user as such. I do use feature modules though so maybe @bmalinconico we could collab on this one? Happy to live chat elsewhere. |
@tanyagray Agree, definitely want to be careful here. Thanks for taking a look! 👍 |
@tanyagray odd, tests ran fine for me. Was it a suite error or a test failure? |
@tanyagray I'd be happy to collab on this if we can find time. I'm on the east coast of the USA and am really only on during work hours. |
Is there a workaround or older version to revert to? I just introduced lazy loaded modules to my project and this resets my state when loading the module. |
@magnattic My PR (#94) works for my use-case and I'm using it in production. In your package.json
However I started by reverting to 0.3.0 and that worked for me too but had its own issues relate to feature modules. |
Thanks for providing your PR. Unfortunately I can't get it to work with my setup:
in
The problem seems to be that it's not compatible with the custom serialize/deserialize functions I am using. This is my setup:
|
@magnattic I see what is wrong, and can update the PR. It looks like you serializing the entire If you are I'll make a small adjustment, but if you are serializing the whole state you are probably running into a different problem then I was trying to solve. |
@magnattic updated my branch, give that a try. PR hasn't updated yet. |
Thanks, this removes the error, but still overwrites my State when the feature module is loaded. This is my scenario:
What happens? When I load my feature module for Basically what I want is for localStorageSync to leave Do I have to setup my sync differently? |
@magnattic So the problem is how do we determine when to partially overwrite the state from localstorage, and when do we perform a merge. The current rules are:
If it is a object and custom serializers/deserializers are used, how do we determine if we should perform a merge or a replace. I can provide an update to get you moving if We could always add a parameter to the object to indicate the rehydrated state, when provided an object, should be merged. |
@bmalinconico I realized I misrepresented my scenario, I updated my comment above. Sorry if I am missing something, but why can't we simply do something like this?
Use the rehydratedState where possible and if a property is missing somewhere, add it from the existing state. This is working recursively. I am not sure why we need the stateKeys at all at this point. Aren't they only needed to get the rehydratedState? |
I feel like, if you are rehydrating the entire section of a state an undefined value coming from localstorage should be respected. We should only do a deep merge when you are selectively rehydrating keys. We should also be careful to ensure we are only duping one level deep, unless a true deep merge is what we are after. Either way these are behavior choices I'll leave up to owners. |
@magnattic ah I didn't see the |
I am still massively confused by the whole thing. Why are we even touching the whole state when a feature module is loaded? The 'update-reducers' action has a property |
Hi, I tried to put this PR when I noticed that my lazy loadable modules get the default state instead of the saved one. Everything worked as it should, but as soon as I connected one more module everything broke. Sorry my English :) |
The problem was solved when I specified a synchronous module in an array of keys |
@magnattic So the reason inevitable is how NGRX gets a feature module bootstrapped. See this line: https://github.com/ngrx/platform/blob/cb473c00475289509f0924321bb293d0ad1137ca/modules/store/src/reducer_manager.ts#L73 When a new feature module is bootstrapped, it isn't bootstraping with an initial state of what is currently in the state, it bootstraps with an initial state of what is provided via the As for using the @voidek-work I'm glad that fixes it for you, but what was the |
@bmalinconico If I get you right...
not working:
layout - state not lazy feature module.
if I rehydrate only lazy modules, then state reset to default. |
@voidek-work I don't see any reason in my patch for why the lack of the |
@bmalinconico |
Basically this renders this mechanism for restoring my state, useless... I don't understand what is happening but I know this is the cause. If I remove the persistence my problem goes away, unfortunately, so does my persisted state... Is anyone planing on fixing this problem? |
@ilennert I have been using my fork in production for a few months now and it is working fine. Please give it a try and report back any issues you encounter and I'll make an effort to fix them. The collaborators are not really responding to this PR... |
Is there any workaround for this scenario? |
@pedrofurtado Please see my fork and report back issues with it. |
As of 2 months ago the fork you provided me didn't work, had you presently updated? |
@bmalinconico Ok, thanks for feedback! I will test the fork 👍 |
#114 this pr causes a side effect when lazy load feature module happen. Using deep merge return a new state object will trigger unexpected changing detection. There is a demo: Printing |
So I have main root state and a lot lazy loaded modules with feature states. I just need to store root state on local storage. So I'm doing But I realized this breaks lazy loaded modules states. When I refresh a container component page that dispatches a bunch of load actions, the state should be loaded but instead state replaced with initial state. If I remove rehydrate: true, then after the refresh the state is loaded with my stuff and not replaced with initial state. But I need to keep rehydrate true there because I only fill the appState when users log in and the app state needs to be carried all across other modules and after refreshes. Work around is to put all other lazy modules with feature states in the key array. This bug report sounds like the issue that I am having. |
@chikakow , are you registering the I was having this issue when I was adding the |
@Empereol, Yes ths was exactly my problem and moving it to "forRoot" StoreModule has fixed my code! |
I am using The root store is called This is my setup: merchant.meta-reducers.ts - for the host app
app.module.ts - host app
entry.module.ts
onboarding.meta-reducer.ts - metareducer for the lazyloaded module
|
Hello,
The following PR introduced a bug related to lazy loaded feature modules: https://github.com/btroncone/ngrx-store-localstorage/pull/76/files
The net effect of this PR is to re-hydrate the state when every feature module is loaded, and this breaks sections of the state which are selectively serialized (
localStorageSync({keys: [{todos: ['name', 'status'] }, ... ]}))
).The result is the state being rehydrated and deleting all other keys not in local storage.
The text was updated successfully, but these errors were encountered: