[utils] Fix resolveProps to correctly merge slotProps defined as functions - #48955
Open
mnajdova wants to merge 1 commit into
Open
[utils] Fix resolveProps to correctly merge slotProps defined as functions#48955mnajdova wants to merge 1 commit into
mnajdova wants to merge 1 commit into
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
silviuaavram
marked this pull request as ready for review
August 12, 2026 16:17
silviuaavram
requested review from
silviuaavram
and
a lite review from Copilot
August 12, 2026 16:17
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes resolveProps so slotProps defined as functions (notably when coming from theme defaultProps) are merged with component-provided slotProps instead of being dropped/overridden, aligning functional slotProps behavior with the object variant.
Changes:
- Defer merging when either side of a slot prop is a function by wrapping it in a function that resolves both sides and then merges via
resolveProps. - Add unit tests covering functional
slotPropsmerging across theme defaults vs component props, including mixed function/object combinations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/mui-utils/src/resolveProps/resolveProps.ts | Wraps functional slot-prop merging to defer resolution until ownerState is available, then merges the resolved objects. |
| packages/mui-utils/src/resolveProps/resolveProps.test.ts | Adds regression tests for merging functional slotProps across default props and component props. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+56
to
+72
| (output[propName] as Record<string, unknown>)[slotPropName] = ( | ||
| ...args: unknown[] | ||
| ) => | ||
| resolveProps( | ||
| typeof defaultSlotPropValue === 'function' | ||
| ? defaultSlotPropValue(...args) | ||
| : defaultSlotPropValue, | ||
| typeof slotPropValue === 'function' ? slotPropValue(...args) : slotPropValue, | ||
| mergeClassNameAndStyle, | ||
| ); | ||
| } else { | ||
| (output[propName] as Record<string, unknown>)[slotPropName] = resolveProps( | ||
| defaultSlotPropValue, | ||
| slotPropValue, | ||
| mergeClassNameAndStyle, | ||
| ); | ||
| } |
Comment on lines
+155
to
+173
| it('keep function slot props from default props when the slot is missing from props', () => { | ||
| const result = resolveProps( | ||
| { | ||
| slotProps: { | ||
| list: (ownerState: { anchorId: string }) => ({ | ||
| 'aria-labelledby': ownerState.anchorId, | ||
| }), | ||
| }, | ||
| }, | ||
| { slotProps: { paper: { className: 'my-paper' } } }, | ||
| ); | ||
|
|
||
| const slotProps = result.slotProps as Record<string, any>; | ||
| expect(slotProps.paper).to.deep.equal({ className: 'my-paper' }); | ||
| expect(slotProps.list).to.be.a('function'); | ||
| expect(slotProps.list({ anchorId: 'dashboard' })).to.deep.equal({ | ||
| 'aria-labelledby': 'dashboard', | ||
| }); | ||
| }); |
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 #48907