Repository navigation
fix: preserve removed drafts with optimized array methods - #1349
jipeng6036-del wants to merge 2 commits into
Conversation
mweststrate
left a comment
There was a problem hiding this comment.
I noticed that the tests test cases like sparse arrays and getters. These kind of non-idiomatic usage of arrays is not supported by Immer, and hence its behavior should not be hitched with tests. Could you drop those?
Pop /shift fixes sound correct.
I suspect with the first note, that the old, more optimized(?) splice implementation could be kept, if you just add drafting the returned res array instead of doing a full unoptimized fallback. If not, this is fine
|
Thanks for the review. I removed the sparse-array and getter tests in 9fe517d. I kept splice on the regular proxy path. Once splice has shifted the array, the removed values alone don't carry their original positions. Some are base entries that need drafts, while newly inserted objects must retain their identity and stay undrafted. The regular proxy path already handles that distinction and preserves native argument coercion. I ran the source and production suites and Flow on the PR branch and with current main merged locally. Coverage and the performance suite also ran successfully on the merged tree. |
With
enableArrayMethods(), a recipe that moves an object between lists and then updates it can mutate the original state, or throw when the base is frozen:Read only the removed element through the existing draft proxy before optimized
pop/shift. Use the normal proxy path forsplice, preserving removed drafts, native argument coercion and sparse-array behavior. Newly inserted external objects keep their existing undrafted behavior.spliceconsequently has the standard proxy cost;pop/shiftretain their internal-copy optimization. The documentation makes that tradeoff explicit.Validation:
yarn test(4,244 source and 3,693 production tests pass; 8 skips in each), Flow, coverage and all four existing performance scripts passed. The unchanged fork Test workflow also passed on this commit.npm packartifacts: 102 public CJS/ESM checks pass across Windows/Linux; baseline defects reproduce. These are local artifacts, not a registry release.Reproduction, exact artifacts, independent checks and size/performance limitations. The size tool needed a size-only OpenSSL compatibility option; the original failed measurements are retained separately.
Prepared and validated with Codex.