gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

Removed List items may affect actual items #408

Open gbiryukov opened 6 years ago

gbiryukov commented 6 years ago

Version

Tell us which versions you are using:

Expected behaviour

Removed List items shouldn't affect actual items.

Actual behaviour

This issue is edge case. Sometimes developers may use third-party libraries like react-transition-group in layout to animate some stuff. Such libraries may cache passed child elements for example to show item removal animation and remove elements from the three with delay. Since List stores child refs associated with indexes instead of keys, asynchronous manipulation with children elements may cause conflicts when two list items with different keys (removed and actual) pretend to modify ref for same index. It can cause incorrect components references in refs registry or missing refs for actual items that may lead to validation errors and crashes.

Steps to reproduce

I created jsfiddle to demonstrate this issue https://jsfiddle.net/69z2wepo/98132/

  1. remove first item from form
  2. press "inspect refs" to ensure that ref for remaining element is missing
  3. press "validate" and app will chash

you also can inspect refs before step 1 to see that refs for both items present