From 60b177745be426bb9705a173a5480ec29f217d2d Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 16 Oct 2026 12:02:22 -0700 Subject: [PATCH] Type structuredClone typed arrays as ArrayBuffer-backed Summary: `cloneTypedArray` passes `value.buffer` to `cloneArrayBuffer(value: ArrayBuffer)`. With TypeScript's ES2024 `ArrayBuffer` definitions, `$TypedArray` (meaning `$TypedArray`) has an `ArrayBufferLike` buffer, which is no longer an `ArrayBuffer`. Hermes, React Native's default engine, has no `SharedArrayBuffer`, and `cloneArrayBuffer` already treats its input and its `slice(0)` copy as an `ArrayBuffer`. This narrows `isTypedArray`'s refinement and `cloneTypedArray`'s parameter to `$TypedArray`. It is a type-only change. Changelog: [Internal] Differential Revision: D125721761 --- .../src/private/webapis/structuredClone/structuredClone.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-native/src/private/webapis/structuredClone/structuredClone.js b/packages/react-native/src/private/webapis/structuredClone/structuredClone.js index 2f493f69c806..820534ef2a57 100644 --- a/packages/react-native/src/private/webapis/structuredClone/structuredClone.js +++ b/packages/react-native/src/private/webapis/structuredClone/structuredClone.js @@ -308,7 +308,7 @@ function cloneArrayBuffer(value: ArrayBuffer): ArrayBuffer { return result; } -function cloneTypedArray(value: $TypedArray): $TypedArray { +function cloneTypedArray(value: $TypedArray): $TypedArray { const buffer = cloneArrayBuffer(value.buffer); const {byteOffset, length} = value; @@ -365,7 +365,9 @@ function defineEnumerableProperty( }); } -declare function isTypedArray(value: unknown): implies value is $TypedArray; +declare function isTypedArray( + value: unknown, +): implies value is $TypedArray; function isTypedArray(value: unknown): boolean { return ArrayBuffer.isView(value) && !(value instanceof DataView); }