fix(useTreeData): insert items into a child node with StrictMode#9824
fix(useTreeData): insert items into a child node with StrictMode#9824chirokas wants to merge 2 commits intoadobe:mainfrom
Conversation
snowystinger
left a comment
There was a problem hiding this comment.
Thanks so much for the PR, it'd be great if you could fill in the description. I realise this is a fairly simple one, but it'd be nice to know the original issue and how to reproduce it/how you are using it that results in this issue. Also, any information on how you diagnosed the issue and how you landed on this fix.
It can be easier if an issue is opened first. This gives us a place to discuss the problem and possible fixes. It really helps us evaluate PRs instead of making a bunch of guesses.
Again, thank you for the PR.
| insert(parentKey: Key | null, index: number, ...values: T[]) { | ||
| setItems(({items, nodeMap: originalMap}) => { | ||
| let {items: newNodes, nodeMap: newMap} = buildTree(values, originalMap, parentKey); | ||
| let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey); |
There was a problem hiding this comment.
should the update function below also do this?
There was a problem hiding this comment.
Not sure why, but the update function works fine with StrictMode.
There was a problem hiding this comment.
I've been unable to find a case where it doesn't work. If we did need to make the change though, we'd need to create the new map outside of the updateTree function so if there's multiple items to update, we don't create a new map for each one.
| insert(parentKey: Key | null, index: number, ...values: T[]) { | ||
| setItems(({items, nodeMap: originalMap}) => { | ||
| let {items: newNodes, nodeMap: newMap} = buildTree(values, originalMap, parentKey); | ||
| let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey); |
There was a problem hiding this comment.
I've been unable to find a case where it doesn't work. If we did need to make the change though, we'd need to create the new map outside of the updateTree function so if there's multiple items to update, we don't create a new map for each one.
Closes
See StackBlitz for more details.
✅ Pull Request Checklist:
📝 Test Instructions:
In the TreeWithDragAndDrop story:
🧢 Your Project: