React component doesn't work with React 18 Strict Mode
mschaul opened this issue · comments
Description
React 18 introduced a new check to Strict Mode which unmounts then remounts components after the initial mount. More info about this here: Updates to Strict Mode.
The lightgallery component doesn't seem to properly handle this. After activating Strict Mode, clicking any of the images doesn't open the gallery anymore. Opening it programmatically seems to work fine though.
Steps to reproduce
I modified the StackBlitz demo on the website to update React and enable Strict Mode.
Here is the link to that: https://stackblitz.com/edit/lightgallery-react-7gqgly
Environment
- Browser and version - Firefox 101.0
- OS - Windows 10
- lightGallery version - 2.4.0
Additional context
From what I could find out with some debugging, the click
event starts fine, but it tries to show the first container which was already removed during the unmount. I don't know if that means the first instance was not deleted properly, or that the state copying that React is doing somehow has this effect.
Did anyone find a workaround for it? Rather than disable StrictMode. @sachinchoolur
Update? This is definitely a deal breaker
There was an issue with setTimeout in the lightGallery destroy method. That was causing the problem.
This has been fixed in version 2.6.0-beta.2
Updated demo - https://stackblitz.com/edit/lightgallery-react-1p6ram?file=package.json
And sorry for the delay :(