Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producer error with nested used on an array member of the substate #522

Closed
1 of 2 tasks
gentilboulet opened this issue Jan 30, 2020 · 2 comments
Closed
1 of 2 tasks
Labels

Comments

@gentilboulet
Copy link

馃悰 Bug Report

Updating an array in a substate produces an unusable object : reusing the produced object results in an error about proxy.

Link to repro

See tests in : https://codesandbox.io/s/minimal-repro-p6r9s

(Note : codesandbox typescript version is 3.6.2, resulting in warnings with Draft<> for immer 5.3.2)

To Reproduce

function initialStateFactory(): IStoreState {
  return {
    substate: {
      array: [{ id: "id1", value: 0 }, { id: "id2", value: 0 }]
    },
    array: [{ id: "id1", value: 0 }, { id: "id2", value: 0 }]
  };
}

export const globalProducer = produce((draft: Draft<IStoreState>) => {
  draft.substate = subProducer(draft.substate);
  draft.array = arrayProducer(draft.array);
}, initialStateFactory());

const subProducer = produce((draftSubState: Draft<{ array: TArray }>) => {
  draftSubState.array = arrayProducer(draftSubState.array);
});

const arrayProducer = produce((draftArray: Draft<TArray>) => {
  draftArray[0].value += 5;
});

Observed behavior

Applying an array producer on a third level depth produces an invalid state.

On the codesandbox repro, the arrayProducer is used at second and third level depth.
On state.array, it produces the expected result.
When applied on state.substate.array, the produced array is broken.

  • Accessing the produced array show the following error, rendering it unusable :
    Cannot perform 'get' on a proxy that has been revoked
  • the modified element is still correctly modified
  • the array length is still 2
  • the second array element seems to be null in console

Expected behavior

Producers should work without issues when nested.

Environment

Was working fine in old code (1.X).
Brokes when updating immer to 5.X.
Seems to works in codesandbox up to 4.0.0-beta.0

  • Immer version: 5.3.2
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@mweststrate
Copy link
Collaborator

Will be fixed in 5.3.3

@aleclarson
Copy link
Member

馃帀 This issue has been resolved in version 5.3.3 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants