react-native icon indicating copy to clipboard operation
react-native copied to clipboard

TextInput ref gets re-set with every render

Open vonovak opened this issue 4 years ago • 8 comments

Description

starting in 0.62 (probably related with the hooks-rewrite of textinput), every time textinput re-renders, the ref callback function is executed. That means that for every character you write, ref callback is called with

  1. null and then
  2. new ref

the refs are not referentially equal, even though the _nativeTag field on the ref is the same, and the TextInput is not unmounted in between the renders.

React Native version:

This is reproducible on current master

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

use code here https://github.com/facebook/react-native/blob/5cde6c5e7d440e62d21ef858d77ed185df8a2da0/RNTester/js/examples/TextInput/TextInputSharedExamples.js#L162 - just put a console log in there

Expected Results

I expect the ref callback to be called when the component mounts / unmounts only, not on every re-render

vonovak avatar May 28 '20 11:05 vonovak

I'm also seeing this

garrettm avatar Jun 04 '20 00:06 garrettm

:warning: Missing Environment Information
:information_source: Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

github-actions[bot] avatar Jun 10 '20 16:06 github-actions[bot]

Same problem. Here my environment information

System:
    OS: macOS 10.15.5
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 228.73 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.20.1 - ~/.nvm/versions/node/v10.20.1/bin/node
    Yarn: 1.22.4 - ~/.nvm/versions/node/v10.20.1/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v10.20.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 22, 23, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 25.0.2, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.0, 29.0.2, 29.0.3
      System Images: android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  npmPackages:
    react: ^16.13.1 => 16.13.1 
    react-native: ^0.62.2 => 0.62.2

yairopro avatar Jun 30 '20 12:06 yairopro

I can confirm this is happening for us as well.

dani-mp avatar Jul 09 '20 13:07 dani-mp

@vonovak The code you provided to reproduce the error actually is expected to cause the callback to be run on every re-render (see callback ref caveats).

But still, I came across the same error even when the callback ref is not re-created on every render. You can look at the result here.

The ref callback is only called on every re-render (4 times) when the code is running on mobile (I have only tested iOS). There is no issue when using React Native Web, or React DOM for that matter.

And I did not find that the values provided are referentially different when using the same callback ref. I used a Set to keep track of how many distinct object references were passed.

david-arteaga avatar Aug 25 '20 03:08 david-arteaga

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Dec 25 '20 20:12 stale[bot]

I believe (but don’t know) this is still a problem

garrettm avatar Dec 25 '20 23:12 garrettm

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Mar 09 '23 12:03 github-actions[bot]

This issue was closed because the author hasn't provided the requested feedback after 7 days.

github-actions[bot] avatar Mar 16 '23 12:03 github-actions[bot]