Skip to content

Push ReactContext logic in derived classes#44226

Closed
RSNara wants to merge 1 commit intofacebook:mainfrom
RSNara:export-D56064036
Closed

Push ReactContext logic in derived classes#44226
RSNara wants to merge 1 commit intofacebook:mainfrom
RSNara:export-D56064036

Conversation

@RSNara
Copy link
Copy Markdown
Contributor

@RSNara RSNara commented Apr 23, 2024

Summary:
Changelog: [Android][Removed] Delete ReactContext.initializeWithInstance(). ReactContext now no longer contains legacy react instance methods. Please use BridgeReactInstance instead.

Yet another attempt to land this (last one was D55964787).

Copy-pasting below the amazing summary from RSNara.

Context

Prior, ReactContext used to implement bridge logic.

For bridgeless mode, we created BridgelessReactContext < ReactContext

Problem

This could lead to failures: we could call bridge methods in bridgeless mode.

Changes

Primary change:

  • Make all the react instance methods inside ReactContext abstract.

Secondary changes: Implement react instance methods in concrete subclasses:

  • New: BridgeReactContext: By delegating to CatalystInstance
  • New: ThemedReactContext: By delegating to inner ReactContext
  • Unchanged: BridgelessReactContext: By delegating to ReactHost

Auxiliary changes

This fixes ThemedReactContext in bridgeless mode.

Problem: Prior, ThemedReactContext's react instance methods did not work in bridgeless mode: ThemedReactContext wasn't initialized in bridgeless mode, so all those methods had undefined behaviour.

Solution: ThemedReactContext now implements all react instance methods, by just forwarding to the initialized ReactContext it decorates (which has an instance).

NOTE: Intentionally not converting BridgeReactContext to Kotlin to minimize the risk of these changes.

Reviewed By: cortinico

Differential Revision: D56064036

@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 Apr 23, 2024
@analysis-bot
Copy link
Copy Markdown

analysis-bot commented Apr 23, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,542,743 -1
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,912,807 +11
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: e67d556
Branch: main

@RSNara RSNara force-pushed the export-D56064036 branch 8 times, most recently from d443ee2 to b5c7d01 Compare April 26, 2024 14:38
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@RSNara RSNara force-pushed the export-D56064036 branch from 44e86f4 to a2a0e85 Compare May 3, 2024 18:29
@RSNara RSNara force-pushed the export-D56064036 branch from a2a0e85 to 1815f16 Compare May 15, 2024 14:17
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

1 similar comment
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@RSNara RSNara force-pushed the export-D56064036 branch from 1815f16 to d416f14 Compare May 15, 2024 14:55
Summary:
Changelog: [Android][Removed] Delete ReactContext.initializeWithInstance(). ReactContext now no longer contains legacy react instance methods. Please use BridgeReactInstance instead.

Yet another attempt to land this (last one was D55964787).

Copy-pasting below the amazing summary from RSNara.

## Context
Prior, ReactContext used to implement bridge logic.

For bridgeless mode, we created BridgelessReactContext < ReactContext

## Problem

This could lead to failures: we could call bridge methods in bridgeless mode.

## Changes
Primary change:
- Make all the react instance methods inside ReactContext abstract.

Secondary changes: Implement react instance methods in concrete subclasses:
- **New:** BridgeReactContext: By delegating to CatalystInstance
- **New:** ThemedReactContext: By delegating to inner ReactContext
- **Unchanged:** BridgelessReactContext: By delegating to ReactHost

## Auxiliary changes
This fixes ThemedReactContext in bridgeless mode.

**Problem:** Prior, ThemedReactContext's react instance methods did not work in bridgeless mode: ThemedReactContext wasn't initialized in bridgeless mode, so all those methods had undefined behaviour.

**Solution:** ThemedReactContext now implements all react instance methods, by just forwarding to the initialized ReactContext it decorates (which has an instance).

NOTE: Intentionally not converting `BridgeReactContext` to Kotlin to minimize the risk of these changes.

Reviewed By: cortinico

Differential Revision: D56064036
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@RSNara RSNara force-pushed the export-D56064036 branch from d416f14 to ea3e4d3 Compare May 21, 2024 14:57
@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label May 21, 2024
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been merged in fb23470.

@github-actions
Copy link
Copy Markdown

This pull request was successfully merged by @RSNara in fb23470.

When will my fix make it into a release? | How to file a pick request?

kosmydel pushed a commit to kosmydel/react-native that referenced this pull request Jun 11, 2024
Summary:
Pull Request resolved: facebook#44226

Changelog: [Android][Removed] Delete ReactContext.initializeWithInstance(). ReactContext now no longer contains legacy react instance methods. Please use BridgeReactInstance instead.

Yet another attempt to land this (last one was D55964787).

Copy-pasting below the amazing summary from RSNara.

## Context
Prior, ReactContext used to implement bridge logic.

For bridgeless mode, we created BridgelessReactContext < ReactContext

## Problem

This could lead to failures: we could call bridge methods in bridgeless mode.

## Changes
Primary change:
- Make all the react instance methods inside ReactContext abstract.

Secondary changes: Implement react instance methods in concrete subclasses:
- **New:** BridgeReactContext: By delegating to CatalystInstance
- **New:** ThemedReactContext: By delegating to inner ReactContext
- **Unchanged:** BridgelessReactContext: By delegating to ReactHost

## Auxiliary changes
This fixes ThemedReactContext in bridgeless mode.

**Problem:** Prior, ThemedReactContext's react instance methods did not work in bridgeless mode: ThemedReactContext wasn't initialized in bridgeless mode, so all those methods had undefined behaviour.

**Solution:** ThemedReactContext now implements all react instance methods, by just forwarding to the initialized ReactContext it decorates (which has an instance).

NOTE: Intentionally not converting `BridgeReactContext` to Kotlin to minimize the risk of these changes.

Reviewed By: cortinico

Differential Revision: D56064036

fbshipit-source-id: 2e380bf7ee46892c5fc0044b03a929f12d122157
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.

3 participants