react / react/react-native

[iOS] Inconsistent unmount lifecycle/cleanup triggered on App Kill when Keyboard is (or was) active

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

还没有人认领这个 Issue。

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

描述

Description

A breaking change in lifecycle behavior has been observed in versions 0.83.4 and 0.84.1.

On iOS, when a user force-quits (kills) the app, React components normally do not trigger their unmount lifecycles (componentWillUnmount or useEffect cleanup) because the JS engine is terminated abruptly.

However, in these specific versions, if the keyboard was currently open or had been opened and then closed during the session, the unmount lifecycle is triggered upon the app being killed. If the keyboard was never opened during the app's session, the unmount lifecycle is not triggered (matching traditional behavior).

This inconsistency causes side effects, such as unexpected API calls or local storage wipes, to run during a process termination where they previously did not.

This behavior doesn't happen on Android and creates inconsistency between platforms.

Steps to reproduce

Since app is killed debugger is detached. AsyncStorage is used to save timestamp of unmount called

  1. Open the application.

  2. Observe a component that logs to the console useEffect and class component unmount timestamp

  3. Scenario A (No Keyboard): Kill the app via the iOS App Switcher.
    Result: No logs appear on next launch (Expected behavior).

  4. Scenario B (Keyboard Active): Reopen the app, tap a TextInput to bring up the keyboard. Kill the app via the App Switcher.
    Result: The unmount logs appear next launch (Inconsistent behavior).

  5. Scenario C (Keyboard Dismissed): Reopen the app, open the keyboard, close the keyboard. Kill the app via the App Switcher.
    Result: The unmount logs appear next launch (Inconsistent behavior).

React Native Version

0.83.4, 0.84.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.1
  CPU: (12) arm64 Apple M4 Pro
  Memory: 380.42 MB / 24.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.15.0
    path: /Users/stas/.nvm/versions/node/v22.15.0/bin/node
  Yarn:
    version: 1.22.22
    path: /Users/stas/.nvm/versions/node/v22.15.0/bin/yarn
  npm:
    version: 10.9.2
    path: /Users/stas/.nvm/versions/node/v22.15.0/bin/npm
  Watchman:
    version: 2026.01.12.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.25659.59.2432.13423653
  Xcode:
    version: 26.3/17C529
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.6
    path: /usr/bin/javac
  Ruby:
    version: 3.4.3
    path: /Users/stas/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.84.1
    wanted: 0.84.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
Not a crash so no specific log is present
MANDATORY Reproducer

https://github.com/worksnk/rn_ios_unmount_breaking_change

Screenshots and Videos

Video shows 3 scenarios in described in steps with logs

https://github.com/user-attachments/assets/cd11d754-182c-4d2e-b9f0-99ee9190d3a5

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 rn_ios_unmount_breaking_change 中的必需 reproducer 开始,并在 iOS 的 React Native 0.83.4 或 0.84.1 上验证三种键盘场景。比较强制退出后打开键盘和不打开键盘时的 unmount 时间戳;完成的标准是已理解该行为,并且杀死应用时不再触发非预期的清理,在适当情况下加入回归覆盖。

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

评估

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

把新 issue 发到你的邮箱

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