Skip to content

[utils] Fix resolveProps to correctly merge slotProps defined as functions - #48955

Open
mnajdova wants to merge 1 commit into
mui:masterfrom
mnajdova:feat/merging-default-props
Open

[utils] Fix resolveProps to correctly merge slotProps defined as functions#48955
mnajdova wants to merge 1 commit into
mui:masterfrom
mnajdova:feat/merging-default-props

Conversation

@mnajdova

Copy link
Copy Markdown
Member

Fixes #48907

@mnajdova mnajdova added type: bug It doesn't behave as expected. package: utils Specific to the utils package. labels Aug 12, 2026
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48955--material-ui.netlify.app/
QR code for https://deploy-preview-48955--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+135B(+0.03%) 🔺+41B(+0.03%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+135B(+0.19%) 🔺+44B(+0.18%)
@mui/utils 🔺+134B(+0.87%) 🔺+38B(+0.64%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@silviuaavram
silviuaavram marked this pull request as ready for review August 12, 2026 16:17
@silviuaavram
silviuaavram requested review from silviuaavram and a lite review from Copilot August 12, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 slotProps merging 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',
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: utils Specific to the utils package. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merging functional slotProps of a theme

2 participants