immerjs / immerjs/immer

Excluding a single property from Object freezing

Open
#928 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue-lacks-relevant-information question
Dominant language
JavaScript
Stars
29k
Forks
881
PR merge metrics
No merged PRs in 30d

Description

🙋‍♂ Question

I am trying to buld a simple Subject/Observer pattern together with immerjs to ensure consistent update propagation in my project.
Right now immerjs is causing some trouble because I want to register an observer to an object that has run through immer and is now frozen.

Error: [Immer] This object has been frozen and should not be mutated

Basically I have to exclude the array of observers from getting touched by immer. How could I achieve that?
If it's not possible, why?

Link to repro

The codesandbox tests don't trigger my observers for some reason.
Running the same code locally gives the correct result.
The first test passes and the second test fails with the above error.

https://codesandbox.io/s/xmzig2

Environment

  • Immer version: 9.0.12
  • typescript 4.6.3
  • Jasmine 4.1.0
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)

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

Review the linked CodeSandbox and compare the first passing test with the second failing test. Check how setUseProxies(true) and setUseProxies(false) affect the frozen object and observer array. Done means determining whether a single property can be excluded from freezing and documenting the supported behavior or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.