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

Fix runOnJS on Web and make it asynchronous #4572

Merged
merged 2 commits into from
Jun 22, 2023
Merged

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Jun 14, 2023

Summary

This PR is amending some changes from #4276 where we exchanged setImmediates for queueMicrotask for _scheduneOnJS.

queueMicrotask does not take any arguments, only a callback and the change of behaviour stemming from this was not considered in runOnJS implementation. This PR fixes this and also makes runOnJS actually call _scheduleOnJS on web, making it asynchronous and consistent with general behavior of runOnJS - before it was unreachable code on web since it would simply return the provided function that was called synchronously.

Test plan

Run WebExample and see that now runOnJS is working properly. I used the following snippet:

function foo() {
    console.log('hello');
  }

  function foz(str: string) {
    console.log(str);
  }

  runOnJS(foo)();
  runOnJS(foz)('bye');

  function bar() {
    console.log('hello again');
  }

  function baz(str: string) {
    console.log(str);
  }

  runOnUI(() => {
    runOnJS(bar)();
    runOnJS(baz)('bye again');
  })();

Before:

Screenshot 2023-06-14 at 13 45 59

After:
Screenshot 2023-06-14 at 13 45 11

@tjzel tjzel added this pull request to the merge queue Jun 22, 2023
Merged via the queue into main with commit 33b1677 Jun 22, 2023
1 check passed
@tjzel tjzel deleted the @tjzel/scheduleOnJS-fix branch June 22, 2023 12:05
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.

None yet

3 participants