Skip to content

Reducers are completely ignored in some cases with AOT #189

@victornoel

Description

@victornoel

I'm submitting a...


[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

What is the current behavior?

This was originally reported in #147 but it was closed by #153 even though the bug discussed there wasn't fixed.

I have a complex application with ngrx 4, only one root store (feature stores), some root effects, and lazyloading via the angular router.

When using AOT, at starts everything works fine but once the application is triggering a route (the component is lazy loaded but I'm not sure it is related since the store is already fully loaded at that point…) the actions are sent and visible via the redux devtools, but no change happens to the store.
I added some logging in one of the metareducers and it's clear that it doesn't even get there.

IMPORTANT: the problem is not about AOT making the application throwing errors, but about AOT making the application fail silently! Please refrain from reporting other issues here :)

Expected behavior:

Things should work :)

Minimal reproduction of the problem with instructions:

I couldn't reproduce it on a small repro, but my application is publicly available.

$ git clone https://gitlab.com/linagora/petals-cockpit.git
$ cd petals-cockpit
$ git checkout 9994938472d2994f07fac6903f2f5735fd5a8be3
$ cd frontend
$ yarn
$ ng serve --prod -e=dev-e2e

Login with admin/admin: nothing happens!
While if you run it with ng serve -e=dev-e2e and login, it will load as expected.

Here is for the record my setup:

export const reducers: ActionReducerMap<IStore> = {
  ui: UiReducer.reducer,
  users: UsersReducer.reducer,
  workspaces: WorkspacesReducer.reducer,
  buses: BusesReducer.reducer,
  busesInProgress: BusesInProgressReducer.reducer,
  containers: ContainersReducer.reducer,
  components: ComponentsReducer.reducer,
  serviceUnits: ServiceUnitsReducer.reducer,
  serviceAssemblies: ServiceAssembliesReducer.reducer,
  sharedLibraries: SharedLibrariesReducer.reducer,
};

// if environment is != from production
// use storeFreeze to avoid state mutation
const metaReducersDev = [storeFreeze, enableBatching];

const metaReducersProd = [enableBatching];

export const metaReducers = environment.production
  ? metaReducersProd
  : metaReducersDev;

And then use them as follows:

@NgModule({
  imports: [
    StoreModule.forRoot(reducers, { metaReducers }),
    EffectsModule.forRoot([
      WorkspacesEffects,
      BusesInProgressEffects,
      UsersEffects,
      UiEffects,
      BusesEffects,
      ContainersEffects,
      ComponentsEffects,
      ServiceAssembliesEffects,
      ServiceUnitsEffects,
      SharedLibrariesEffects,
    ]),
    // it'd be nice to have the possibility to activate redux devtools
    // even if we're in prod but only with the extension
    // since ngrx v4, no idea how to do that
    !environment.production
      ? StoreDevtoolsModule.instrument({ maxAge: 50 })
      : [],
    ...
],
  providers,
})
export class CoreModule {}

CoreModule is then imported in the main AppModule.

Version of affected browser(s),operating system(s), npm, node and ngrx:

node 8, typescript 2.4, ngrx 4.0.5, angular 4.1.3 and angular-cli 1.3.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions