Skip to content

useTreeData append stops working after selecting a key using setSelectedKeys #3288

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

Closed
nkalpak opened this issue Jul 10, 2022 · 3 comments
Closed
Labels
bug Something isn't working strict mode

Comments

@nkalpak
Copy link

nkalpak commented Jul 10, 2022

🐛 Bug Report

useTreeData append stops working after selecting a key using setSelectedKeys

🤔 Expected Behavior

append should work at all times

😯 Current Behavior

append quits working after an item is selected using setSelectedKeys

💁 Possible Solution

/

🔦 Context

I am trying to build a custom tree view component using the useTreeData hook

💻 Code Sample

https://codesandbox.io/s/currying-https-vyq7ri?file=/src/App.tsx:363-364

🌍 Your Environment

Software Version(s)
@react-stately/data 3.5.1
Browser Google Chrome
Operating System Windows 10
@snowystinger
Copy link
Member

Add Item fails the second time you call it every time, regardless of the call to setSelectedKeys. Might make sure you aren't creating two items with the same id?

@nkalpak
Copy link
Author

nkalpak commented Jul 11, 2022

Yeah, if you "add item" twice in succession in the codesandbox, I don't expect to see 2 items because the item with that id is already added.

This issue is about the item not being added at all if you first change the selection in the tree data state. The following video might help to illustrate the flow:

2022-07-11.09-25-22.mp4

Basically, there are two flows:

  1. Click on "add item" once
  2. All good, item with ID 8324823 is added

Alternatively:

  1. Click on "select 1"
  2. This calls setSelectedKeys to update the selection with the key 1
  3. Click on "add item" once
  4. Item with ID 8324823 isn't added, even though it doesn't already exist in the state

@snowystinger
Copy link
Member

Took another look, appears to be related to StrictMode. If you remove StrictMode from the codesandbox, it works as expected. StrictMode is being addressed under the umbrella Issue #779

@snowystinger snowystinger added strict mode bug Something isn't working labels Jul 11, 2022
@LFDanLu LFDanLu closed this as completed Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working strict mode
Projects
None yet
Development

No branches or pull requests

3 participants