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

RFC: Bridgeless: Introduce unstableRequiresMainQueueSetup in modules #49957

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

RSNara
Copy link
Contributor

@RSNara RSNara commented Mar 11, 2025

Summary:

Context

Native modules can implement this method:

- (BOOL)requiresMainQueueSetup {
  return YES;
}

When this method returns true:

  • The bridge eagerly initializes the module on the main queue, during react native init.
  • But, TurboModules just lazily load the module when needed, synchronously executing the module setup on the main thread.

Problem

The turbomodule behaviour is hazardous:

  1. If javascript loads a main queue module, the js thread blocks on the main thread.
  2. And if the main thread blocks on javascript thread (via fling), react native could deadlock.

Solution

We need this "eagerly execute some code on the ui thread" functionality in React Native, in some way shape or form.

Proposal: This diff re-introduces the old functionality into turbo modules:

Buck API:
Plugin:

react_module_plugin_providers(
    name = "AccessibilityManager",
    native_class_func = "RCTAccessibilityManagerCls",
    unstable_requires_main_queue_setup = True,
)

OSS API:
codegenConfig in package.json:

"codegenConfig": {
    "name": "<SpecName>",
    "type": "<types>",
    "jsSrcsDir": "<source_dir>",
    "android": {
      "javaPackageName": "<java.package.name>"
    },
    "ios": {
      "modules": {
        "AccessibilityManager": {
          "className": "RCTAccessibilityManager",
          "unstableRequiresMainQueueSetup": true
         }
      }
    }
  },

Todos

  • introduce warnings when some or all main queue modules take too long to load,
  • think through deprecation strategy for objc "requiresMainQueueSetup" on turbomodules

Differential Revision: D70413478

RSNara added 2 commits March 11, 2025 12:27
Summary:
This will just make sure that we don't unintentionally break this script.

Changelog: [Internal]

Differential Revision: D70919549
…9905)

Summary:
Pull Request resolved: facebook#49905

This diff breaks down generate-artifacts-executor into smaller files.

Changelog: [Internal]

Differential Revision: D70795042

Reviewed By: alanleedev
@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 11, 2025
@facebook-github-bot
Copy link
Contributor

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

RSNara added 2 commits March 11, 2025 13:38
…nents

Summary:
This diff introduces annotations into the ios codegen config!

## Before
In the new architecture, people can declare module/component codegen config in [package.json](https://reactnative.dev/docs/the-new-architecture/using-codegen#configuring-codegen)

This config contains the following maps:
- modulesConformingToProtocol
- modulesProvider
- componentProvider

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modulesConformingToProtocol": {
        "RCTImageURLLoader": [
          "RCTHelloWorldImageURLLoader"
        ],
        "RCTURLRequestHandler": [
          "RCTHelloWorldURLRequestHandler"
        ],
        "RCTImageDataDecoder": [
          "RCTHelloWorldImageDataDecoder"
        ]
      },
      "modulesProvider": {
        "HelloWorldImageURLLoader": "RCTHelloWorldImageURLLoader",
        "HelloWorldURLRequestHandler": "RCTHelloWorldURLRequestHandler",
        "HelloWorldImageDataDecoder": "RCTHelloWorldImageDataDecoder"
      },
      "componentProvider": {
        "FooComponent": "RCTFooComponentClass"
      }
    }

```

## After
This information is a little bit easier to understand if we group it by module/component (into **annotations**):

(that's what this diff does!)

```
"codegenConfig": {
    "name": "HelloWorldSampleModule",
    "type": "all",
    "jsSrcsDir": "specs",
    "android": {
      "javaPackageName": "com.helloworld"
    },
    "ios": {
      "modules": {
        "HelloWorldImageURLLoader": {
          "conformsToProtocols": ["RCTImageURLLoader"],
          "className": "RCTHelloWorldImageURLLoader"
        },
        "HelloWorldURLRequestHandler": {
          "conformsToProtocols": ["RCTURLRequestHandler"],
          "className": "RCTHelloWorldURLRequestHandler"
        },
        "HelloWorldImageDataDecoder": {
          "conformsToProtocols": ["RCTImageDataDecoder"],
          "className": "RCTHelloWorldImageDataDecoder"
        }
      },
      "components": {
        "FooComponent": {
          "className": "RCTFooComponent"
        }
      },
    }

```

## Migration
The old way is still supported (for now). We will deprecate it soon, and eventually remove it from react native!

Changelog: [iOS][Added] - Codegen: Introduce module/component annotations inside package.json

Differential Revision: D70822061
Summary:
## Context
Native modules can implement this method:
```
- (BOOL)requiresMainQueueSetup {
  return YES;
}
```

When this method returns true:
- **The bridge** eagerly initializes the module on the main queue, **during** react native init.
- But, **TurboModules** just lazily load the module when needed, synchronously executing the module setup on the main thread.

## Problem
The turbomodule behaviour is hazardous:
1. If javascript loads a main queue module, the js thread blocks on the main thread.
2. And if the main thread blocks on javascript thread (via fling), react native could deadlock.

## Solution
We need this "eagerly execute some code on the ui thread" functionality in React Native, in some way shape or form.

**Proposal:** This diff re-introduces the old functionality into turbo modules:

**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
         }
      }
    }
  },
```

## Todos
- introduce warnings when some or all main queue modules take too long to load,
- think through deprecation strategy for objc "requiresMainQueueSetup" on turbomodules

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

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

@RSNara RSNara force-pushed the export-D70413478 branch from a33e5f2 to f7fe2e7 Compare March 11, 2025 21:12
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 p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants