Skip to content

Fragment under boolean condition leads to crashes #17218

Closed
@yevmoroz

Description

Do you want to request a feature or report a bug?
Bug

What is the current behavior?

Having such code sample inside render's return block

{booleanVariable && <Fragment>contents</Fragment>}

Results in error of a kind

NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

About 1% of users of an application were affected by this, however, I myself was not able to reproduce it. From a component error stack I was able to track-down where possibly can be an issue. Replacing {booleanVariable && ...} with ternary {booleanVariable ? ... : null} resolved the problem and our users are not facing it anymore.

What is the expected behavior?
React not throwing error. Maybe warning? Not rendering that particular part? But not crashing the whole application.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
It crashed with react version 16.9.0, other versions were not tested. Users that were affected have Windows 7+, Mac OS 10.13+ and Chrome 77+.

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