[WebAPIs] structuredClone: WeakMap/WeakSet/Promise prototype mutations break initial render under Hardened JS (SES)

未關閉
#60,002 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

@leotm 已經在處理了。

開始於 2026年11月13日。

  • #60003 來自 @leotm —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
30/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
javascript, react-native
領域
mobile

研究方向

Start in packages/react-native/src/private/webapis/structuredClone/structuredClone.js, especially the top-level class marking around lines 394-407 and the reference at line 298; then read packages/react-native/src/private/setup/setUpDOM.js and Performance.js to trace the lazy-load path. Reproduce with the linked template under LavaMoat lockdown and verify the module loads without mutating frozen built-in prototypes. A fix is already proposed in PR #60003, so coordinate there before starting.

由索引模型根據 Issue 內容生成。

描述

Needs: Triage :mag:
Description

https://github.com/react/react-native/blob/649c1054e766b3554a690506bce7d48c02882d93/packages/react-native/src/private/webapis/structuredClone/structuredClone.js#L298

https://github.com/react/react-native/blob/649c1054e766b3554a690506bce7d48c02882d93/packages/react-native/src/private/webapis/structuredClone/structuredClone.js#L394-L407

crashes apps whose built-in prototypes are frozen (Hardened JS / SES)

i.e. via LavaMoat React Native lockdown

e.g. react-native-template-new-architecture

unless patched with the/a fix when upgrading to v0.89

when apps like metamask/metamask-mobile eventually adopt v0.89 stable
they will crash on first render as soon as structuredClone loads

TypeError: cannot add a new property
    at markClassAsNonSerializable (structuredClone.js:401:45)
    at anonymous (structuredClone.js:405:27)
    ...
    at metroRequire (require.js:98:24)
    at metroImportDefault (require.js:123:31)
    at measure (Performance.js:343:30)
    at renderRootSync (ReactFabric-dev.js:15001:26)
    at performWorkOnRootViaSchedulerTask (ReactFabric.js:3928:24)

then remaining calls fail since structuredClone is undefined

TypeError: undefined is not a function
    at measure (Performance.js:343:30)
    ...
Error: Should not already be working.
    at performWorkOnRoot (ReactFabric-dev.js:14078:20)

... the measure frame: performance.measure() called with a detail
343: (structuredClone(detail)) is behind the detail !== undefined guard
so the crashing call must have passed a detail
performance.mark() with a detail fails similarly

structuredClone.js currently marks built-in classes non-serializable by adding the symbol prop to the built-in prototypes at the module top level

since the built-in prototypes are frozen (non-extensible) and RN source is strict-mode
the first cls.prototype[SYMBOL] = true throws during eval on WeakMap

structuredClone installs lazily
setUpDOM.js: polyfillGlobal('structuredClone', () => require('../webapis/structuredClone/structuredClone').default)
the first use runs that require and throws, the factory's require(...).default never resolves, so the structuredClone global is left undefined
the first throw is contained rather than fatal (the app still reaches later structuredClone uses), so every following use fails with undefined is not a function
so the first performance.measure(name, { detail }) during the first render (Fabric dev instrumentation) lazily loads structuredClone.js then throws at its top level

its not a new mutation, 0.88.1 includes the module (same code), but 0.89 pulled the module into the startup path
245bbfaf0a exposes structuredClone/DOMException as globals in packages/react-native/src/private/setup/setUpDOM.js (not in 0.88.1)
14de25bb2d extends structuredClone with ArrayBuffer/DataView/typed array/BigInt/Error support, and Performance.js (imported by startup timing) calls structuredClone in mark()/measure() whenever detail is defined

as an aside spotted couple spec-compliant gaps RE WeakRef and FinalizationRegistry which i'll follow up seperately

Steps to reproduce

1a. clone react-native-template-new-architecture
1b. checkout to branch react-native-0.88.1-to-0.89.0-rc.0-repro
2. run yarn android or yarn ios

React Native Version

0.89.0-rc.0

Affected Platforms

Runtime - iOS, Runtime - Android

Output of npx @react-native-community/cli info
npx @react-native-community/cli info
info Fetching system and libraries information...
System:
  OS: macOS 27.3
  CPU: (12) arm64 Apple M2 Pro
  Memory: 612.80 MB / 16.00 GB
  Shell:
    version: 5.9.2
    path: /opt/homebrew/bin/zsh
