Files
react-native/packages/react-native/React/Base
Moti ZilbermanandFacebook GitHub Bot be441f8fbe Create PageTarget{Delegate,Controller}, respond to Page.reload (#42587)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42587

Changelog: [Internal]

* Introduces the Target Delegate and Target Controller concepts (see `CONCEPTS.md`).
* Introduces the `PageTargetDelegate` interface and `PageTargetController` class (see doc comments).
* Uses the above infra to implement support for the `Page.reload` CDP command. Each integration provides its own `PageTargetDelegate` that knows how to trigger a reload in a platform- and architecture-specific way.
  * iOS Bridge/Bridgeless and `PageTargetTest` are the only integrations that exist as of this diff, and are all updated here; Android will follow later.

NOTE: `RCTBridge` = iOS Bridge, `RCTHost` = iOS Bridgeless.

## Object lifetimes

`PageAgent` holds a raw `PageTargetController&` reference to a member of `PageTarget`, through which it gets access to that target's `PageTargetDelegate&` (another raw reference).

Here's what makes this safe:

1. **`PageTargetDelegate` outlives `PageTarget`** - this is the responsibility of the platform integration ( = the code that instantiates `PageTarget`).
2. **`PageTarget` outlives its Sessions and Agents** - this is `PageTarget`'s "moral" responsibility, even though it doesn't own its Sessions outright (`InspectorPackagerConnection` does). We add an assertion in `PageTarget`'s destructor to catch violations, and document that the integrator must call `getInspectorInstance().removePage` (which terminates all remaining sessions) before destroying the corresponding `PageTarget`.

NOTE: In upcoming diffs we'll use the new Target→Session references, currently used only for the assertion in (2), to power actual functionality (e.g. dispatching CDP events to the frontend when some imperative method is called on `PageTarget`).

## Thread safety

`PageTargetDelegate::onReload` is guaranteed to be called synchronously on the thread where messages are dispatched to `PageTargetSession`, which on iOS is the main (UI) thread.

Reviewed By: huntie

Differential Revision: D51164125

fbshipit-source-id: 4c3eeb81a8df9677c173588eb5acfd686722c3c9
2024-01-24 05:52:56 -08:00
..
2023-09-04 10:55:18 -07:00