[select][combobox] Fix record items label lookup reading from Object.prototype - #5518
Merged
Merged
Conversation
XionWCFM
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
August 16, 2026 16:13
commit: |
Bundle size
PerformanceTotal duration: 1,180.54 ms -7.26 ms(-0.6%) | Renders: 76 (+0) | Paint: 1,866.52 ms +13.73 ms(+0.7%)
12 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5517
Summary
When
itemsis provided as a plain record map,resolveSelectedLabelread the label with(items as any)[value] ?? fallback(). The bracket lookup walks the prototype chain, so a selected value matching anObject.prototypemember (constructor,toString,hasOwnProperty,__proto__, …) resolved to the inherited function instead of the fallback label. Since functions are nevernull/undefined, the??fallback never ran, and rendering the value viaSelect.Value/Combobox.Valuecrashed with "Functions are not valid as a React child."The lookup now only reads own keys via
Object.hasOwn, preserving the documentednullplaceholder key behavior (coerced to"null").Why this is the established pattern in the codebase
This is the same prototype-chain trap that
CheckboxGroupalready guards against — checkbox values are consumer data, so a value likeconstructormust not read offObject.prototype:checkbox-group/useCheckboxGroupParent.ts:17-18uses aMapinstead of an object for its value registry, with an explicit comment:checkbox-group/useCheckboxGroupParent.test.tsx:258has a dedicated test, "does not read aria-controls ids off Object.prototype".Form errors are keyed by field name (also consumer data), so the same collision is guarded with
Object.hasOwninform/Form.tsx:150,field/root/FieldRoot.tsx:94, andfield/error/FieldError.tsx:41. This change brings the remaining record lookup inresolveSelectedLabelin line with those.Test plan
resolveValueLabel.test.tscovering:nullplaceholder key in a record still resolvingpnpm test:jsdom resolveValueLabel --no-watch,SelectValue,ComboboxValue— all passpnpm eslint,pnpm typescript,pnpm prettier— clean