Binaries:
  Node:
    version: 22.23.1
    path: /Users/leo/.local/state/fnm_multishells/29305_1794588089192/bin/node
  Yarn:
    version: 4.18.1
    path: /Users/leo/.local/state/fnm_multishells/29305_1794588089192/bin/yarn
  npm:
    version: 10.9.8
    path: /Users/leo/.local/state/fnm_multishells/29305_1794588089192/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.17.0
    path: /var/folders/w0/pbc5gqt14yjg4b1y7s6x6wpw0000gn/T/frum_29306_1794588089207/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 27.3
      - iOS 27.3
      - macOS 27.3
      - tvOS 27.3
      - visionOS 27.3
      - watchOS 27.3
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 27.3/27C5020n
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.21.0.3
    path: /Users/leo/.jenv/shims/javac
  Ruby:
    version: 3.4.10
    path: /var/folders/w0/pbc5gqt14yjg4b1y7s6x6wpw0000gn/T/frum_29306_1794588089207/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 21.0.0-alpha.1
    wanted: 21.0.0-alpha.1
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.89.0-rc.0
    wanted: 0.89.0-rc.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
Running "MyApp" with {"rootTag":11,"initialProps":{},"fabric":true}
console.js:667 TypeError: cannot add a new property
    at markClassAsNonSerializable (structuredClone.js:401:45)
    at anonymous (structuredClone.js:405:27)
    at loadModuleImplementation (require.js:285:12)
    at guardedLoadModule (require.js:183:45)
    at metroRequire (require.js:98:24)
    at metroImportDefault (require.js:123:31)
    at measure (Performance.js:343:30)
    at run (native)
    at prepareFreshStack (ReactFabric-dev.js:14720:28)
    at renderRootSync (ReactFabric-dev.js:15001:26)
    at performWorkOnRoot (ReactFabric-dev.js:14158:25)
    at performWorkOnRootViaSchedulerTask (ReactFabric-dev.js:3928:24)
anonymous @ console.js:667
overrideMethod @ backend.js:17416
reactConsoleErrorHandler @ ExceptionsManager.js:184
anonymous @ setUpDeveloperTools.js:42
reportException @ ExceptionsManager.js:108
handleException @ ExceptionsManager.js:173
handleError @ setUpErrorHandling.js:26
reportFatalError @ error-guard.js:53
guardedLoadModule @ require.js:185
metroRequire @ require.js:98
metroImportDefault @ require.js:123
measure @ Performance.js:343
prepareFreshStack @ ReactFabric-dev.js:14720
renderRootSync @ ReactFabric-dev.js:15001
performWorkOnRoot @ ReactFabric-dev.js:14158
performWorkOnRootViaSchedulerTask @ ReactFabric-dev.js:3928
console.js:667 TypeError: undefined is not a function
    at measure (Performance.js:343:30)
    at run (native)
    at prepareFreshStack (ReactFabric-dev.js:14720:28)
    at renderRootSync (ReactFabric-dev.js:15001:26)
    at performWorkOnRoot (ReactFabric-dev.js:14158:25)
    at performWorkOnRootViaSchedulerTask (ReactFabric-dev.js:3928:24)
anonymous @ console.js:667
overrideMethod @ backend.js:17416
reactConsoleErrorHandler @ ExceptionsManager.js:184
anonymous @ setUpDeveloperTools.js:42
reportException @ ExceptionsManager.js:108
handleException @ ExceptionsManager.js:173
handleError @ setUpErrorHandling.js:26
reportFatalError @ error-guard.js:53
console.js:667 Error: Should not already be working.
    at performWorkOnRoot (ReactFabric-dev.js:14078:20)
    at performWorkOnRootViaSchedulerTask (ReactFabric-dev.js:3928:24)
MANDATORY Reproducer

https://github.com/leotm/react-native-template-new-architecture

Screenshots and Videos

No response

主要語言
C++
星號
127k
分支
25.5k
平均合併
3 天 22 小時
30 天內合併 PR
235

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

react/react-native 的其他 Issue

查看 react/react-native 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。