fix: wrap onEnd gesture handler to prevent worklets bundle-mode crash (deltaYOnGestureStart)#535
Open
nazmiaydogdu wants to merge 1 commit into
Open
fix: wrap onEnd gesture handler to prevent worklets bundle-mode crash (deltaYOnGestureStart)#535nazmiaydogdu wants to merge 1 commit into
nazmiaydogdu wants to merge 1 commit into
Conversation
… (deltaYOnGestureStart)
|
@nazmiaydogdu is attempting to deploy a commit to the Ammar Ahmed's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
With
react-native-reanimatedv4 /react-native-workletsin bundle mode, dragging a sheet to dismiss crashes at the end of the pan gesture:Repro versions: react-native-actions-sheet 10.1.2, react-native-reanimated 4.5.0, react-native-worklets 0.10.0 (Babel plugin with
bundleMode: true,strictGlobal: true).Root cause
In bundle mode the worklets Babel plugin extracts each gesture callback into its own worklet file and serializes its closure. The pan gesture passes
onEnddirectly:So the extracted worklet is
onEnd, whose first statement writes a mutable closure primitive:onChangedoes not crash because it is passed wrapped in an arrow function: the extracted worklet is a thin shim that just callsonChange(captured by reference), and with.runOnJS(true)that call runs on the JS thread where the closure is intact.onEndlacks this indirection.Fix
Wrap
onEndthe same wayonChangealready is, so the extracted worklet is a thin shim and the closure writes happen in the real JS function:One line, no behavior change:
onEndstill runs on the JS thread via.runOnJS(true), identical to howonChangeis handled.Test plan
gestureEnabledand a scrollable body, on an app using reanimated 4 / worklets bundle mode.