immer icon indicating copy to clipboard operation
immer copied to clipboard

Idea: forbid grabbing non draftables in strict mode

Open mweststrate opened this issue 5 years ago • 1 comments

🚀 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

mweststrate avatar Oct 21 '20 08:10 mweststrate

I tried to take a stab at implementing this in https://github.com/immerjs/immer/pull/715

Gelio avatar Dec 03 '20 22:12 Gelio