Description
Description
Hi there, first of all, thanks so much for your continued work on React Native, amazing project! 🙌
Recently I tried adding an empty string (both literal ''
and a variable with the same value) outside of a <Text>
component and I did not experience a crash like I was expecting (I was expecting it to show me the Text strings must be rendered within a <Text> component.
error as documented in many issues in this repo and elsewhere on the Internet).
For example, this code:
const App = () => {
const name = '';
return (
<SafeAreaView>
<View>
<Text>Empty string outside of <Text>:</Text>
{''}
<Text>Empty string variable outside of <Text>:</Text>
{name}
</View>
</SafeAreaView>
);
};
...does not cause a crash:
Whereas adding content to one of the string literals (adding the 'a'
) does indeed cause the error:
My question: Is this an intentional feature in the last versions of React Native? Or a regression?
Motivation: If this is indeed not an issue, then the documentation for eslint-plugin-react/jsx-no-leaked-render
needs to be changed: jsx-eslint/eslint-plugin-react#3203 (comment)
cc @rickhanlonii I created an issue over here, since you mentioned you would take a look into it
- Original Tweet: https://twitter.com/karlhorky/status/1577257935796740096
- Reproduction (
[email protected]
): https://github.com/karlhorky/react-native-empty-string-outside-text-component
Version
0.70.1
Output of npx react-native info
System:
OS: macOS 12.6
CPU: (8) arm64 Apple M1
Memory: 307.61 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.11.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.2 - /opt/homebrew/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.1 => 0.70.1
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
info React Native v0.70.3 is now available (your project is running on v0.70.1).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.70.3
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.70.1
info To upgrade, run "react-native upgrade".
Steps to reproduce
- Clone the repository above
- Start the application in an iPhone Simulator or Android emulator
- The empty strings outside of
<Text>
components do not cause the app to crash