react-collapse icon indicating copy to clipboard operation
react-collapse copied to clipboard

Block stays expenaded with isOpened=false

Open ascrazy opened this issue 3 years ago • 4 comments

There appears to be a bug for the case when isOpened value changes to true and then immediatelly changes back to false (because of useEffect). Please see Demo2Inner in this Codepen - https://codepen.io/ascrazy/pen/MWmJWYR?editors=0010

Screen Shot 2021-07-13 at 15 24 56

ascrazy avatar Jul 13 '21 12:07 ascrazy

If I postpone syncyng up value and initialValue just for 50ms (so isOpened becomes true then switches back to false in ~50ms) - problem is gone.

    React.useEffect(() => {
      setTimeout(() => setValue(initialValue), 50);
    }, [initialValue]);

ascrazy avatar Jul 13 '21 12:07 ascrazy

Also had the same issue. Can't believe something as obvious as this is a persisting bug. Fixed it by debouncing the state that is tied to Collapse opening & closing (https://thewebdev.info/2021/03/14/how-to-use-the-react-useeffect-hook-with-debounce/).

bot19 avatar Nov 12 '21 02:11 bot19

Hey @bot19, if that is so obvious and this is a solution you believe is worth having - feel free to fork library, publish with your own namespace and use it. I am not getting paid for anything done here and I have spent a lot of my personal free time working on these libs and maintaining them as much as I could. Good luck with your open-source journey 👌🏻

nkbt avatar Nov 12 '21 03:11 nkbt

The reason for this and other bugs is that the container's height is fixed into px every time React calls getSnapshotBeforeUpdate(), which happens a bunch of times during the normal application lifecycle.

This is fixed in kir4ik's pull request: https://github.com/nkbt/react-collapse/pull/310

tobia avatar Jan 23 '23 11:01 tobia