Skip to content

ToolsPanelItem: hasValue silently fails when it returns a non-boolean (e.g., undefined), causing the control to not render #73069

@ddryo

Description

@ddryo

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

  1. 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.

  2. Render the control within the editor sidebar (e.g., a block inspector panel).

  3. Ensure both operands are undefined at render time.

  4. Observe that the control does not render.

  5. 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.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

Labels

[Package] Components/packages/components[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions