Skip to content

noLeakedRender

biome.json
{
"linter": {
"rules": {
"nursery": {
"noLeakedRender": "error"
}
}
}
}

Prevent problematic leaked values from being rendered.

This rule prevents values that might cause unintentionally rendered values or rendering crashes in React JSX. When using conditional rendering with the logical AND operator (&&), if the left-hand side evaluates to a falsy value like 0, NaN, or any empty string, these values will be rendered instead of rendering nothing.

const Component = () => {
const count = 0;
return <div>{count && <span>Count: {count}</span>}</div>;
}
code-block.jsx:3:16 lint/nursery/noLeakedRender ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Potential leaked value that might cause unintended rendering.

1 │ const Component = () => {
2 │ const count = 0;
> 3 │ return <div>{count && <span>Count: {count}</span>}</div>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 │ }
5 │

JavaScript’s && operator returns the left value when it’s falsy (e.g., 0, NaN, ”). React will render that value, causing unexpected UI output.

Make sure the condition is explicitly boolean.Use !!value, value > 0, or a ternary expression.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const Component = () => {
const items = [];
return <div>{items.length && <List items={items} />}</div>;
}
code-block.jsx:3:16 lint/nursery/noLeakedRender ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Potential leaked value that might cause unintended rendering.

1 │ const Component = () => {
2 │ const items = [];
> 3 │ return <div>{items.length && <List items={items} />}</div>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 │ }
5 │

JavaScript’s && operator returns the left value when it’s falsy (e.g., 0, NaN, ”). React will render that value, causing unexpected UI output.

Make sure the condition is explicitly boolean.Use !!value, value > 0, or a ternary expression.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const Component = () => {
const user = null;
return <div>{user && <Profile user={user} />}</div>;
}
code-block.jsx:3:16 lint/nursery/noLeakedRender ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Potential leaked value that might cause unintended rendering.

1 │ const Component = () => {
2 │ const user = null;
> 3 │ return <div>{user && <Profile user={user} />}</div>;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4 │ }
5 │

JavaScript’s && operator returns the left value when it’s falsy (e.g., 0, NaN, ”). React will render that value, causing unexpected UI output.

Make sure the condition is explicitly boolean.Use !!value, value > 0, or a ternary expression.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

const Component = () => {
const count = 0;
return <div>{count > 0 && <span>Count: {count}</span>}</div>;
}
const Component = () => {
const items = [];
return <div>{!!items.length && <List items={items} />}</div>;
}
const Component = () => {
const user = null;
return <div>{user ? <Profile user={user} /> : null}</div>;
}
const Component = () => {
const condition = false;
return <div>{condition ? <Content /> : <Fallback />}</div>;
}
const Component = () => {
const isReady = true;
return <div>{isReady && <Content />}</div>;
}