Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes https://bsky.app/profile/breakintoprogram.co.uk/post/3lbxo3eouis2v.
When you spam-tap the image many times, you may end up with
nextLightbox
changing midway through the animation:nextLightbox
isnull
(lightbox is closed)nextLightbox
is an objectnextLightbox
is a different objectThis sequence would cause this effect to be cleaned up and re-set up:
social-app/src/view/com/lightbox/ImageViewing/index.tsx
Lines 102 to 127 in 84796c1
The logic there should handle that scenario fine, but it didn't. In particular, I used rAF to work around a Reanimated bug but bumped into a React Native bug. The expected order of operations in case of an interruption was:
1
0
1
But due to the rAF callback order in React Native, we'd do:
1
0
)1
)1
0
So we'd get stuck at
0
as the final frame and the screen would freeze in an inconsistent state.The Fix
There are two parts to the fix:
cancelAnimationFrame
etc. So this is a scoped hackfix.lightbox -> null
andnull -> lightbox
which is easier to think about.lightbox -> null -> otherLightbox
could get batched intolightbox -> otherLightbox
. For now it seems unlikely, we can revisit with Fabric if that can happen.Test Plan
First, go back to
main
. Do this for testing:Also add these logs:
Verify that you can still spam the lightbox into emitting:
Note the flipped order of
queue
andset
, that's the bug.Then cherry-pick the first commit. Verify you can still spam the lightbox but you get:
So it doesn't get stuck anymore.
Then undo the first fix (go back to
requestAnimationFrame
) and test the second commit. Verify that that fix alone is also sufficient on its own because you don't get interrupted at all:Finally, test with both commits. They should not interfere with each other.
For fun, you can also try this:
This disables the blocking overlay entirely. Verify you can't completely break the lightbox by spamming (despite more gestures being enabled) — it will eventually settle in some final state.
Try on both iOS and Android.