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

Initial createReducer state is not frozen #939

Closed
markerikson opened this issue Mar 25, 2021 · 0 comments · Fixed by #940
Closed

Initial createReducer state is not frozen #939

markerikson opened this issue Mar 25, 2021 · 0 comments · Fixed by #940
Milestone

Comments

@markerikson
Copy link
Collaborator

Immer auto-freezes state when processed in a case reducer. However, we currently do not freeze the initial state. This means that it is possible to mutate the initial state before any actions are dispatched. Not sure if the mutation checker picks up on it or not.

Another issue is that I'm looking at updating the immutability and serialization checks to skip past frozen values for speed. If the initial state isn't frozen, we don't get the benefit there. Now, it's also likely that the initial state is almost empty so it won't take long to scan those values anyway, but I can't see a reason to not freeze the initial state.

Fortunately, it looks like it's trivial to do this by adding:

const frozenInitialState = createNextState(initialState, draft => {})

and using the frozen state instead.

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

Successfully merging a pull request may close this issue.

1 participant