Commit Graph

5193 Commits

Author SHA1 Message Date
Ingrid Wang fdf4ec3297 Remove unused handler on PushNotificationIOS.removeEventListener (#43037)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43037

Changelog:
[iOS][Breaking] Removing unused `handler` param on  PushNotificationIOS.removeEventListener

Reviewed By: philIip

Differential Revision: D53781102

fbshipit-source-id: a3372d0ccb4addf9983c143fb1a3e206f6aae103
2024-02-16 15:22:49 -08:00
Ingrid Wang 1bd45768e3 Update docs on PushNotificationIOS (#43038)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43038

Changelog:

[Internal] Documentation edits

Reviewed By: philIip

Differential Revision: D53782268

fbshipit-source-id: b13ce5e64f9fc106d29f9b04fb6b7ba3e2ae0b2c
2024-02-16 15:22:49 -08:00
Ingrid Wang 713ded1d5f Tweak documentation for soundName property (#43004)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43004

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D53734570

fbshipit-source-id: e2233b4a2f1bcb48af5d56319d215eb0ccceaa4e
2024-02-16 15:22:49 -08:00
Moti Zilberman da03d7b829 Implement Runtime.addBinding (global bindings only) (#43065)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43065

Changelog: [Internal]

Implements support for [`Runtime.addBinding`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#method-addBinding) in the new RN CDP backend.

This implementation is mostly complete and matches Chrome's behaviour, but does not include the ability to target bindings by execution context (the optional `executionContextId` and `executionContextName` params) - that will come in a separate diff for ease of review/landing.

Incidentally, this diff also introduces the `JsiIntegrationPortableTest::expectMessageFromPage` helper, which allows us to "asynchronously" extract the contents of an expected message. For consistency and clarity, we refactor all the other `EXPECT_CALL(this->fromPage(), onMessage(JsonEq(...)))` assertions to use it as well.

Reviewed By: huntie

Differential Revision: D53266709

fbshipit-source-id: 046326acdf5dacc18e179e43589cdd2d012f353a
2024-02-16 11:16:41 -08:00
Moti Zilberman 828ad04cef Assign auto-incrementing execution context IDs (#43064)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43064

Changelog: [Internal]

Aligns React Native's CDP backend with V8's behaviour of assigning a sequential ID (here unique within a given PageTarget) to each execution context.

Reviewed By: huntie

Differential Revision: D53776531

fbshipit-source-id: 950599c323f416e8180e42281d94ae9c00f15fb0
2024-02-16 11:16:41 -08:00
Moti Zilberman e34e7d75b3 Lift execution context management out of Runtime (#43063)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43063

Changelog: [Internal]

Moves the responsibility for managing CDP execution contexts out of the Runtime and into the Instance.

This includes the responsibilities to:
1. Assign execution context IDs/names
2. Emit events when execution contexts are created/destroyed
3. Route CDP messages to the correct Runtime

**Re 1:** We currently assign a *constant* execution context ID, which diverges from V8's implementation but is in line with what Hermes has done so far. I'll follow up separately to assign (locally) unique IDs, since this diff is long enough already.

**Re 3:** Right now, the message routing responsibility is mostly theoretical: only one Runtime exists at a time and "routing" can be done by RuntimeAgent simply deciding whether or not to act on a message (since it receives all messages by default and knows its own `ExecutionContextDescription`). True multi-Runtime / multi-context support is firmly a future concern, and we can revisit this ( = probably hoist more logic into Instance) when we get there.

In the `ExecutionContextNotifications` integration test we can see that a few minor bugs in the current Hermes-based implementation are fixed, and also that execution context management is now engine-agnostic (so we can use `JsiIntegrationPortableTest` instead of `JsiIntegrationHermesTest`).

Reviewed By: huntie

Differential Revision: D53759776

fbshipit-source-id: 50ac126789c95b25f845780df2c3346ec345d5d5
2024-02-16 11:16:41 -08:00
Riccardo Cipolleschi 5164e83c3b Fix the compiler flags for libraries (#43071)
Summary:
While looking at another issue, I realized that in some cases the script was adding the same flags twice and it was leaving the RCT_NEW_ARCH_ENABLED behind.

## Changelog:
[iOS][Fixed] - Pass the right flags to libraries

Pull Request resolved: https://github.com/facebook/react-native/pull/43071

Test Plan: Fixed Unit tests

Reviewed By: huntie

Differential Revision: D53860576

Pulled By: cipolleschi

fbshipit-source-id: 1f6f4852df8d316293b93d7c5fbef09a249893a5
2024-02-16 10:39:01 -08:00
Riccardo Cipolleschi f61f87c5ef Make the addUIBlock's Dictionary works correctly (#43060)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43060

When inestigating the reason why [`react-native-view-shot`]() ws not working, we realized that there are many libraries that follows this pattern:

```objc
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
    if (UIView *view = viewRegistry[reactTag]) {
      //do something with the View
    }
  }];
```
The problem is that, with the New Architecture, that view registry is usually empty, because the components are registered and tracked in another place.
This make many libraries stop working when used with the New Architecture.

This change introduces a class that behaves like a dictionary but that forward the calls to retrieve the view to the right place, in order to get the view that is needed.

Noticably, this approach allow us also to remove some shenanigans we were applying to make sure that the interop layer could access the views wrapped in it, so the current solution is more general and should work in multiple situations.

## Changelog
[iOS][Fixed] - Make sure that `addUIBlock` provides a Dictionary-look-alike object that returns the right views when queried.

Reviewed By: sammy-SC

Differential Revision: D53826203

fbshipit-source-id: 08d359676d69777b88fa9b18dc141187ac42dbce
2024-02-16 09:39:44 -08:00
Nicola Corti 906985b097 Back out "Update RNGP to handle cxxModule in codegenConfig" (#43050)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43050

Original commit changeset: 702f09ccf793

Original Phabricator Diff: D53669912

Changelog:
[Internal] [Changed] - Back out "[RN][Android][TmCxxAutolinking] Update RNGP to handle cxxModule in codegenConfig"

Reviewed By: cipolleschi

Differential Revision: D53812110

fbshipit-source-id: a7583c0cb8354bf31723794fbbb4ca5de8f1790a
2024-02-16 09:20:02 -08:00
Nicola Corti 2697b9af5c Back out "Add cxxModule to RN-Tester's codegenConfig" (#43051)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43051

Original commit changeset: 97b9985b94ef

Original Phabricator Diff: D53669913

Changelog:
[Internal] [Changed] - Back out "[RN][Android][TmCxxAutolinking] Add cxxModule to RN-Tester's codegenConfig"

Reviewed By: cipolleschi

Differential Revision: D53812108

fbshipit-source-id: 5c5dfbaf95685953ef20cf35061a72afffe00ed3
2024-02-16 09:20:02 -08:00
Riccardo Cipolleschi 267ea2661a Convert RCTConvert to mm in preparation for DisplayP3 changes
Summary:
This is a preliminary change which converts RCTConvert to an objectiveC++ file. This is required by the next diffs in the stack.

## Changelog
[iOS][Changed] - Make RCTConvert an Objective-C++ (`.mm`) file in prep for DisplayP3 changes

Reviewed By: javache

Differential Revision: D53520228

fbshipit-source-id: cf45c42955401b4e14fe68221129077817b2598e
2024-02-16 09:15:49 -08:00
David Vacca 15700626cc Enable FabricPendingEventQueue by default in RN OSS (#43029)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43029

Enable FabricPendingEventQueue by default in RN OSS

changelog: [internal] internal

Reviewed By: cortinico

Differential Revision: D53766819

fbshipit-source-id: 53529b10a3880702867793c3eeae216a2c3f4cea
2024-02-15 11:49:19 -08:00
Oskar Kwaśniewski c5f48ac612 feat: make __gitignore file work for OOT platforms (#42963)
Summary:
This PR makes `__gitignore` file universal for Apple OOT platforms.

## Changelog:

[GENERAL] [CHANGED] - Make template's .gitignore file universal for OOT platforms

Pull Request resolved: https://github.com/facebook/react-native/pull/42963

Test Plan: CI Green

Reviewed By: NickGerleman

Differential Revision: D53674632

Pulled By: yungsters

fbshipit-source-id: cb510d9bd2ee6f1c39b77a842e7947b67def552a
2024-02-15 11:44:42 -08:00
Oskar Kwaśniewski 209140046b fix: PerfMonitor option not showing on iOS (Bridgeless) (#42891)
Summary:
This PR fixes PerfMonitor option not showing on iOS when running bridgeless. The `initialize` method is not called in bridgeless which causes this option to not be added. I've converted this approach to work for both bridgeless and non-bridgeless.

bypass-github-export-checks

## Changelog:

[IOS] [FIXED] - Perf Monitor option not showing in Bridgeless

Pull Request resolved: https://github.com/facebook/react-native/pull/42891

Test Plan: Run RNTester, open Perf monitor

Reviewed By: RSNara

Differential Revision: D53518507

Pulled By: cipolleschi

fbshipit-source-id: c16d41006c5a3f96d53d4f76fd317941a1eb839f
2024-02-15 09:11:41 -08:00
Samuel Susla ca980447f0 remove feature flag enableOnDemandReactChoreographer (#43044)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43044

changelog: [internal]

Reviewed By: javache

Differential Revision: D53758129

fbshipit-source-id: bd921553e2aeaadac56624a100f5f27310995c98
2024-02-15 08:09:27 -08:00
Riccardo Cipolleschi ab5e2e8099 Fix forwarding touches to components in the Interop Layer
Summary:
When analyzing the `hitTest:withEvent` function, I realized that we were not forwarding the touches to the legacy view.

The previous algorithm was returning the InteropLegacyWrapper view itself when the touches were happening in the legacy view, preventing the handlers attached to the legacy view to fire.

With this change, if the legacy view receives a touch, it can handle it.

## Changelog
[iOS][Fixed] - Make sure to forward touches to the wrapped component in the InteropLayer.

Reviewed By: sammy-SC

Differential Revision: D53806218

fbshipit-source-id: 87b0aa6e900935092e6f5e1533b871c1d224b718
2024-02-15 07:54:46 -08:00
Pieter De Baets 53e3f364cf Fix incorrect cast in RemoveDeleteTree (#43018)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43018

Assuming that if View is a ViewGroup, its ViewManager is a ViewGroupManager is incorrect. Custom ViewManagers may use ViewGroups internally to represent complex views exposed to JS.

Type-check the ViewManager instead to avoid the crash seen in T178300877

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D53586565

fbshipit-source-id: 49408098cebc7f76d8be0e585187ba9b6ca52049
2024-02-15 05:39:23 -08:00
Pieter De Baets 5a5c9eb96c Remove ReactViewManagerWrapper
Summary:
This was introduced to support MapBuffer-based view managers (D33735245), but that experiment has been removed from the codebase (D53072714).

This indirection is preventing a proper fix for a crash we're seeing with RemoveDeleteTree (T178300877)

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D53586567

fbshipit-source-id: d391ca56b23fc3dd57429c5ad8a7a405e97a81f2
2024-02-15 05:39:23 -08:00
Riccardo Cipolleschi a3998f8d15 Generate the RCTModulesConformingToProtocolsProvider only for react-native core (#43046)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43046

This fixes a problem where RCTModulesConformingToProtocolsProvider was generated also in Library space.

## Changelog:
[iOS][Fixed] - Generate the RCTModulesConformingToProtocolsProvider only once in user space

## Facebook
See comment [here](https://www.internalfb.com/diff/D53441411?dst_version_fbid=750944970297544&transaction_fbid=719673583317629)

Reviewed By: dmytrorykun

Differential Revision: D53807045

fbshipit-source-id: 2c4a15c3c7943cfcc1f5ea5dd5ab47c3a31e6596
2024-02-15 04:17:35 -08:00
Moti Zilberman 59d46e83ef Recreate jsi::Runtime during reload operation in JsiIntegrationTest
Summary:
Changelog: [Internal]

Fixes a small omission in D53756996 that will come into play in future diffs.

bypass-github-export-checks

Reviewed By: robhogan

Differential Revision: D53771004

fbshipit-source-id: 4c94db37ef51793420e126a81c5d6c0543493ec7
2024-02-15 01:47:30 -08:00
sebmarkbage 0f134fd091 Remove __self and __source location from elements (#28265)
Summary:
Changelog: [Internal]

Along with all the places using it like the `_debugSource` on Fiber.
This still lets them be passed into `createElement` (and JSX dev
runtime) since those can still be used in existing already compiled code
and we don't want that to start spreading to DOM attributes.

We used to have a DEV mode that compiles the source location of JSX into
the compiled output. This was nice because we could get the actual call
site of the JSX (instead of just somewhere in the component). It had a
bunch of issues though:

- It only works with JSX.
- The way this source location is compiled is different in all the
pipelines along the way. It relies on this transform being first and the
source location we want to extract but it doesn't get preserved along
source maps and don't have a way to be connected to the source hosted by
the source maps. Ideally it should just use the mechanism other source
maps use.
- Since it's expensive it only works in DEV so if it's used for
component stacks it would vary between dev and prod.
- It only captures the callsite of the JSX and not the stack between the
component and that callsite. In the happy case it's in the component but
not always.

Instead, we have another zero-cost trick to extract the call site of
each component lazily only if it's needed. This ensures that component
stacks are the same in DEV and PROD. At the cost of worse line number
information.

The better way to get the JSX call site would be to get it from `new
Error()` or `console.createTask()` inside the JSX runtime which can
capture the whole stack in a consistent way with other source mappings.
We might explore that in the future.

This removes source location info from React DevTools and React Native
Inspector. The "jump to source code" feature or inspection can be made
lazy instead by invoking the lazy component stack frame generation. That
way it can be made to work in prod too. The filtering based on file path
is a bit trickier.

When redesigned this UI should ideally also account for more than one
stack frame.

With this change the DEV only Babel transforms are effectively
deprecated since they're not necessary for anything.

DiffTrain build for commit https://github.com/facebook/react/commit/37d901e2b81e12d40df7012c6f8681b8272d2555.

Reviewed By: kassens

Differential Revision: D53543159

Pulled By: tyao1

fbshipit-source-id: 8e5509a16ea8d3234881e2305149326fb31e3845
2024-02-14 20:32:48 -08:00
Phillip Pan 16276ce0f6 build backwards compat API for runtime pointer (#43012)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43012

Changelog: [iOS][Added]

This implements the functionality to give access to the jsi::Runtime in iOS in bridgeless. In bridge, this value is a private selector on RCTBridge that is exposed via category. We build this into the backwards compatible RCTBridgeProxy here.

This should work out of the box in bridgeless if you are already retrieveing the pointer via the bridge. However, we recommend users to eventually migrate towards C++ TurboModule or the RuntimeExecutor if possible. This will be removed in the future.

Reviewed By: RSNara

Differential Revision: D53646413

fbshipit-source-id: a5584f22d433a580d537b8780a3bcd503680acb8
2024-02-14 19:01:02 -08:00
Phillip Pan 315be8290d build backwards compat API for runtime pointer (#43013)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43013

Changelog: [Android][Added]

This is a pre-deprecated API to give access to the jsi::Runtime in Android in bridgeless. In bridge, this value is exposed via the ReactContext, but is not implemented in the BridgelessReactContext. We do that here.

This should work out of the box in bridgeless if you are already retrieveing the pointer via ReactContext. However, we recommend users to eventually migrate towards C++ TurboModule or the RuntimeExecutor if possible. This will be removed in the future.

Reviewed By: RSNara

Differential Revision: D53645247

fbshipit-source-id: b98657560c43a625bdf947d19d186952c9b44364
2024-02-14 19:01:02 -08:00
Zhengwei Liu 45b1aef291 introduce experimental props endDraggingSensitivityMultiplier and endDraggingSensitivityVelocityMultiplier to ScrollView
Summary:
changelog: [internal]

Adding experimental props to control scroll speed on iOS.

Reviewed By: cipolleschi

Differential Revision: D53757152

fbshipit-source-id: 5848780ffcc91242494d371731cc0efce87b3159
2024-02-14 18:24:46 -08:00
Thomas Nardone 1c4ed12370 Fix Win build (#43025)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43025

Changelog:
[General][Fixed] - Fix JSExecutor build error on Windows

Reviewed By: motiz88, cipolleschi

Differential Revision: D53762452

fbshipit-source-id: bea7295d9261fa013d14231dfba66cb4369a8916
2024-02-14 14:58:45 -08:00
Moti Zilberman 7b00a92a3b Add CDP-JSI integration tests (#43027)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43027

Changelog: [Internal]

Adds a test suite for the integration between the modern RN CDP backend and Hermes (plus potentially other JS engines), mocking out the rest of RN.

For simplicity, everything is single-threaded and "async" work is actually done through a queued immediate executor ( = run immediately and finish all queued sub-tasks before returning).

The main limitation of the simpler threading model is that we can't cover breakpoints etc - since pausing during JS execution would prevent the test from making progress. Such functionality is better suited for a full RN+CDP integration test (using RN's own thread management) as well as for each engine's unit tests.

## Types of tests in this diff

* `TEST_F(JsiIntegrationHermesTest, ...)` - tests specific to the Hermes integration.
* `TYPED_TEST(JsiIntegrationPortableTest, ...)` - tests that should pass on all engines.
  * These use gtest's [typed tests](https://google.github.io/googletest/advanced.html#typed-tests) feature.
  * This is a good fit for testing CDP features that have no strict dependency on Hermes (like the upcoming `Runtime.addBinding` support). **Long term**, aspirationally, all tests should be in this category, covering a consistent baseline of CDP features needed for debugging with any supported engine.
  * The first "non-Hermes" engine we test against (`GenericEngineAdapter`) is actually Hermes in disguise, minus any Hermes-specific CDP handling. We could conceivably add more engines here, as long as we have the ability to build them (and their JSI bindings) as part of building the tests.

bypass-github-export-checks

Reviewed By: huntie

Differential Revision: D53756996

fbshipit-source-id: fbafb088abd4263ec841bf848185637ec126c6d1
2024-02-14 10:44:41 -08:00
Edmond Chui 032208d81a Update tests for URL assertions
Summary:
Changelog: [Internal]

Update tests to be more resilient against prod changes; and make it easier to read the actual vs expected values upon failure.

Reviewed By: motiz88

Differential Revision: D53762409

fbshipit-source-id: d627d5041295f645ed00aa5d0645419a9ac4a7f8
2024-02-14 10:37:13 -08:00
Phillip Pan cc147ceb79 add example for capturing initial notification in push notification manager (#42687)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42687

Changelog: [Internal]

adding an example for if you want to use `getInitialNotification`.

Reviewed By: ingridwang

Differential Revision: D52931618

fbshipit-source-id: 7552c358e5bc98228b7ae74ea1adf450f7b075e6
2024-02-14 10:32:11 -08:00
Phillip Pan 75e6137add store initial notification in static instead of property
Summary:
Changelog: [Internal]

I'm updating this API to match the semantics of the other new APIs, namely that they're static methods that don't depend on the instance of the native module. This should help streamline our documentation. Instead of capturing the launch notification as an ivar, we capture it in a static variable that we clear out when the object gets cleared or is invalidated, which is similar to an ivar / property.

Reviewed By: ingridwang

Differential Revision: D53743761

fbshipit-source-id: b6ff048ef8d653e8f4be19194a2211792a542252
2024-02-14 10:32:11 -08:00
Phillip Pan 2740491e32 resolve getInitialNotification for local notifications with notification schema
Summary:
Changelog: [Internal]

In the past, local notifications were stored in the launch options as UILocalNotification, whereas remote notifications were stored as NSDict. This means that we had different handling in PushNotificationIOS.js. This condition was not handling the differences in local and remote notifications that JS expected, which I'm fixing here.

Reviewed By: ingridwang

Differential Revision: D53734086

fbshipit-source-id: 73ef436a232c16de3b72f7236db94012aafdc434
2024-02-14 10:32:11 -08:00
Moti Zilberman 3020747101 Add missing react_render_core -> runtimeexecutor CMake dep (#43028)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43028

Changelog: [Internal]

Should fix an OSS Android build failure introduced in the stack of D53671483. (Apparently CMake doesn't propagate transitive header dependencies?)

Reviewed By: robhogan

Differential Revision: D53767182

fbshipit-source-id: 3251153b6f6ef1a51f73e1bf939f7e308ca0611d
2024-02-14 10:26:09 -08:00
Ruslan Lesiutin ca141d94eb refactor: remove source usages from getInspectorData
Summary:
Changelog: [Internal]

Required for landing D53543159.

2 reasons for landing this:
1. Inspector is technically deprecated and will be removed once React DevTools are shipped with Chrome DevTools for RN debugging.
2. Long-term solution for source fetching is lazy loading based on component stacks - https://github.com/facebook/react/pull/28265

Reviewed By: kassens

Differential Revision: D53757524

fbshipit-source-id: cbb2aab79ba40ea66da5c1ddde95d3fe374b6006
2024-02-14 10:12:14 -08:00
Moti Zilberman 266122248f RuntimeTarget refactor - introduce WeakList for Target→Agent refs
Summary:
Changelog: [Internal]

Replaces the copypasta'd `PageTarget::forEachSession`, `InstanceTarget::forEachAgent` and `RuntimeTarget::forEachAgent` with a shared utility class for managing a list of `weak_ptr`s.

In a `WeakList`, elements can only be added (`insert`), iterated over (`forEach`), and counted (`size`, `empty`). Conceptually, elements are automatically removed from the list as soon as they're destroyed, but internally, space is reclaimed *lazily*: the next time we have a reason to iterate over the underlying list, we delete any pointers that are found to be null.

## Naming

This is almost a WeakSet, but we don't bother checking for duplicates, hence "WeakList".

Reviewed By: hoxyq

Differential Revision: D53671483

fbshipit-source-id: 460bfbaa2b8e821281dc352fed0946f99352c9fc
2024-02-14 07:13:19 -08:00
Moti Zilberman d4468fb1e4 RuntimeTarget refactor - Add this-scoped async executors to all Targets
Summary:
Changelog: [Internal]

# This diff

1. Provides all Targets with an `executorFromThis()` method, which can be used from within a Target to access a *`this`-scoped main thread executor* = a `std::function` that will execute a callback asynchronously iff the current Target isn't destroyed first.
2. Refactors how (all) Target objects are constructed and retained, from a plain constructor to `static shared_ptr create()`. This is because `executorFromThis()` relies internally on `enable_shared_from_this` plus two-phase construction to populate the executor.
3. Creates utilities for deriving scoped executors from other executors and `shared_ptr`s.

The concept is very much like `RuntimeExecutor` in reverse: the #1 use case is moving from the JS thread back to the main thread - where "main thread" is defined loosely as "anywhere it's legal to call methods on Target/Agent objects, access session state, etc". The actual dispatching mechanism is left up to the owner of each `PageTarget` object; for now we only have an iOS integration, where we use `RCTExecuteOnMainQueue`.

Coupling the ownership/lifetime semantics with task scheduling is helpful, because it avoids the footgun of accidentally/nondeterministically moving `shared_ptr`s (and destructors!) to a different thread/queue .

# This stack
I'm refactoring the way the Runtime concept works in the modern CDP backend to bring it in line with the Page/Instance concepts.

Overall, this will let us:

* Integrate with engines that require us to instantiate a shared Target-like object (e.g. Hermes AsyncDebuggingAPI) in addition to an per-session Agent-like object.
* Access JSI in a CDP context (both at target setup/teardown time and during a CDP session) to implement our own engine-agnostic functionality (`console` interception, `Runtime.addBinding`, etc).
* Manage CDP execution contexts natively in RN, and (down the line) enable first-class debugging support for multiple Runtimes in an Instance.

The core diffs in this stack:

* ~~Introduce a `RuntimeTarget` class similar to `{Page,Instance}Target`. ~~
* ~~Make runtime registration explicit (`InstanceTarget::registerRuntime` similar to `PageTarget::registerInstance`). ~~
* ~~Rename the existing `RuntimeAgent` interface to `RuntimeAgentDelegate`.~~
* ~~Create a new concrete `RuntimeAgent` class similar to `{Page,Instance}Agent`.~~
* ~~Provide `RuntimeTarget` and `RuntimeAgent` with primitives for safe JSI access, namely a `RuntimeExecutor` for scheduling work on the JS thread.~~
  * Provide RuntimeTarget with mechanism for scheduling work on the "main" thread from the JS thread, for when we need to do more than just send a CDP message (which we can already do with the thread-safe `FrontendChannel`) in response to a JS event. *← This diff*

## Architecture diagrams

Before this stack:
https://pxl.cl/4h7m0

After this stack:
https://pxl.cl/4h7m7

Reviewed By: hoxyq

Differential Revision: D53356953

fbshipit-source-id: 152c784eb64e9b217fc2966743b33f61bd8fd97e
2024-02-14 07:13:19 -08:00
Moti Zilberman b3a7a13ff8 RuntimeTarget refactor - Add RuntimeExecutor to RuntimeTarget
Summary:
Changelog: [Internal]

I'm refactoring the way the Runtime concept works in the modern CDP backend to bring it in line with the Page/Instance concepts.

Overall, this will let us:

* Integrate with engines that require us to instantiate a shared Target-like object (e.g. Hermes AsyncDebuggingAPI) in addition to an per-session Agent-like object.
* Access JSI in a CDP context (both at target setup/teardown time and during a CDP session) to implement our own engine-agnostic functionality (`console` interception, `Runtime.addBinding`, etc).
* Manage CDP execution contexts natively in RN, and (down the line) enable first-class debugging support for multiple Runtimes in an Instance.

The core diffs in this stack will:

* ~~Introduce a `RuntimeTarget` class similar to `{Page,Instance}Target`. ~~
* ~~Make runtime registration explicit (`InstanceTarget::registerRuntime` similar to `PageTarget::registerInstance`). ~~
* ~~Rename the existing `RuntimeAgent` interface to `RuntimeAgentDelegate`.~~
* ~~Create a new concrete `RuntimeAgent` class similar to `{Page,Instance}Agent`.~~
* Provide `RuntimeTarget` and `RuntimeAgent` with primitives for safe JSI access, namely a `RuntimeExecutor` for scheduling work on the JS thread. *← This diff*
  * We'll likely develop a similar mechanism for scheduling work on the "main" thread from the JS thread, for when we need to do more than just send a CDP message (which we can already do with the thread-safe `FrontendChannel`) in response to a JS event.

## Architecture diagrams

Before this stack:
https://pxl.cl/4h7m0

After this stack:
https://pxl.cl/4h7m7

Reviewed By: hoxyq

Differential Revision: D53266710

fbshipit-source-id: df3a181fcc8e033c37a7f4f430f23a29b326b56a
2024-02-14 07:13:19 -08:00
Edmond Chui 496724fbdb Remove URI encoding
Summary:
Changelog: [Internal]

Fixed double-encoding for the websocket url.
`URLSearchParams` already encode the values, passing a pre-encoded `encodeUriComponent` string will cause it to double-encode, making the value unreadable when decoding once.

Missed these lines while splitting the initial diff stack.
Added tests now.

Reviewed By: motiz88

Differential Revision: D53721568

fbshipit-source-id: cfaaa7eb50c40364c904e9ffc5698201df8ab22b
2024-02-14 05:20:46 -08:00
Samuel Susla 3272b05c3d update react renderers with unified feature flags
Summary:
# changelog:
[General][Changed] - sync React renderers to 18.3.0-canary-03d6f7cf0-20240209

Syncs React renderers to https://github.com/facebook/react/commit/03d6f7cf007cb3b2a3a65e6ec29be02aafd87870 which is canary for 18.3.0-canary-03d6f7cf0-20240209.

This includes feature flag changes: https://github.com/facebook/react/commit/36b078cc7a50ad0cd66e7f6b4b8e4a1295e47f67

Reviewed By: javache

Differential Revision: D53704743

fbshipit-source-id: 3f4fd5eddf300217e06b0642acb3c683849c5228
2024-02-14 05:13:17 -08:00
Moti Zilberman 48f1f2d0db RuntimeTarget refactor - Store weak refs to agents in RuntimeTarget
Summary:
Changelog: [Internal]

Applies to RuntimeTarget → RuntimeAgent the same pattern we use for InstanceTarget → InstanceAgent (D53266708) and PageTarget → PageTargetSession: the target has `weak_ptr`s to its agents/sessions so it can (1) dispatch events to them and (2) assert that they are destroyed before the target itself is destroyed.

In RuntimeTarget this will primarily serve as an event dispatching mechanism from JS (single target) to CDP (multiple sessions), with the addition of threading abstractions in upcoming diffs.

Reviewed By: hoxyq

Differential Revision: D53266706

fbshipit-source-id: 64d7226a1aebf00e0ad178f28101a568e9bc6c53
2024-02-14 04:19:35 -08:00
Moti Zilberman 04eadf6a6c RELAND [RN][CDP] [3/n] RuntimeTarget refactor - RuntimeAgent --> RuntimeAgentDelegate
Summary:
This is a resubmission of D53266707 with a fix in the OSS version of `HermesExecutorFactory` (it was incorrectly referencing `HermesRuntimeAgent.h` which doesn't exist anymore). The original diff summary follows.

 ---

Changelog: [Internal]

I'm refactoring the way the Runtime concept works in the modern CDP backend to bring it in line with the Page/Instance concepts.

Overall, this will let us:

* Integrate with engines that require us to instantiate a shared Target-like object (e.g. Hermes AsyncDebuggingAPI) in addition to an per-session Agent-like object.
* Access JSI in a CDP context (both at target setup/teardown time and during a CDP session) to implement our own engine-agnostic functionality (`console` interception, `Runtime.addBinding`, etc).
* Manage CDP execution contexts natively in RN, and (down the line) enable first-class debugging support for multiple Runtimes in an Instance.

The core diffs in this stack will:

* ~~Introduce a `RuntimeTarget` class similar to `{Page,Instance}Target`.~~ (D53233914)
* ~~Make runtime registration explicit (`InstanceTarget::registerRuntime` similar to `PageTarget::registerInstance`).~~ (D53233914)
* Rename the existing `RuntimeAgent` interface to `RuntimeAgentDelegate`.   *← This diff*
* Create a new concrete `RuntimeAgent` class similar to `{Page,Instance}Agent`.   *← Also in this diff*
* Provide `RuntimeTarget` and `RuntimeAgent` with primitives for safe JSI access, namely a `RuntimeExecutor` for scheduling work on the JS thread.
  * We'll likely develop a similar mechanism for scheduling work on the "main" thread from the JS thread, for when we need to do more than just send a CDP message (which we can already do with the thread-safe `FrontendChannel`) in response to a JS event.

## Architecture diagrams

Before this stack:
https://pxl.cl/4h7m0

After this stack:
https://pxl.cl/4h7m7

Reviewed By: EdmondChuiHW

Differential Revision: D53748590

fbshipit-source-id: bd0cf9f74b95abc52b4903f8a7afddcefa303d8a
2024-02-14 04:19:35 -08:00
Rubén Norte b97f3e779a Move Web performance APIs to private directory (#42769)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42769

Changelog: [internal]

These APIs are not currently enabled in OSS, so moving the modules should be safe and not considered a breaking change.

Reviewed By: NickGerleman

Differential Revision: D53267565

fbshipit-source-id: edd3daa7c5043e44e5fd4b1af074093ed3ef4152
2024-02-14 03:58:10 -08:00
Nicola Corti 6a4d011c6b Backport addUIBlock and prependUIBlock to Fabric for Android
Summary:
The `.addUIBlock` and `.prependUIBlock` APIs on UiManagerModule are missing on Fabric.
Here I'm re-implementing them to make migration to Fabric easier.

Set of changes:
- Moved `NativeViewHierarchyManager` to `NativeViewHierarchyManagerImpl` and extracted an interface
- Moved `addUIBlock` and `prependUIBlock` to the shared `UIManager` interface
- Added a `InteropUIBlockListener` class that takes care of executing the UI Blocks, implemented as a `UIManagerListener`

Changelog:
[Android] [Changed] - Changed the API of addUIBlock and prependUIBlock to implement it also in Fabric.

Reviewed By: mdvacca

Differential Revision: D53612514

fbshipit-source-id: 1cddbc391477318064f15c733a380983c3737373
2024-02-14 02:10:48 -08:00
David Vacca cc2a73aa4d Revert initialization of event emits during initial rendering in Fabric
Summary:
Original commit changeset: 0b56b7495db6

Original Phabricator Diff: D53108114

bypass-github-export-checks

changelog: [internal] internal

Reviewed By: philIip

Differential Revision: D53746331

fbshipit-source-id: 95daf5660845eb9a5dd84da85833727aed4e65e3
2024-02-14 00:00:48 -08:00
Nick Gerleman 3b2c4a1834 Partial Back out "[react-native] Move CSSTokenizer to "react/renderer/css""
Summary:
Removes the OSS build logic I added in D53377527, to turn Android build green (target not yet used outside tests).

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D53746020

fbshipit-source-id: 6e8a8e111a307b955b838c0522d3d0802e3865c3
2024-02-13 21:51:46 -08:00
Nick Gerleman c9a9e5dc82 Back out "RuntimeTarget refactor - RuntimeAgent --> RuntimeAgentDelegate"
Summary:
This one snuck in with new OSS buid failures after when we had another change cause a failure. Back it out, to get CI passing.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D53745683

fbshipit-source-id: f889bf7541e6f664053d5c0e4851cb448cdbb615
2024-02-13 21:51:46 -08:00
Nick Gerleman f2d09651e0 CSSDeclaredStyle
Summary:
Adds a sparse `CSSDeclaredStyle` structure to represent the collection of declarations from the user, before being further processed/computed. This will later be procssed into computed style.

Also fixes up some bad naming wrt specified value and declared value.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D53696422

fbshipit-source-id: 4258c86a29a0b2251c969b299b5b4703c06696db
2024-02-13 20:13:22 -08:00
Nick Gerleman 516c4ccb71 Fix CSSParser constexpr-iness
Summary:
I originally marked most of this as constexpr, since the code around the variant, and parsing, were already header only and avoiding allocations, and was pretty leaf node.

`reinterpret_cast` and similar is not allowed under constexpr until C++ 26, which `CSSValue` was using. We change our method of storage to a recursively defined union, which is the same underlying implementation of `std::variant` (and is how it is constexpr).

`std::pow` is also not constexpr until C++ 26 which means we can't assign a CSSValue which tokenizes a decimal number... But... constexpr here is more a bonus, and not worth pulling in constexpr math library to do it.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D53696265

fbshipit-source-id: 01442ab9222b3f3ef8ccb01383648fb2e1f747dd
2024-02-13 20:13:22 -08:00
Nick Gerleman 383b90719b Add test for parseCSSProp for prop without keyword specialization
Summary: Didn't have a test for this before. Add one.

Reviewed By: joevilches

Differential Revision: D53537840

fbshipit-source-id: 30872e2dd5b4c35eab7ee66b6f6f322ff0b7735c
2024-02-13 20:13:22 -08:00
Nick Gerleman 2cc0d032bb Flesh out CSSPropDefinition
Summary:
1. Add "initial" values, and whether the prop should be inherited (currently only applies to direction).
2. Add some more border properties that we can replicate with the current data types we support, that are part of valid CSS. These are in ViewProps today instead of YogaStylableProps, but style computation can read both at once.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D53537101

fbshipit-source-id: cce926ba0caba0467493611e3000d1ba396de19e
2024-02-13 20:13:22 -08:00
Nick Gerleman c37fc74212 Add CSSProp and CSSPropDefinition (#42913)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42913

This structures properties into a `CSSProp` enum (so that we can have a runtime-key per style prop), associated with a `CSSPropDefinition` structure which groups the supported types and keywords. This has some niceness of removing the macro bits, but more importantly, means we can query parse related information without a field of the value yet existing (need for sparse storage of CSS values). In the future, it will serve as where we define "initial" values, and likely, the processes for interpolation and inheritance.

We restructure `CSSValueVariant` to not always support keywords, as it may not be a valid possibility for computed values (which do not have CSS wide keywords). Computed values themselves may also reduce more keywords than the global ones (e.g. border width computed value absolutizes keywords).

We also flesh out more of the prop definitions, and parsing. All the properties here relay back to YogaStylableProps of today, but I intentionally filled out the prop definitions a bit more than we do anything with right now (will design higher level to ignore unknown props).

Changelog: [Internal]

Reviewed By: rozele

Differential Revision: D53518450

fbshipit-source-id: 1b48ae2513a258d15c5e7fd16ef06f1b6be8dab2
2024-02-13 20:13:22 -08:00
Nick Gerleman a8f239d957 Add <ratio> support to CSSValueVariant and parseCSSValue() (#42879)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42879

Adds support for parsing and storing a component value of the <ratio> CSS basic data type. This would allow removing `processAspectRatio` from viewconfigs later, which we would need for correct substitution of functions/expressions resulting in the ratio numerator/denominator.

This also fleshes out the parser a bit more, and does some renaming, and convention setting.

Changelog: [Internal]

Reviewed By: rozele

Differential Revision: D53457930

fbshipit-source-id: bed79e05978ed4152c865cdf90701dea779c8622
2024-02-13 20:13:22 -08:00