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

When using RouterState.Full in router-store: "Cannot assign to read only property 'tView' of object '[object Object]'" #2510

Closed
adrdilauro opened this issue May 5, 2020 · 5 comments

Comments

@adrdilauro
Copy link

Minimal reproduction of the bug/regression with instructions:

Initialising @ngrx/router-store in the following way causes an exception

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

The error is the following

ERROR Error: Uncaught (in promise): TypeError: Cannot assign to read only property 'tView' of object '[object Object]'
    at getOrCreateTComponentView (core.js:7625)
    at createRootComponentView (core.js:18912)
    ...

The error I am seeing seems to be related to #2109, which was apparently fixed in #2351, but had a recrudescence in #2404.

I inspected the source code, and found out that, at line https://github.com/ngrx/platform/blob/master/modules/router-store/src/router_store_module.ts#L172, DefaultRouterStateSerializer is used instead of MinimalRouterStateSerializer by default, when you specify that you want to use RouterState.Full.

Following the discussion in #2404, I suspect that the cause of the error is that, at line https://github.com/ngrx/platform/blob/master/modules/router-store/src/serializers/default_serializer.ts#L30 of the default serialiser, you are including in the serialised data the component that is attached to the route: such component is not an @ngrx component, thus it doesn't get included in the fix done in PR #2351.

Explicitly forcing MinimalRouterStateSerializer is a workaround that avoids the exception, like this:

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

Finally, I am seeing this error regardless of the presence of strict checks.

Expected behavior:

I should be able to configure RouterState.Full in StoreRouterConnectingModule.forRoot() without having to add MinimalRouterStateSerializer.

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

  • @ngrx/store: 9.0.0
  • @ngrx/router-store: 9.1.0
  • @angular/core: 9.0.6
  • node: 12.13.0

Other information:

I would be willing to submit a PR to fix this issue

[x] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@adrdilauro adrdilauro changed the title When using RouterState.Full in router-state: "Cannot assign to read only property 'tView' of object '[object Object]'" When using RouterState.Full in router-store: "Cannot assign to read only property 'tView' of object '[object Object]'" May 5, 2020
@timdeschryver
Copy link
Member

Can you try this with the latest @ngrx/store and @ngrx/router-store version (v9.1.1) please?

@adrdilauro
Copy link
Author

@timdeschryver with that version I get the following error:

Screen Shot 2020-05-07 at 16 51 50

@timdeschryver
Copy link
Member

timdeschryver commented May 13, 2020

Thanks @adrdilauro.

This is the desired result, as it's also noted in our docs.
IIRC we did this because this configuration was the default in previous versions.
Do you recall something about this @brandonroberts ?

We could make the MinimalSerializer also the default for the RouterState.Full option, but I'm not sure why this would be helpful. If you're using RouterState.Full, my guess is that you want the full router event stored and added to the action.

@brandonroberts
Copy link
Member

Yea, we had to do it that way because of the navigationId/event information I believe. This should not be an issue with the latest release. If it is re-open the issue.

@Frankitch
Copy link

I stumbled upon this issue.
As stated in the docs I set the runtime check strictStateSerializability to false (default) but I also had to set strictStateImmutability to false to make it work...

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

4 participants