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

Bridgeless: Implement unstableRequiresMainQueueSetup api in modules #50040

Closed
wants to merge 2 commits into from

Conversation

RSNara
Copy link
Contributor

@RSNara RSNara commented Mar 14, 2025

Summary:
This diff implements main queue module initialization.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

On Necessity

Sync dispatches to the main thread from the js thread can deadlock react native. And async dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

Caveat

This api is dangerous and discouraged. Everyone will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Mar 14, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

@RSNara RSNara force-pushed the export-D71084243 branch from f05d1cc to 4a886d9 Compare March 17, 2025 18:19
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

@RSNara RSNara force-pushed the export-D71084243 branch from 4a886d9 to 3c3feb7 Compare March 18, 2025 21:19
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from 3c3feb7 to 37168de Compare March 18, 2025 21:32
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

@RSNara RSNara force-pushed the export-D71084243 branch from 37168de to 145d66f Compare March 18, 2025 23:45
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from 145d66f to ccd3381 Compare March 18, 2025 23:51
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 18, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from ccd3381 to a39df38 Compare March 18, 2025 23:57
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from a39df38 to 86aab45 Compare March 19, 2025 00:09
…#49957)

Summary:
Pull Request resolved: facebook#49957

## Changes
This diff introduces the api for "main queue modules" into turbo modules.

This will occur occurs before any rendering.

## Rationale

Rendering can now include main -> js sync calls. If we allow js -> main sync calls during rendering, react native can deadlock.

With this diff, we can move the js -> main sync calls to before any rendering happens.

## APIs
**Buck API:**
Plugin:
```
react_module_plugin_providers(
    name = "AccessibilityManager",
    native_class_func = "RCTAccessibilityManagerCls",
    unstable_requires_main_queue_setup = True,
)
```

**OSS API:**
[codegenConfig](https://reactnative.dev/docs/the-new-architecture/using-codegen) in package.json:
```
"codegenConfig": {
    "name": "<SpecName>",
    "type": "<types>",
    "jsSrcsDir": "<source_dir>",
    "android": {
      "javaPackageName": "<java.package.name>"
    },
    "ios": {
      "modules": {
        "AccessibilityManager": {
          "className": "RCTAccessibilityManager",
          "unstableRequiresMainQueueSetup": true
         }
      }
    }
  },
```

Changelog: [iOS][Added] Introduce unstableRequiresMainQueueSetup api to modules

Differential Revision: D70413478

Reviewed By: cipolleschi
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [Both][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from 86aab45 to f145b98 Compare March 19, 2025 16:36
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from f145b98 to 171b377 Compare March 19, 2025 16:47
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@RSNara RSNara force-pushed the export-D71084243 branch from 171b377 to 8a6b7e9 Compare March 19, 2025 17:04
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Reviewed By: mdvacca

Differential Revision: D71084243
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D71084243

@RSNara RSNara force-pushed the export-D71084243 branch from 8a6b7e9 to b088fb9 Compare March 19, 2025 21:19
RSNara added a commit to RSNara/react-native that referenced this pull request Mar 19, 2025
…#50040)

Summary:
Pull Request resolved: facebook#50040

This diff implements main queue module setup.

Sometimes, people need to capture uikit things, and use them from javascript. In those cases, people can write main queue modules. These modules will be eagerly initialized on the main queue, during react native init.

## On Necessity
**Sync** dispatches to the main thread from the js thread can deadlock react native. And **async** dispatches to the main thread from the js thread sometimes might not be enough: it could lead to flickery rendering. So, we need to allow people to capture ui thread things, before any js executes.

## Caveat
This api is dangerous and discouraged. All react native surfaces will pay the cost of one surface introducing a main queue module. It could also slow down common/critical interactions in your app, if you're not careful.

We will introduce performance logging for this infrastructure. So that we can monitor and file tasks, when main queue module init starts taking "too long."

Changelog: [General][Breaking]: Introduce beforeload callback arg into ReactInstance::loadScript

Differential Revision: D71084243

Reviewed By: mdvacca
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 061174c.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants