-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
[styled-engine] Fix style overrides variants type #45478
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
Changes from 8 commits
9618878
04ea73d
cade9e8
d7ec526
1537b32
daa9579
cbe257a
e91681e
48dda59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,7 @@ const theme = createTheme(); | |
variants: [ | ||
{ | ||
props: ({ ownerState }) => ownerState.color === 'primary', | ||
style: {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't style required before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was, but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. that's correct. |
||
}, | ||
], | ||
}), | ||
|
@@ -263,3 +264,24 @@ const theme = createTheme(); | |
}, | ||
}); | ||
} | ||
|
||
// Invalid variant | ||
{ | ||
createTheme({ | ||
components: { | ||
MuiButton: { | ||
styleOverrides: { | ||
// @ts-expect-error invalid variant | ||
root: { | ||
variants: [ | ||
{ | ||
props: { variant: 'not-a-variant' }, | ||
style: { border: 0 }, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,19 +59,7 @@ export interface CSSOthersObjectForCSSObject { | |
} | ||
|
||
// Omit variants as a key, because we have a special handling for it | ||
export interface CSSObject | ||
extends CSSPropertiesWithMultiValues, | ||
CSSPseudos, | ||
Omit<CSSOthersObject, 'variants'> {} | ||
|
||
interface CSSObjectWithVariants<Props> extends Omit<CSSObject, 'variants'> { | ||
variants: Array<{ | ||
props: Props | ((props: Props) => boolean); | ||
style: | ||
| CSSObject | ||
| ((args: Props extends { theme: any } ? { theme: Props['theme'] } : any) => CSSObject); | ||
}>; | ||
} | ||
export interface CSSObject extends CSSPropertiesWithMultiValues, CSSPseudos, CSSOthersObject {} | ||
|
||
export interface ComponentSelector { | ||
__emotion_styles: any; | ||
|
@@ -106,8 +94,29 @@ export interface FunctionInterpolation<Props> { | |
export interface ArrayInterpolation<Props> extends ReadonlyArray<Interpolation<Props>> {} | ||
|
||
export type Interpolation<Props> = | ||
| InterpolationPrimitive | ||
| CSSObjectWithVariants<Props> | ||
| null | ||
| undefined | ||
| boolean | ||
| number | ||
| string | ||
| ComponentSelector | ||
| Keyframes | ||
| SerializedStyles | ||
| CSSPropertiesWithMultiValues | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a myth to me. If not adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean with "myth"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At first, I thought that ![]() Here is the full error:
I don't fully understand why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error is not related too much to the type that's being added, this is suspicious, let me check it again locally and I will report back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on this type: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/createTheme.ts#L38 the error is expected in my opinion. The issue is that in createTheme, we return this type: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/createThemeNoVars.d.ts#L82 which has different definition for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed loosening There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DiegoAndai I tried loosen the type and include the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this change is causing major issues on mui-x There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I am taking a look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wrote the info in slack > https://mui-org.slack.com/archives/C011VC970AW/p1747795216756729 |
||
| (CSSObject & { | ||
siriwatknp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
variants?: Array<{ | ||
props: | ||
| Partial<Props> | ||
| (( | ||
props: Partial<Props> & { | ||
ownerState: Partial<Props>; | ||
}, | ||
) => boolean); | ||
style: | ||
| CSSObject | ||
| ((args: Props extends { theme: any } ? { theme: Props['theme'] } : any) => CSSObject); | ||
}>; | ||
}) | ||
| ArrayInterpolation<Props> | ||
| FunctionInterpolation<Props>; | ||
|
||
|
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.
Have to fix this because the type of
selected
isboolean | undefined
.Should we loosen the type like of props? to be
() => boolean | null | undefined
?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.
I don't mind the
!!
to cast into booleanThere 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.
Does this mean this is a breaking change?
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.
I would argue it's a fix as it was always supposed to be
() => boolean
(it's onlyboolean
in theCSSObjectWithVariants
type), but it wasn't actually because the type wasn't being correctly picked up.It's one of those fixes that could be perceived as a breaking change.
Maybe we could compromise with a minor release and an explanation on the changelog?
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 would be the last thing that we need to decide on. Similar to the
styles
now being required, this is a fix that might be perceived as breaking.My proposal is that we release it with in a minor version and a note.
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.
Let's do that.