Skip to content

Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample (#57985) - #57985

Open
christophpurrer wants to merge 4 commits into
react:mainfrom
christophpurrer:export-D116375214
Open

Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample (#57985)#57985
christophpurrer wants to merge 4 commits into
react:mainfrom
christophpurrer:export-D116375214

Conversation

@christophpurrer

@christophpurrer christophpurrer commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary:

The two RNTester TurboModule example screens had drifted apart, making it hard to
compare TurboModule and C++ TurboModule behaviour side by side. Align
SampleTurboModuleExample with the style already used by
NativeCxxModuleExampleExample:

  • Order and group the entries in _tests the same way (callback, ArrayBuffer
    group, get* group, promises, voidFunc), so the buttons render in the same
    order on both screens.
  • Make the Examples union match the tests that actually exist; it still listed
    many entries copied from the C++ example that SampleTurboModule does not
    implement (getCustomHostObject, getSet, setMenuItem, ...) and was missing
    getEnum, getRootTag and getUnsafeObject.
  • Add the missing installJSIBindings entry to ErrorExamples and type
    _renderResult as Examples | ErrorExamples.
  • Surface rejected promises from the error tests in the UI instead of only
    logging them to the console, matching the other screen.
  • Fix getUnsafeObject to call getUnsafeObject instead of getObject.
  • Merge the duplicated NativeSampleTurboModule imports and drop a stale Flow
    suppression.

Changelog:
[Internal]

Differential Revision: D116375214

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 17, 2026
@meta-codesync

meta-codesync Bot commented Aug 17, 2026

Copy link
Copy Markdown

@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D116375214.

Facebook Employee and others added 4 commits August 17, 2026 18:00
…ct#57983)

Summary:
Pull Request resolved: react#57983

Follow-ups in the ObjC `ArrayBuffer` conversion path.

Correctness:
- Copy JS-heap `ArrayBuffer` arguments whenever the call can carry them past it. A
  function argument becomes a block the module may invoke after the call returns, so
  the copy decision now scans the argument list instead of looking only at the
  return kind. The scan is memoized in `ArrayBufferCopyPolicy` and runs at most once
  per call, only when a JS-heap buffer is actually converted.
- Thread that policy through array and object conversion, so buffers nested inside
  array/object arguments follow the same alias/copy rules as top-level ones. They
  were previously always copied.
- Make the copy decision, and reject detached buffers, before reading
  `data()`/`size()`. The scan runs arbitrary JS (accessors, Proxy traps), which could
  otherwise detach or resize the buffer behind an already-read pointer.
- Share one detached check, `detail::throwIfDetached`, with the C++ bridging path,
  and skip it for free once a runtime has shown it doesn't implement
  `ArrayBuffer.prototype.detached`. Hermes doesn't, so this drops a property get and
  a thrown-and-caught exception from every conversion.
- Turn a runtime that cannot expose an ArrayBuffer's bytes into a `jsi::JSError`
  naming the method, instead of letting `std::logic_error` escape through JSI.
- Convert `NSException` raised during argument conversion into a `JSError`. That
  conversion runs outside the `try` in `performMethodInvocation`, and
  `RCTArrayBuffer` can raise.
- Run the caller's `cleanup` block before the designated initializer raises on a
  NULL/non-zero-length mismatch; nothing else would ever release those bytes.
- Normalize `mutableBytes` to NULL for zero-length buffers, so the documented
  "NULL iff empty" invariant holds for every factory.
- Warn, once per class, when `convertObjCObjectToJSIValue` falls through to
  `undefined` instead of doing so silently. A warning rather than an error: that
  fallthrough is reached by any module returning an `NSDate`, `NSURL` or custom
  object, and an `RCTLogError` there would redbox in dev.

Build fix:
- Migrate the macOS sample TurboModule to `RCTArrayBuffer`. It still used
  `NSData`/`NSMutableData`, which no longer matches the generated spec.

Docs: `RCTArrayBuffer.h` spells out that a non-owning buffer must not be captured in
a block, stored, or passed to a callback or promise block, that the framework copies
whenever the method signature reveals such an escape, and that a buffer nested in an
`NSArray`/`NSDictionary` argument follows the same rules — the one case the ObjC
signature does not reveal.

Changelog:
[iOS][Fixed] - Copy ArrayBuffer arguments in ObjC TurboModules whenever they can outlive the call, including buffers nested in objects and arrays

Differential Revision: D115767439
Summary:
Work on top of [D115767439](https://www.internalfb.com/intern/diff/115767439/) / hg commit id 9fc956a2d543bd26f04648cb254e4955f040b3b1 and fix any issues still left in the C++, ObjC and Java/Kotlin Array Buffer implementation except these 2 tasks which are handled separatly. [T285167897](https://www.internalfb.com/tasks/T285167897) / [T285167853](https://www.internalfb.com/tasks/T285167853)

I want to remove any duplicate code e.g. check if we have redundant subclasses of jsi::MutableBuffer

[https://www.internalfb.com/code/search?q=filepath%3Areact-native-github%20repo%3Afbsource%20jsi%3A%3AMutableBuffer](https://www.internalfb.com/code/search?q=filepath%3Areact-native-github%20repo%3Afbsource%20jsi%3A%3AMutableBuffer)

We should also align the C++, ObjC and Java/Kotlin implementation if possible: Naming, style, order of methods e.t

Differential Revision: D116358593
…oad the correct commit data.

Differential Revision: D116345031
…eact#57985)

Summary:
Pull Request resolved: react#57985

The two RNTester TurboModule example screens had drifted apart, making it hard to
compare TurboModule and C++ TurboModule behaviour side by side. Align
`SampleTurboModuleExample` with the style already used by
`NativeCxxModuleExampleExample`:

- Order and group the entries in `_tests` the same way (callback, ArrayBuffer
  group, `get*` group, promises, `voidFunc`), so the buttons render in the same
  order on both screens.
- Make the `Examples` union match the tests that actually exist; it still listed
  many entries copied from the C++ example that `SampleTurboModule` does not
  implement (`getCustomHostObject`, `getSet`, `setMenuItem`, ...) and was missing
  `getEnum`, `getRootTag` and `getUnsafeObject`.
- Add the missing `installJSIBindings` entry to `ErrorExamples` and type
  `_renderResult` as `Examples | ErrorExamples`.
- Surface rejected promises from the error tests in the UI instead of only
  logging them to the console, matching the other screen.
- Fix `getUnsafeObject` to call `getUnsafeObject` instead of `getObject`.
- Merge the duplicated `NativeSampleTurboModule` imports and drop a stale Flow
  suppression.

Changelog:
[Internal]

Differential Revision: D116375214
@meta-codesync meta-codesync Bot changed the title Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample (#57985) Aug 18, 2026
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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant