Multiline controlled input enters an infinite loop on iOS
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked rn-bug-loop reproducer and reproduce the infinite loop on iOS using the controlled multiline TextInput shown in the issue. Compare behavior with multiline removed, then trace the React Native TextInput path involved; done means multiline controlled input no longer loops while the reported setup remains functional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, javascript, react-native
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100