dgreene1 / react-accessible-treeview

A react component that implements the treeview pattern as described by the WAI-ARIA Authoring Practices.
https://dgreene1.github.io/react-accessible-treeview
MIT License
261 stars 37 forks source link

Do not error when data has nodes removed that are expanded #174

Open blittle opened 7 months ago

blittle commented 7 months ago

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.

stale[bot] commented 5 months ago

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.

blittle commented 5 months ago

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

dgreene1 commented 5 months ago

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

stale[bot] commented 3 months ago

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] commented 2 months ago

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

mihna123 commented 2 months ago

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

dgreene1 commented 2 months ago

Stalebot closed it. I’ll reopen it.

camplowell commented 1 month ago

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

TylerAHolden commented 2 weeks ago

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.