-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Avatar] Fix img slot types and add missing slots #45483
base: master
Are you sure you want to change the base?
Conversation
{ | ||
"name": "img", | ||
"description": "The component that renders the transition.\n[Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong.
Netlify deploy previewBundle size reportDetails of bundle changes (Toolpad) |
fallback: { | ||
expectedClassName: classes.fallback, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot test the img
slot together with fallback
here because there is a logic within the component that dynamically render either one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we list what other options were tried, maybe even on the original issue to make sure we don't come back to this again. Some I can think of:
- dynamically inferring types (pros and cons, e.g. TS check performance)
- loosening the types for the slot props with some defaults
etc.
height: 40, | ||
blurDataURL: 'data:image/png;base64', | ||
} satisfies ImageProps, | ||
} as AvatarProps['slotProps'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary assertion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, it's still required because the slotProps.img
has a fixed structure that's different from ImageProps
.
If you exclude the line, TS throws an error.
Added here: #45443 (comment) |
closes #45443
This PR follows the option (2) solution explained in #45443 (comment)
Root cause
The types of
slots.img
is too strict, not able to provide a custom component, .e.g. Next.js Image.Solution
Change the slot type to
React.ElementType
which accept any React component or string. Please see the added spec.I also use this opportunity to add missing slots (
root
andfallback
) in this PR.