fix(react-utilities): handle special native prop names - #36806
Paolo Aliprandi (paolo-aliprandi) wants to merge 3 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
📊 Bundle size reportUnchanged fixtures
|
|
Pull request demo site: URL |
| ): TAttributes { | ||
| const allowedPropNames = (tagName && nativeElementMap[tagName]) || htmlElementProperties; | ||
| const allowedPropNames = | ||
| tagName && Object.prototype.hasOwnProperty.call(nativeElementMap, tagName) |
There was a problem hiding this comment.
we could use the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
| tagName && Object.prototype.hasOwnProperty.call(nativeElementMap, tagName) | |
| tagName && Object.hasOwn(nativeElementMap, tagName) |
There was a problem hiding this comment.
I tried this suggestion, but react-utilities:build fails with error TS2550 because this package’s configured TypeScript lib does not include Object.hasOwn. I kept Object.prototype.hasOwnProperty.call, which provides the same own-property check and preserves the current build target. Do you think it's ok to proceed in this way?
There was a problem hiding this comment.
Martin Hochel (@Hotell) do you think we can tweak ts config to allow using Object.hasOwn?
| for (const key of keys) { | ||
| const isNativeProp = | ||
| (!isArray && (allowedPropNames as Record<string, number>)[key]) || | ||
| (!isArray && Object.prototype.hasOwnProperty.call(allowedPropNames, key)) || |
There was a problem hiding this comment.
same here
There was a problem hiding this comment.
as above
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fixes have regression coverage, and no unresolved issues were identified.
Review effort: Balanced
Findings: None
What changed in this PR
This PR fixes how react-utilities filters native props with special property names, preventing prototype-chain matches and preserving the filtered result’s prototype.
Changes:
- Require own-property matches for native element and prop allow-lists.
- Safely copy an explicitly allowed
__proto__property. - Add regression tests and a patch change file.
| File | Description |
|---|---|
packages/react-components/react-utilities/src/utils/properties.ts |
Tightens allow-list matching and safely copies __proto__. |
packages/react-components/react-utilities/src/utils/properties.test.ts |
Tests inherited names and result-prototype behavior. |
packages/react-components/react-utilities/src/utils/getNativeElementProps.ts |
Avoids inherited tag-name matches. |
packages/react-components/react-utilities/src/utils/getNativeElementProps.test.ts |
Tests a prototype-chain tag name. |
change/@fluentui-react-utilities-98768ced-77df-4ff0-942d-db5a851f8745.json |
Records the patch release. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Summary
Validation
yarn nx run react-utilities:test --runTestsByPath src/utils/getNativeElementProps.test.ts src/utils/properties.test.ts --runInBandyarn nx run react-utilities:lintyarn nx run react-utilities:build