Fix stuck lightbox (#6816)

* Fix lightbox getting stuck by fixing rAF order

If you spam opening lightbox too fast, the effect that calls rAF will clean up and set up again midflight. Unfortunately, due to rAF order being unreliable, it may fire in reverse order, causing "open, open, close" instead of "open, close, open", so it would get stuck closed. This fixes the rAF order.

* Don't allow opening another lightbox while it's open
This commit is contained in:
dan
2024-11-28 16:55:05 +00:00
committed by GitHub
parent 0aee6390fa
commit d08ce0d473
2 changed files with 40 additions and 3 deletions
+9 -1
View File
@@ -31,7 +31,15 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
const openLightbox = useNonReactiveCallback(
(lightbox: Omit<Lightbox, 'id'>) => {
setActiveLightbox({...lightbox, id: nanoid()})
setActiveLightbox(prevLightbox => {
if (prevLightbox) {
// Ignore duplicate open requests. If it's already open,
// the user has to explicitly close the previous one first.
return prevLightbox
} else {
return {...lightbox, id: nanoid()}
}
})
},
)