-
-
Notifications
You must be signed in to change notification settings - Fork 849
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to deep clone ignoring immer references? (deepCurrent vs currrent) #1091
Comments
This might be a bug in |
#1105 should fix the handling of Proxy properties. When drafted, they are now finalized correctly. Let me know if it isn't solved by |
Well while the issue with the nested objects in Symbols is fixed, I still need to use my version of deepCurrent, i guess it is because I check extra stuff:
|
Well it actually works, I don't need it to be recursive anymore. I will change its name to "saferCurrent" tho as it does not throw error if the object is not a draft
|
Hello!
Issue
I'm struggling to mutate an object as i need to split it and then add different things to each new end. The problem is that the original object has nested objects, so when duplicating, the original nested objects get referenced.
Lets say i have
And then i split a to:
if i do this in the same draft and i modify b:2 it affects both.
I'm trying to sue structuredClone, structuredClone(current(a)) but they don't work because the draft are embeded.
With some real data:
Basically I split the original object which has $id: ['id1' ,'id2'] into an array with two objects.
This works at the root node, i get an array with two different BzId "_0" and "_1"
But if i modify the nested object, it gets modified in both places.
I tried to use this:
...structuredClone(subNode),
But it gets this error:
[object Array] could not be cloned.
I guess this happens when it arrives to the nested structures created by immer.
Is there a way in immer to deeply clone an object and drop?
or the only way i can do right is a deepCurrent() and then use structureCloned over the result?
Immer version:
Using immer (9.0.21 as 10.0.x does not work with symbols that have references to objects)
The text was updated successfully, but these errors were encountered: