Skip to content

[General] Do not prepare config multiple times#4144

Open
m-bert wants to merge 4 commits intomainfrom
@mbert/do-not-prepare-config-twice
Open

[General] Do not prepare config multiple times#4144
m-bert wants to merge 4 commits intomainfrom
@mbert/do-not-prepare-config-twice

Conversation

@m-bert
Copy link
Copy Markdown
Collaborator

@m-bert m-bert commented May 4, 2026

Description

Calling preapreConfig multiple times with the same config object results in warning from react-native-worklets, as the config object is frozen once it is passed to the native side (e.g. bindSharedValues)

I've used similar technique as with disableReanimated - memoize config and check whether it has changed. If not - there's no need to call prepareConfig again.

Test plan

Tested on the repro app.

Copilot AI review requested due to automatic review settings May 4, 2026 15:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent calling prepareConfig multiple times for the same gesture config object, avoiding react-native-worklets warnings caused by the config being frozen after being sent to native.

Changes:

  • Replace the one-time memoization of disableReanimated with memoization of the initial config object.
  • Add a guard intended to skip repeated prepareConfig(config) calls when the config hasn’t changed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +50
if (config !== previousConfig) {
prepareConfig(config);
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread packages/react-native-gesture-handler/src/v3/hooks/useGesture.ts Outdated
m-bert and others added 3 commits May 4, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants