Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when trying to call non-worklet from UI thread #3821

Merged
merged 5 commits into from
Nov 30, 2022

Conversation

kmagiera
Copy link
Member

Summary

After #3722 the error message presented after attempting to synchronously call React runtime function from the UI runtime has changed and became less descriptive than before. This PR adds a way for us to throw a more descriptive error in such scenario.

Test plan

Use the following code:

function rnMethod() {
  console.log('from RN');
}

function uiMethod() {
  'worklet';
  rnMethod(); // this should throw
}

runOnUI(uiMethod)();

Before this change you'd get a generic "Object is not a function" thrown at the line where we call rnMethod, now the error message says "Tried to synchronously call a non-worklet function" and presents possible solution (see the diff for the whole error message)

src/reanimated2/core.ts Outdated Show resolved Hide resolved
src/reanimated2/core.ts Outdated Show resolved Hide resolved
src/reanimated2/core.ts Outdated Show resolved Hide resolved
src/reanimated2/core.ts Outdated Show resolved Hide resolved
kmagiera and others added 4 commits November 30, 2022 16:20
Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
@kmagiera kmagiera merged commit ecf719a into main Nov 30, 2022
@kmagiera kmagiera deleted the shareables/errors-for-non-worklet-call branch November 30, 2022 16:18
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…oftware-mansion#3821)

## Summary

After software-mansion#3722 the error message presented after attempting to
synchronously call React runtime function from the UI runtime has
changed and became less descriptive than before. This PR adds a way for
us to throw a more descriptive error in such scenario.

## Test plan

Use the following code:
```
function rnMethod() {
  console.log('from RN');
}

function uiMethod() {
  'worklet';
  rnMethod(); // this should throw
}

runOnUI(uiMethod)();
```

Before this change you'd get a generic "Object is not a function" thrown
at the line where we call `rnMethod`, now the error message says "Tried
to synchronously call a non-worklet function" and presents possible
solution (see the diff for the whole error message)

Co-authored-by: Tomek Zawadzki <tomasz.zawadzki@swmansion.com>
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