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
v9.0.11 introduces sparse array regression #1019
Comments
Random thoughts I had about sparse arrays/elisions that might inform this request:
|
To be fair I don't think Immer very intentionally supports sparse arrays. Especially not as something to be distinguished from Imho using I recommend to use a more idiomatic alternative instead to remove elements from arrays, like assigning |
@mweststrate That makes a lot of sense, and thank you for your time! I commented on the other PR that also extends array patches for adding and removing items. Unfortunately for me 馃槈, it is a much better direction and I'm excited for it to land. Sparse arrays are uncommon, can't be represented with JSON/JSON patches, and don't work in ReduxJS. As an immer user, I'm not strictly tied to ReduxJS or a state that can be serialized into JSON, but the common use-case is better here.
I wouldn't call it happenstance that an array is an object 馃槢 Everything is an object in JS! What's the justification for claiming all sparse arrays are anti-pattern? I'm not sure I see how that fits into the conversation. |
Anti pattern, because it doesn't solve any problem that isn't solved more idiomatically otherwise, behaves unpredictable with other standard functions and libraries, and afaik de-opts from a lot of performance optimisations (that is true for |
馃悰 Bug Report
#879 looks like an awesome fix -- thank you! -- but it has a side-effect of breaking sparse arrays created with
delete
.I'm a comfortable immer user but relatively new to contributions. If someone has the time to coach, I would be glad to iterate on #879. My "hunch" is that immer should revert to actually deleting instead of setting the index to
undefined
, but the patch generation will need to be different for arrays and objects so the actual fix from #879 isn't reverted. At first glance, the es5 plugin changes look compatible with sparse arrays. Thanks for your timeTo Reproduce
Observed behavior
delete
creates dense arrays withundefined
valuesExpected behavior
delete
creates sparse arraysEnvironment
We only accept bug reports against the latest Immer version.
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: