question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Text>{[React.createElement(() => null)]}</Text> trigger a totally unexpected error

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Sorry but in my current project, react-native info does not exist yet (0.42). This my bug is reproducible on Expo SDK 0.22 (so react-native 0.49) on both iOS and Android so my platform informations won’t help.

Steps to Reproduce

Create a component with a Text that have an array of children. One of the children is a component that in my case, might returns null. Easiest thing to reproduce is to throw in any project

<Text>{[React.createElement(() => null)]}</Text>

Expected Behavior

I expect the Text to just render nothing, like a null value normally does.

Actual Behavior

As we are speaking, this code trigger an fatal error (actually in production release, this can even crash your app.

The fatal error is not even appropriate as it says:

Views nested within a <Text> must have a width and height.

It can be very hard to debug in a big codebase.

screen shot 2017-11-02 at 16 12 57

This can looks like an edge case, but at the same time I am really surprised of this bug.

Reproducible Demo

https://snack.expo.io/@moox/text-with-null-components

Just load this on expo and you will get a white page instead of a “Test” string in the very top left corner.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MoOxcommented, Nov 6, 2017

@cdlewis not directly removed as there is now <ImageBackground> that allows the same behavior as Image was offering. So not sure that’s a good idea to not give the ability to allow children to Text. For my experience, it’s very useful to be able to use components in a Text. A simple example I see is i18n.

0reactions
stale[bot]commented, Sep 6, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.createElement: type is invalid -- expected a string
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >
Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing framework of your choice. At Facebook we use Jest for painless JavaScript...
Read more >
8 common React error messages and how to address them
Learn about the most common error messages in React Development and the meaning behind them, the error itself, and how to fix it....
Read more >
How To Create React Elements with JSX - DigitalOcean
css'; function App() { return null; } export default App;. Save and exit the text editor. Finally, delete the logo. In the terminal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found