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

delete an element in the array, patches is an empty array #879

Closed
1 of 3 tasks
blinkcat opened this issue Dec 7, 2021 · 3 comments
Closed
1 of 3 tasks

delete an element in the array, patches is an empty array #879

blinkcat opened this issue Dec 7, 2021 · 3 comments
Labels

Comments

@blinkcat
Copy link

blinkcat commented Dec 7, 2021

馃悰 Bug Report

immer v9.0.7
just delete an element in the array, it is not difficult to reproduce the bug, please take a look at the following demo or code.

Link to repro

demo

To Reproduce

import { produceWithPatches, enablePatches } from 'immer';

enablePatches();

const [newState, patches, inversePatches] = produceWithPatches(
  [1, 2, 3],
  (draft) => {
    delete draft[2];
  }
);

console.log(newState, patches, inversePatches);
// output:
// [1, 2, undefined] [] []

Observed behavior

As described above, patches and inversePatches are all empty

Expected behavior

They should not be empty.

Environment

We only accept bug reports against the latest Immer version.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
@github-actions
Copy link
Contributor

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

The release is available on:

Your semantic-release bot 馃摝馃殌

@bever1337
Copy link

bever1337 commented Feb 26, 2023

Do I understand this prevents immer from creating sparse arrays with delete? I've spent the evening slowly removing pieces of my stack and API calls trying to find issues with sparse indices. I have no trouble creating sparse arrays using "proxied mutation"

// produces [<empty>,42]
(draftState: Draft<{ values: [] }>) => {
  values[1] = 42;
}

Then:

// produces [undefined, undefined]
// expected [<empty>, <empty>]
(draftState: Draft<{ values: [] }>) => {
  delete values[1];
}

@bever1337
Copy link

bever1337 commented Feb 28, 2023

Be careful using the stackblitz console to test the reproduction results. It runs a parser on the input data which casts holes to undefined. Opening the browser's devtools reveals the proper output (no undefined values).

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

2 participants