Skip to content
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

Can't import lazy-loaded module's state from json using Redux DevTools #1326

Closed
MasDevProject opened this issue Sep 9, 2018 · 6 comments
Closed

Comments

@MasDevProject
Copy link

MasDevProject commented Sep 9, 2018

I'm developing an application using Angular and ngrx with redux DevTools for Chrome. My application has also a lazy-loaded module and I configured it like this:

@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        RouterModule.forChild([
            { path: '', component: UserLazyHistoryComponent }
        ]),
        StoreModule.forFeature(moduleFeatureName, reducers),
        EffectsModule.forFeature([
            HistoryEffects
        ])
    ],
    declarations: [UserLazyHistoryComponent]
})
export class UserLazyHistoryModule { }

and this is my reducer index file:

export const moduleFeatureName = 'user-lazy-module';

export interface UserLazySate {
    history: fromHistory.HistoryState;
}

export const reducers = {
    history: fromHistory.reducer
};

export const selectHistoryModuleState = createFeatureSelector<UserLazySate>(moduleFeatureName);

export const selectHistory = createSelector(selectHistoryModuleState, s => s.history);

With this configuration everything works well but I noticed that when I export the state of the application (as a json) using the ReduxDevTools and than I upload it, the state of the lazy module is not loaded. It remains null.

If I start the application right in the state of the lazy-laoded module and then I import the json, it works, but if I start from the beginning of the app, then I import the json, using the time-slider, when I reach the lazy module the state is null (default).

Expected behavior:

The state of lazy-loaded modules should be imported correctly from json.

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

  • "@angular/cli":"6.0.8"
  • "@angular/common":"6.1.6"
  • "@ngrx/router-store":"6.1.0"
  • "@ngrx/store":"6.1.0"
  • "@ngrx/store-devtools":"6.1.0"
  • MacOs 10.13.6
  • Chrome 69
@dummdidumm
Copy link
Contributor

Duplicate of #919 (which was closed, but is not really solved yet, @brandonroberts maybe you should reopen it).

@brandonroberts
Copy link
Member

Why do you consider it not resolved? Because its not released?

@dummdidumm
Copy link
Contributor

#919 contains one specific use case which is not resolved yet, which explains the same problem of the issue which is reported here I think:

  1. Be on a page where a lazy loaded module of some other page is not loaded yet
  2. Import a JSON which, in the course of reapplying the actions, changes to the page of that lazy loaded module
  3. -> Bug: Actions are reapplied to "old" reducers. There is no logic "oh, there is a page change which has a lazy loaded reducer, let's wait for it and then continue reapplying the actions".

Part of #919 was fixed through the "wait for update reducers initially", but this specific use case was not.

@SenthilKumaranC
Copy link

SenthilKumaranC commented Nov 13, 2019

I am planning to introduce state management layer in my official angular project , I want to show a demo to team that how we can replay actions by importing jsons , but facing the same above mentioned issue. If this got resolved , then I can conduct the magic show to the team.

I am planning to add deffered actions queue in root metareducer and execute those actions again on lazy module load. But , is there anyway to check those actions are already added to store or not. Do we have any action collection to check incoming action present or not?

@dummdidumm
Copy link
Contributor

There is a "update reducers" action I think, which is called everytime a new reducer is added. If you load the app with devtools open you should see these actions. But this would be only a workaround on your side. To really fix this, we need to finish what was started in #955 .

@SenthilKumaranC
Copy link

SenthilKumaranC commented Nov 15, 2019

I can able to retain state now with lazy loading reducers but not using update reducers. I have maintained a deferred action collection , on module load ngOnit executing the action collection in side effect. For time being , this is ok for me.

One drawback is for each action call , there will be two calls - failed action call and success action call while replaying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants