react / react/react-native

Multiline controlled input enters an infinite loop on iOS

Đang mở
#46,850 11 bình luận 27 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Issue: Author Provided Repro Platform: iOS
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với reproducer rn-bug-loop được liên kết và tái hiện vòng lặp vô hạn trên iOS bằng TextInput multiline được điều khiển như trong issue. So sánh hành vi khi bỏ multiline, sau đó lần theo đường đi của React Native TextInput có liên quan; hoàn thành khi input multiline được điều khiển không còn lặp và setup được báo cáo vẫn hoạt động bình thường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
ios, javascript, react-native
Lĩnh vực
mobile-dev
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.