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

Empty text node crashes #1845

Closed
KevinBatdorf opened this issue May 29, 2022 · 5 comments
Closed

Empty text node crashes #1845

KevinBatdorf opened this issue May 29, 2022 · 5 comments
Assignees
Labels
api Issues related to API bug Something isn't working status: fixed in next release The issue will be closed once next release is available

Comments

@KevinBatdorf
Copy link
Contributor

KevinBatdorf commented May 29, 2022

Raycast version: 1.35.2

Description

Error: Reconciler: Text instances not supported

Returning an empty text node crashes the app. I realize this may be an antipattern though.

Steps To Reproduce

Add this command:

import { List } from "@raycast/api";
export default () => <List>{"" && <List.Item title="My list item" />}</List>;

(Adding some context below in case people come here from Google)

A typical use case would be some data like a website URL coming from an API that you check against, and the data may be an empty string:

export default () => (<List>
  {response?.website && <List.Item title="response.website" />}
</List>);

A better way, of course, is:

export default () => (<List>
  {response?.website ? <List.Item title="response.website" /> : null}
</List>);

The current behavior

It crashes

Screen Shot 2022-05-29 at 5 44 44 PM

The expected behavior

Fail gracefully (at least in production mode?)

@KevinBatdorf KevinBatdorf added api Issues related to API bug Something isn't working labels May 29, 2022
@mathieudutour
Copy link
Member

I’m not sure what gracefully would mean in this case, the reconciler doesn’t support text nodes and there are no plan to support them. We could potentially filter out empty strings on every component but that would impact the performances.

you are indeed right that it is an anti-pattern to use x && y in jsx because you will end up with empty strings and 0s in your output.

@KevinBatdorf
Copy link
Contributor Author

KevinBatdorf commented May 30, 2022

Gracefully would mean instead of crashing the app, it wouldn't render the text node but instead continue to render the other* child nodes. The code I shared here that crashes in Raycast would render properly in React. That's why I opened the issue.

It's an anti pattern but not uncommon with string and boolean values. Arrays behave differently as you pointed out.

I'm not privy to the implementation details so I can't assist with performance issues.

@mathieudutour
Copy link
Member

The code I shared here that crashes in Raycast would render properly in React

It would render properly in react-dom because it supports text nodes. It wouldn't in react-native AFAIK because strings needs to be wrapped in a Text Component.

@KevinBatdorf
Copy link
Contributor Author

Ah, Im not very familiar with React Native. Well anyway, this was also opened to give a solution to anyone else that hits the same error and isn't sure what's going on. It will likely show up on Google in that case. Feel free to close it.

Thanks for looking into it though and the extra context.

@mattisssa mattisssa added the status: fixed in next release The issue will be closed once next release is available label Jun 9, 2022
@mattisssa
Copy link
Contributor

Should be fixed in the v1.37.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to API bug Something isn't working status: fixed in next release The issue will be closed once next release is available
Projects
None yet
Development

No branches or pull requests

3 participants