react-accessible-treeview icon indicating copy to clipboard operation
react-accessible-treeview copied to clipboard

Do not error when data has nodes removed that are expanded

Open blittle opened this issue 1 year ago • 9 comments

We use react-accessible-treeview at Shopify along with folder/file search. With our implementation the rendered nodes change based on the search query. We also want the nodes to default to being expanded. As shown with the included test, TreeView breaks when re-rendered where both the data and expandedIds props change.

The problem is that the previous expandedIds data is stored, and the difference is calculated. But an ID should not be included in the difference if that ID doesn't still exist in the data. As I see it, there are two solutions:

  1. If the id is not found in the data, ignore it. That's what's implemented in this PR, inspired by https://github.com/dgreene1/react-accessible-treeview/pull/132
  2. Change the difference function to take the tree data as a param, and only add an ID to the diff if it's still in the data tree.

This resolves #133

I think I have a workaround by never removing nodes from the tree, and instead adding a boolean to the metadata whether or not it should be displayed.

blittle avatar Feb 01 '24 20:02 blittle

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 09 '24 21:04 stale[bot]

I'm happy to update the PR in any way if necessary to get it merged. Thank you in advance.

blittle avatar Apr 12 '24 19:04 blittle

@blittle I’ve asked my team to look at it

dgreene1 avatar Apr 15 '24 22:04 dgreene1

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 14 '24 23:06 stale[bot]

This issue was closed automatically since it was marked as stale because it has not had recent activity. Thank you for your contributions.

stale[bot] avatar Jun 22 '24 02:06 stale[bot]

Why was this closed? I think this is a fine solution to issue #133

mihna123 avatar Jun 26 '24 13:06 mihna123

Stalebot closed it. I’ll reopen it.

dgreene1 avatar Jun 26 '24 13:06 dgreene1

I'd really love to see this get merged. Working around it from outside the library is proving to be a very convoluted process.

camplowell avatar Jul 21 '24 00:07 camplowell

Would like to see this merged as well. I'm trying to save expanded state when watching a filesystem folder, so if a subfolder is deleted on the OS and the expandedId was saved in local state then it errors because the node doesn't exist in the tree anymore. A "quiet" failure is expected for my use-case. I would expect just like this PR fixes, the node is ignored.

TylerAHolden avatar Aug 26 '24 18:08 TylerAHolden