react / react/react-native

Updating App Properties is not available on the ReactSurface interface

未关闭
#54,075 6 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Needs: Triage :mag:
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

Situation

As an app developer for one of Europe's largest theme parks, I'm tasked with migrating our RN projects to the new architecture.
For our apps we use an in-house developed navigation library that, amongst other things, allows us to update the properties of native views.

Old Architecture

In the old architecture, we were able to read and update the appProperties property on the ReactRootView of the ReactDelegate that we create.

New Architecture

In the new architecture, the ReactRootView property still exists on the ReactDelegate, but will raise SoftExceptions when it tries to update properties that have been left purposefully unimplemented, as the new architecture will just use the Fabric renderer.

In order to still be able to update the properties dynamically we have implemented a workaround that creates and holds a reference to the ReactSurface, set this on the ReactDelegate and explicitly downcast to ReactSurfaceImpl so we can call the updateInitProps function.

... (subclass of android.fragment.app.Fragment)

private var surface: ReactSurface? = null

... (in onCreateView of a Fragment)

surface = reactDelegate.reactHost?.createSurface(  
  requireActivity(),  
  "OurModuleName",  
  injectSailorProps(cachedProps)  
) 
reactDelegate.setReactSurface(surface)

...

fun updateReactProperties(newProperties: Bundle) {
  (surface **as? ReactSurfaceImpl**)?.updateInitProps(newProperties)
}

This downcast is undesirable as its implementation might change at any given point between RN versions.

Question / Request

Is this the envisioned way to update the view properties in the new architecture?
If so, we would like to request the updateInitProps() function to be added to the ReactSurface interface.
If not, please enlighten us on the proper way to update view properties.

Steps to reproduce

Try to call the
ReactRootView.appProperties = bundleOf() (might require actual properties rather than an empty bundle)
with the new architecture and notice the soft exceptions that get raised. Follow the stack trace to see that these methods have been purposefully left unimplemented.
Use the downcast of ReactSurface to actually update the properties when new arch is enabled

React Native Version

0.81.4

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.6.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 150.58 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.6.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 4.9.2
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.5.1
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2025.08.11.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/sjorsdehaas/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK:
    API Levels:
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 29.0.2
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play Tablet ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.26094.121.2512.13840223
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.16
    path: /usr/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/sjorsdehaas/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.1
    wanted: ^20.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.81.4
    wanted: 0.81.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
[ReactNative Architecture][JS] 'updateView' is not available in the new React Native architecture. 
anonymous @ 10.0.2.2:8081/index.…ths=url-server:1187
overrideMethod @ 10.0.2.2:8081/index.…hs=url-server:43436
reactConsoleErrorHandler @ 10.0.2.2:8081/index.…hs=url-server:23987
anonymous @ 10.0.2.2:8081/index.…hs=url-server:50663
raiseSoftError @ 10.0.2.2:8081/index.…ths=url-server:7300
updateView @ 10.0.2.2:8081/index.…ths=url-server:7349
commitTextUpdate @ 10.0.2.2:8081/index.…hs=url-server:79154
runWithFiberInDEV @ 10.0.2.2:8081/index.…hs=url-server:78361
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83296
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83265
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83265
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83265
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83384
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83384
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83265
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83265
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83384
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83384
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83249
recursivelyTraverseMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:83239
commitMutationEffectsOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83304
flushMutationEffects @ 10.0.2.2:8081/index.…hs=url-server:84366
commitRoot @ 10.0.2.2:8081/index.…hs=url-server:84346
commitRootWhenReady @ 10.0.2.2:8081/index.…hs=url-server:83913
performWorkOnRoot @ 10.0.2.2:8081/index.…hs=url-server:83901
performSyncWorkOnRoot @ 10.0.2.2:8081/index.…hs=url-server:79783
flushSyncWorkAcrossRoots_impl @ 10.0.2.2:8081/index.…hs=url-server:79703
scheduleUpdateOnFiber @ 10.0.2.2:8081/index.…hs=url-server:83824
dispatchSetStateInternal @ 10.0.2.2:8081/index.…hs=url-server:81094
dispatchSetState @ 10.0.2.2:8081/index.…hs=url-server:81066
anonymous @ 10.0.2.2:8081/index.…s=url-server:102273
MANDATORY Reproducer

https://github.com/sjorsdehaas-efteling/app-properties-update/tree/main/ReproducerApp

Screenshots and Videos

Purposefully unimplemented methods due to OSS / New Arch:

Image

SoftExceptions in devtools:

Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 ReactSurface 接口开始,比较 ReactSurfaceImpl、ReactDelegate 和 ReactRootView 在 appProperties 和 updateInitProps 方面的行为。运行必需的 ReproducerApp,以确认当前 new-architecture 的行为。当更新视图属性的受支持方式已公开或得到明确文档说明,且不要求对实现进行 downcast 时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, kotlin, react-native
领域
api, mobile
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。