-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(Store): runtime checks #1613
Conversation
c2671f7
to
f4b02ae
Compare
this.next(state); | ||
scannedActions.next(action); | ||
}, | ||
error: err => this.error(err), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was needed in order for me to test the case with an invalid next state.
Preview docs changes for f4b02ae at https://previews.ngrx.io/pr1613-f4b02ae/ |
Preview docs changes for 0f52c54 at https://previews.ngrx.io/pr1613-0f52c54/ |
Preview docs changes for 8e3eaf8 at https://previews.ngrx.io/pr1613-8e3eaf8/ |
Preview docs changes for 38e9cc1 at https://previews.ngrx.io/pr1613-38e9cc1/ |
Is this the API we had in mind? |
Yes, I like the API. A few thoughts:
|
We still have
What about making these checks opt-in v8 and log a warning on start up (in dev) that these checks will be the default in v9 or v8.x?
Is it correct that if we would flatten out the meta reducers inside the |
See fcd21bb, I lied. The user also has to add But now that I'm thinking about it, the user has to change the token from |
Preview docs changes for fcd21bb at https://previews.ngrx.io/pr1613-fcd21bb/ |
For an easy transition we could provide a linter and possibly add it to the migration script? |
Preview docs changes for 89a9b21 at https://previews.ngrx.io/pr1613-89a9b21/ |
I think we should do a separate PR to remove the non-serializable parts (paramMap, queryParamMap) from router-store so we aren't breaking too many things here. |
modules/store/src/index.ts
Outdated
@@ -6,6 +6,7 @@ export { | |||
MetaReducer, | |||
Selector, | |||
SelectorWithProps, | |||
RuntimeChecks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These don't need to be exported publicly except for USER_PROVIDED_META_REDUCERS
metaReducers, | ||
runtimeChecks: { | ||
strictStateSerializabilityChecks: false, | ||
strictActionSerializabilityChecks: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are we mutating actions? We should clean this up.
Preview docs changes for 60ce1c9 at https://previews.ngrx.io/pr1613-60ce1c9/ |
Preview docs changes for 0bd736a at https://previews.ngrx.io/pr1613-0bd736a/ |
When #1613 gets merged we have mutation checks built in
Preview docs changes for b553983 at https://previews.ngrx.io/pr1613-b553983/ |
modules/store/src/models.ts
Outdated
@@ -39,3 +39,9 @@ export type SelectorWithProps<State, Props, Result> = ( | |||
state: State, | |||
props: Props | |||
) => Result; | |||
|
|||
export interface RuntimeChecks { | |||
strictStateSerializabilityChecks: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already calling these RuntimeChecks
, so we can remove Checks
from the properties themselves.
modules/router-store/spec/utils.ts
Outdated
@@ -29,7 +29,14 @@ export function createTestModule( | |||
TestBed.configureTestingModule({ | |||
declarations: [AppCmp, SimpleCmp], | |||
imports: [ | |||
StoreModule.forRoot(opts.reducers), | |||
StoreModule.forRoot(opts.reducers, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this as its opt-in
modules/store/src/runtime_checks.ts
Outdated
if (isDevMode()) { | ||
if (runtimeChecks === undefined) { | ||
console.warn( | ||
'@ngrx/store: we added immutability and serializability runtime checks in @ngrx/store.\n' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this message short and add information about the checks to a page we link to. Another idea is to make this a comment for the RootStoreConfig
so it shows up in their IDE and makes the console less noisy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, you're right 😅 the link to a page is a good idea 👍
My intention was to log it so it will certainly be visible, but this can quickly become annoying. It will also log out the messages in people's tests... On the other hand I'm afraid this change will be unnoticed by teams if don't log it and only add a comment on RootStoreConfig
.
The consolw.warn
can be "disabled" by providing a config, this can just be an empty object.
What do you think of logging:
@ngrx/store: runtime checks are currently opt-in but will be the default in the next major version, see -link- for more information.
The link can point to the changelog, or the migration page on ngrx.io
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Preview docs changes for 74b5ce7 at https://previews.ngrx.io/pr1613-74b5ce7/ |
74b5ce7
to
9d66646
Compare
Preview docs changes for 9d66646 at https://previews.ngrx.io/pr1613-9d66646/ |
Preview docs changes for 9242ce3 at https://previews.ngrx.io/pr1613-9242ce3/ |
1 similar comment
Preview docs changes for 9242ce3 at https://previews.ngrx.io/pr1613-9242ce3/ |
@timdeschryver will you rebase so we can land this? |
Does this need to land as a rebase? Are there any breaking change commits? If so, the other commit messages need to be cleaned up. |
This includes serialization checks and mutation checks BREAKING CHANGE: The META_REDUCERS token has been renamed to USER_PROVIDED_META_REDUCERS The META_REDUCERS token has become a multi token and can be used by library authors
9242ce3
to
218a1a4
Compare
I've rebased and added a BREAKING CHANGE comment |
Preview docs changes for 218a1a4 at https://previews.ngrx.io/pr1613-218a1a4/ |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #857
What is the new behavior?
State serialization checks
Action serialization checks
Mutation checks
Remove ngrx-store-freeze ?
Remove non-serializable properties on the router ?
Does this PR introduce a breaking change?
BREAKING CHANGE:
The META_REDUCERS token has been renamed to USER_PROVIDED_META_REDUCERS
The META_REDUCERS token has become a multi token and can be used by
library authors
Other information
Based of feat/serialization-and-mutation-checks
This PR also affects #1539