react / react/react-native

[iOS] RCTLogBoxView crashes on dealloc when app uses SceneDelegate because it still assumes AppDelegate.window exists

未关闭
#56,571 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Description

When using a SceneDelegate-based iOS app lifecycle, React Native crashes in RCTLogBoxView during deallocation because it still accesses RCTSharedApplication().delegate.window.

The following code in RCTLogBoxView is problematic:

- (void)dealloc
{
#if !TARGET_OS_MACCATALYST // sharedApplication.delegate is not available on Mac Catalyst
  [RCTSharedApplication().delegate.window makeKeyWindow];
#endif
}

In a SceneDelegate setup, the app’s main window is typically owned by the active UIWindowScene, not exposed as AppDelegate.window. As a result, this code can crash with an unrecognized selector / invalid access depending on how the app delegate is implemented.

This looks like the same broader class of SceneDelegate compatibility issues as other places in React Native that still assume application.delegate.window exists.

Steps to reproduce
  1. Create a React Native app on iOS
  2. Adopt SceneDelegate / UIScene lifecycle
  3. Ensure the app delegate does not expose a window property
  4. Trigger LogBox presentation and dismissal / teardown in development
  5. Observe crash when RCTLogBoxView is deallocated
React Native Version

0.83.0

Output of npx @react-native-community/cli info
npx @react-native-community/cli info
Screenshots and Videos

RCTLogBoxView

  • (void)dealloc
    {

#if !TARGET_OS_MACCATALYST

[RCTSharedApplication().delegate.window makeKeyWindow];

#endif

}

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先定位 RCTLogBoxView 并阅读其 dealloc 实现,尤其是对 RCTSharedApplication().delegate.window 的访问。使用基于 SceneDelegate 的 app 重现 teardown 流程,然后验证 LogBox 的关闭和 deallocation 不再导致 crash,同时保持现有行为不变。

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

评估

技术栈
ios, objective-c, react-native
领域
mobile-dev
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

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