Description
the <ToolsPanelItem> hasValue API appears to expect a boolean, but it does not validate or coerce the returned value. When hasValue returns a non-boolean (e.g., undefined), the control fails to render and there is no console error or warning, making the issue difficult to diagnose.
Examples
If you do the following, controls will not be rendered when hoge or foo are undefined.
<ToolsPanelItem
hasValue={() => hoge || foo}
/* ... */
>
{/* control */}
</ToolsPanelItem>
This can avoid the problem if modified as follows.
<ToolsPanelItem
hasValue={() => !!(setTransition || setHov)}
/* ... */
>
{/* control */}
</ToolsPanelItem>
However, it takes time to notice this because there are no errors in the console.
Expected behavior:
-
hasValue should reliably accept and require a boolean.
-
If a non-boolean is returned, the component should either:
▫ Coerce to a boolean internally (Boolean(result)), or
▫ Emit a clear developer warning (and ideally fail in dev builds), so consumers can correct their code.
- Documentation and types should communicate the strict boolean requirement.
Step-by-step reproduction instructions
-
Create a ToolsPanelItem and set hasValue to an expression that can evaluate to undefined, e.g. hasValue={() => hoge || foo} where both values may be undefined initially.
-
Render the control within the editor sidebar (e.g., a block inspector panel).
-
Ensure both operands are undefined at render time.
-
Observe that the control does not render.
-
Check the browser console: no error or warning is emitted.
Screenshots, screen recording, code snippet
No response
Environment info
Browser: Chrome (latest) on macOS.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
Description
the
<ToolsPanelItem>hasValueAPI appears to expect a boolean, but it does not validate or coerce the returned value. When hasValue returns a non-boolean (e.g., undefined), the control fails to render and there is no console error or warning, making the issue difficult to diagnose.Examples
If you do the following, controls will not be rendered when hoge or foo are undefined.
This can avoid the problem if modified as follows.
However, it takes time to notice this because there are no errors in the console.
Expected behavior:
hasValue should reliably accept and require a boolean.
If a non-boolean is returned, the component should either:
▫ Coerce to a boolean internally (Boolean(result)), or
▫ Emit a clear developer warning (and ideally fail in dev builds), so consumers can correct their code.
Step-by-step reproduction instructions
Create a ToolsPanelItem and set hasValue to an expression that can evaluate to undefined, e.g. hasValue={() => hoge || foo} where both values may be undefined initially.
Render the control within the editor sidebar (e.g., a block inspector panel).
Ensure both operands are undefined at render time.
Observe that the control does not render.
Check the browser console: no error or warning is emitted.
Screenshots, screen recording, code snippet
No response
Environment info
Browser: Chrome (latest) on macOS.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.