-
Notifications
You must be signed in to change notification settings - Fork 8
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
ensureVisible inside useEffect and "two children with the same key" #9
Comments
Apologies for the late response, been caught with a whole bunch of stuff. It seems that the error consistently happens with key 13. Before I investigate if there's anything wrong with the harness, are you experiencing any error like this in your production/real app too? Btw I'm curious to know what are you using |
No problem! It seems to depend on the height of And another strange case (see https://codesandbox.io/s/thirsty-dust-qq0xd?file=/src/App.js):
The error will happen when you reach the folder with 1 file, as the next entries' keys will mix up. Note: It will not happen if the whole tree is expanded beforehand (so perhaps ensureVisible will only do the scrolling). It will also not happen if after the 1-file folder there are less than 4 entries (perhaps this is connected with how many entries are pre-rendered?). As for the use case, I have a flat list of paths (similar to the examples) out of which I build an fp-ts/Tree and then I use The Tree allows me to count how many files each directory has (up to the root, which will show the count of all files), and also track other metadata for the directory (which depends on its files' content). I also use it in In each So this family of libraries (aspen) is fantastic - not only is if fast (2000+ entries are not a problem - scrolling, expanding/collapsing), but it also gives enough flexibility. |
We also ran into a similar issue when trying to 'expand all' directories on initial load. Sometimes we get overlapping keys. I think this might be a timing issue somewhere? It seems like the same row is rendered once collapsed and once expanded. |
Will allocate some time this week to put some breakpoints and see what's going on. |
After some experiments I have pinpointed it to FileTree.tsx - getItemAtIndex. If I bypass the Turning the cache back on, when I add |
Am I understanding correctly that if caching mechanism is active, then different indexes can sometimes return same prop data? |
I think so. My interpretation is that when a directory is unfolded (due to ensureVisible), the elements in the list change their index. |
@nikhil-mohite can you please create a very minimal codesandbox, just bare enough to reproduce your specific same key issue? This is to ensure we have knowledge of all the ways this issue can be triggered. Also, note that there will be no further development towards the current version of Aspen, all the resources are now dedicated towards Aspen 2. You can follow the progress here. Click |
Reproduction: https://codesandbox.io/s/sweet-mestorf-jcqoo?file=/src/App.js
In short, I have to track the path of the file that is currently selected. It can be changed externally (i.e. not from the tree), as in the example via next/prev buttons. I pass this state to the tree so that the folders expand when necessary via
ensureVisible
.If you click "NEXT" several times, React will complain that there are "two children with the same key", and indeed, you can see how the labels mix up.
Any ideas?
The text was updated successfully, but these errors were encountered: