-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Milestone
Description
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.
Metadata
Metadata
Assignees
Labels
No labels