immerjs / immerjs/immer

Idea: forbid grabbing non draftables in strict mode

Open
#686 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

breaking change proposal
Dominant language
JavaScript
Stars
29k
Forks
881
PR merge metrics
No merged PRs in 30d

Description

🚀 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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the referenced issue #674 and the existing Immer behavior around non-draftable class instances. The proposal leaves the API choice open between mutableRef, unsafe, original, and enableStrictMode; done would require a decided design and corresponding behavior for strict mode and backward compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.