react / react/react-native

Multiline controlled input enters an infinite loop on iOS

未关闭
#46,850 11 条评论 27 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Description

This code enters an infinite loop on iOS.

import React, {useState, memo} from 'react'
import {TextInput} from 'react-native'

let App = () => {
  console.log('render App')
  const [outlet, setOutlet] = useState(null)
  return (
    <>
      <Outlet outlet={outlet} />
      <Child setOutlet={setOutlet} />
    </>
  )
}
export default App

let Child = memo(({setOutlet}) => {
  console.log('render Child')
  const [value, setValue] = useState('')
  return (
    <Portal setOutlet={setOutlet}>
      <TextInput
        onChangeText={text => setValue(text)}
        value={value}
        multiline
        style={{
          backgroundColor: 'red',
          marginTop: 200,
        }}
      />
    </Portal>
  )
})

let Outlet = memo(({outlet}) => {
  console.log('render Outlet')
  return outlet
})

let Portal = memo(({children, setOutlet}) => {
  console.log('render Portal')
  React.useLayoutEffect(() => {
    setOutlet(children)
  }, [children])
  return null
})

Removing multiline prop fixes the issue.

I suspect this may be related to https://github.com/facebook/react-native/issues/36494 but who knows.

Steps to reproduce

See above

React Native Version

0.75.4

Affected Platforms

Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 14.6.1
  CPU: (16) arm64 Apple M3 Max
  Memory: 53.04 GB / 128.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.8.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 3.6.4
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.09.09.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.4
    wanted: 0.75.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
Stacktrace or Logs
n/a
Reproducer

https://github.com/gaearon/rn-bug-loop

Screenshots and Videos

https://github.com/user-attachments/assets/9ddf62e5-4322-4d8e-bfd7-c34d94ec773b

贡献指南

打开贡献指南

从这里开始

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

调研方向

从链接的 rn-bug-loop 复现器开始,使用 issue 中所示的受控多行 TextInput 在 iOS 上复现无限循环。比较移除 multiline 后的行为,然后跟踪涉及的 React Native TextInput 路径;当受控多行输入不再循环且报告中的设置仍能正常工作时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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