Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput with nested Text field for styling duplicates letters when typing. #34668

Closed
AdamJB opened this issue Sep 12, 2022 · 9 comments
Closed
Labels
Component: TextInput Related to the TextInput component. Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@AdamJB
Copy link

AdamJB commented Sep 12, 2022

Description

Recently we updated to RN 0.70, and have encountered an issue where having a nested inside a field causes double typing. Before this worked fine in RN 0.63.

We use this to stylize @mention inputs for a chat feature.

Notes:
Adding value={''} fixes the issue for iOS, but causes a crash on Android with Cannot specify both value and children..

I managed to get it working on Android by commenting that line out in the RN code base, and patching it, but it causes another issue, where typing on Android "skips" a few letters when typing.

Version

0.70.0

Output of npx react-native info

System:
OS: macOS 12.5.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 1.82 GB / 16.00 GB
Shell: 5.7.1 - /usr/local/bin/zsh
Binaries:
Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
Yarn: 1.22.19 - ~/git/caliber-mobile-app/node_modules/.bin/yarn
npm: 8.18.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: Chipmunk 2021.2.1 Patch 2 Chipmunk 2021.2.1 Patch 2
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.16 - /Users/abednarek/.sdkman/candidates/java/current/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: v0.70.0 => 0.70.0
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  • Use a Text Input with nested for styling
  • Type in the text field, and notice that the characters are duplicated. 1 set is Styled as per the component, and the others are styled differently.

Snack, code example, screenshot, or link to a repository

Code Snippet on reproducing this issue. Quite straight forward:

<TextInput
  style={{
    width: 240,
    height: 44,
    backgroundColor: '#ccc',    
  }}
  onChangeText={(text) => {
    setEnteredText(text);
  }}          
  >
  <Text
    style={{
      color: '#F0F'
    }}>
      {enteredText}
  </Text>
</TextInput>

Here's what it looks like when I type "Hi":
Screen Shot 2022-09-12 at 2 25 20 PM

@react-native-bot react-native-bot added the Component: TextInput Related to the TextInput component. label Sep 12, 2022
@wfern
Copy link
Contributor

wfern commented Sep 13, 2022

Hi! I can confirm and reproduce the issue.

I can confirm it's not happening on 0.69.x.

I think it was introduced here: 51f49ca
Setting the value to an empty string works on iOS but not on Android because os this check:

const childCount = React.Children.count(children);
invariant(
!(props.value != null && childCount),
'Cannot specify both value and children.',
);

Commenting the added lines of the commit fixed for me on both platforms.

@AdamJB
Copy link
Author

AdamJB commented Sep 13, 2022

Hi,

I did that but it causes another issue for me. Typing on Android skips letters on the Android Keybaord on Android 10 and 11, but seems to work fine on Android 12. I was able to also get it working with other keyboards, like Fleksy, but we can't just ask all our Android users to use different keyboards.

Simple way to reproduce that:
On an Android 10 emulator, type something like "keyboard" really quick using the virtual keyboard, and notice that when typing 2 characters quickly together will register with the keyboard and show that it was tapped, but the characters don't get sent to the input field.

I assume it's related to why this 'Cannot specify both value and children' was introduced.

  • Adam

@wfern
Copy link
Contributor

wfern commented Sep 13, 2022

I try to find this issue, tested on Android 10 and 11 emulators for this and can't reproduce it. Tested with virtual and physical keyboard typing really quick but no luck find it.

Can you make a quick video reproducing it? I think it can help other people to confirm it.

@efstathiosntonas
Copy link

efstathiosntonas commented Sep 14, 2022

This is the issue:
https://user-images.githubusercontent.com/717975/190082383-66bb3ee3-1a6e-4b2b-9dcc-1c1da99472ff.mov

edit: I also use this "technique" to add @mentions

@HackerM00n
Copy link

Faced the same problem after updating RN 0.68.0 to 0.70.1.

Compared TextInput.js and found two lines that break our functionality.

Screenshot 2022-09-17 at 11 51 56

I just commented them and it worked for me. No need to add value={''}.

Hope this helps you too.

@t0nyh0
Copy link

t0nyh0 commented Sep 20, 2022

Thank you @HackerM00n!

react-native+0.70.1.patch file for those using patch-package for now, until an official fix is in

https://github.com/facebook/react-native/issues/34668

diff --git a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
index cb71d97..8fa1171 100644
--- a/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
+++ b/node_modules/react-native/Libraries/Components/TextInput/TextInput.js
@@ -976,8 +976,6 @@ function InternalTextInput(props: Props): React.Node {
   const text =
     typeof props.value === 'string'
       ? props.value
-      : typeof lastNativeText === 'string'
-      ? lastNativeText
       : typeof props.defaultValue === 'string'
       ? props.defaultValue
       : '';

@Noitham
Copy link

Noitham commented Sep 27, 2022

Confirm I have the same issue after upgrading from 0.69.4 to 0.70.1.

Moved the <TextInput> nested children into the value prop instead and all good.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 26, 2023
@github-actions
Copy link

github-actions bot commented Apr 4, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Apr 4, 2023
@facebook facebook locked as resolved and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TextInput Related to the TextInput component. Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

7 participants