ComboboxControl: narrow onChange callback type to string | null - #81568
Conversation
onChange callback value type to string | nullonChange callback type to string | null
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
Narrows ComboboxControl’s callback type to match its runtime contract and updates affected consumers.
Changes:
- Introduces a shared
string | nullvalue type. - Narrows three consumer handlers.
- Updates package changelogs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/components/src/combobox-control/types.ts |
Narrows the callback type. |
packages/components/CHANGELOG.md |
Records the type change. |
packages/dataviews/src/components/dataform-controls/combobox.tsx |
Narrows the DataForm handler. |
packages/dataviews/CHANGELOG.md |
Records the internal update. |
packages/fields/src/fields/parent/parent-edit.tsx |
Narrows the parent handler. |
packages/fields/CHANGELOG.md |
Records the internal update. |
packages/media-fields/src/attached_to/edit.tsx |
Narrows the attachment handler. |
packages/media-fields/CHANGELOG.md |
Records the internal update. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * Function called with the selected value changes. | ||
| */ | ||
| onChange?: ( value: ComboboxControlProps[ 'value' ] ) => void; | ||
| onChange?: ( value: ComboboxControlValue ) => void; |
|
Size Change: 0 B Total Size: 7.72 MB |
|
|
||
| Function called when the selected value changes. | ||
|
|
||
| - Type: `( value: string | null | undefined ) => void` |
There was a problem hiding this comment.
The undefined type was even documented as something we supported.
mcsf
left a comment
There was a problem hiding this comment.
Glad my suggestion was helpful. :)
…null The onChange parameter was typed via an indexed access on the optional `value` prop, which leaked an accidental `undefined` into the union. The component only ever calls onChange with a string or null, so hoist the value type into a named alias and use it for both props. This lets the DataForm combobox control drop the `undefined` widening it had to add when vendoring ValidatedComboboxControl (#81449). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The parent field (@wordpress/fields) and attached_to field (@wordpress/media-fields) carried the same `| undefined` widening in their combobox onChange handlers, forced by the old callback type. Narrow them to match the fixed upstream signature, and fill in the PR number placeholders in the CHANGELOG entries. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The rebase onto trunk landed after the 2026-08-12 release cut (components 39.0.0, dataviews 18.0.0), leaving the entries stranded in the released sections, which the CHANGELOG diff CI check rejects. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
46e3ed4 to
f201100
Compare
|
Flaky tests detected in f201100. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/31780731026 Should navigate inner blocks with arrow keys in
|
Follow up to this comment.
What?
Narrows the ComboboxControl onChange callback parameter type from
string | null | undefinedtostring | nullby hoisting the value type into a named alias, and reverts the undefined widening that #81449 added to the DataForm combobox handler.Why?
The
onChangeparameter was typed via an indexed access on the optional value prop:And so
ComboboxControlProps[ 'value' ](due to the?modifier onvalue) leaksundefinedinto the onChange callback parameter type. The component never actually callsonChangewithundefined— only with a suggestionstringornullon reset — so consumers were forced to widen their handlers for a value that never arrives (as happened in #81449).How?
By hoisting and sharing the type:
Checked the impact on major consumers and there were no handler breaks.
Testing Instructions
npm run build(or a TypeScript check) and confirm it passes.packages/dataviews/src/components/dataform-controls/combobox.tsx, confirm theonChangehandler typed (newValue: string | null) compiles without the previous| undefinedwidening.Use of AI Tools
Authored with the assistance of Claude Code (implementation, consumer-impact analysis, and this description); reviewed and verified by me.