Skip to content

Idea: forbid grabbing non draftables in strict mode #686

Open
@mweststrate

Description

@mweststrate

🚀 Feature Proposal

See #674 and many other issues where people are surprised that Immer by default totally ignores their class instances.
The idea is that if a field contains a non-draftable object, it becomes unreadable. E.g.: produce(state, draft => { draft.buffer; }) would throw. To still use the buffer inside a draft, a explicit signal needs to be given, e.g. produce(state, draft => { mutableRef(draft.buffer).push(17); ).

Not sure about the name: mutableRef, unsafe could all work. Or maybe we could even reuse the existing original method for this purpose, although that might be confusing.

For easy backward compatibility an option enableStrictMode(boolean) could be used, by default off in the current version, and enabled in the next major.

Can this be solved in user-land code?

No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions