Skip to content

Empty string without <Text> component does not cause error / crash #35002

Closed
@karlhorky

Description

@karlhorky

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 &lt;Text&gt;:</Text>
        {''}
        <Text>Empty string variable outside of &lt;Text&gt;:</Text>
        {name}
      </View>
    </SafeAreaView>
  );
};

...does not cause a crash:

FeOKuedXwAEbQim

Whereas adding content to one of the string literals (adding the 'a') does indeed cause the error:

FeOK4U8XwAM4FID

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

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

  1. Clone the repository above
  2. Start the application in an iPhone Simulator or Android emulator
  3. The empty strings outside of <Text> components do not cause the app to crash

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions