Platform: Router Store: make minimal router state serializer the default

Created on 7 Nov 2019  路  9Comments  路  Source: ngrx/platform

This provides the minimal set of router state that is fully immutable and serializable. Will have to do some coordination with libraries such as Nx that use the full router state for the navigation effects.

Breaking Change Router Store

Most helpful comment

@evgenyfedorenko Hi, the routerState configured to RouterState.Full isn't compatible with these runtime checks:

runtimeChecks: {
  strictStateSerializability: true,
  strictActionSerializability: true,
}

It's due to the prototypes chain from paramMap, queryParamMap and component properties. That's why the MinimalRouterStateSerializer should be set by the default I think.

All 9 comments

I could take this one, likely will need more info

The short answer is to update the docs and update the config's default serializer to be the minimal router serializer.

But I'm assuming we would also want to update the action's to reflect the minimal payloads (e.g. usage of MinimalRouterSnapshot instead of the ActivatedRouterSnapshot).

I am playing with router store in ngrx example app and passing in full serializer

    StoreRouterConnectingModule.forRoot({
      routerState: RouterState.Full,
    }),

getting an error

ERROR Error: Detected unserializable action at "payload.routerState.root.paramMap"

Should we fix this?

@evgenyfedorenko Hi, the routerState configured to RouterState.Full isn't compatible with these runtime checks:

runtimeChecks: {
  strictStateSerializability: true,
  strictActionSerializability: true,
}

It's due to the prototypes chain from paramMap, queryParamMap and component properties. That's why the MinimalRouterStateSerializer should be set by the default I think.

@timdeschryver Do we want to be able to invoke StoreRouterConnectingModule with 0 passed in config options and default serializer to RouterState.Minimal? Currently serializer param is optional and is derived from routerState param. If only serializer is passed but not routerState it breaks if strictActionSerializability enabled. This does not make sense to me since serializer is explicitly specified already.

@timdeschryver in case you missed it.

The default options should be RouterState.Minimal and the serializer MinimalRouterStateSerializer.

If the serializer is passed, this change will most likely be a breaking change.
The fix for it would be to set the routerState to Default. This is what https://github.com/ngrx/platform/pull/2291 solves.

@timdeschryver btw, I find it a bit confusing that both routerState and serializer are present in the config, and they could be contradicting each other. I think I have a solution for that.

@alex-okrushko I agree, if I remember correctly it was done like this to not have a breaking change.

I also want to point out that it's not just setting the serializer, it's also used to dispatch the router events. With minimal, it will only dispatch the router event id and the url.

https://github.com/ngrx/platform/blob/master/modules/router-store/src/router_store_module.ts#L319-L339

Was this page helpful?
0 / 5 - 0 ratings