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

Function component returning null creates an empty text node in the DOM #1490

Open
pauldijou opened this issue Oct 1, 2019 · 3 comments
Open

Comments

@pauldijou
Copy link

Issue Template

Observed Behaviour

Inferno is creating an empty text node when a functional component returns null.

function Nothing() {
  return null;
}

class App extends Component {
  render() {
    return <div><Nothing /></div>
  }
}

Here, the div will have one children, an empty text node.

Expected Current Behaviour

Inferno should not create anything. null, as from my understanding, means to put nothing in the DOM at all. Replacing the functional component with directly {null} in the JSX actually does that (no text node at all).

It's important because an empty text node can actually display some empty spacing if line-height is defined in the CSS on some browsers. I would not expect a component returning null to have any impact.

Reproducing:
https://codesandbox.io/s/vigorous-browser-sw31e

Here is React rendering the same JSX code without any text node in both case:
https://codesandbox.io/s/admiring-water-o3exp

Inferno Metadata

macOS Chrome.

@Havunen
Copy link
Member

Havunen commented Oct 6, 2019

Empty text node is used to track position of Component with null children.

Ideally we dont want to do this, but it fixes some issues. We could try remove that logic and see which test cases will fail

@pauldijou
Copy link
Author

Could using an HTML comment be a valid alternative?

@Havunen
Copy link
Member

Havunen commented Nov 20, 2019

Yes, comment nodes could be used but they pollute DOM :(

I need to check if same routines what we use for Fragments could be used to add support for not rendering anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants