Skip to content
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

[system] Fix various issues reported by using @mui/styled-engine-sc #29035

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Oct 13, 2021

Fixing some issues found by using @mui/styled-engine-sc directly in the @mui/system. Inspired by #29036. The changes from #29036 are also included here. The purpose is to battle test how well the integration with styled-components is really working.

Fixes #28905
Fixes #27167

List of problems found:

The issues (not blocking) that I could not resolve are:

@mnajdova mnajdova marked this pull request as draft October 13, 2021 15:10
@mui-pr-bot
Copy link

mui-pr-bot commented Oct 13, 2021

Details of bundle changes

Generated by 🚫 dangerJS against 1ae3b8b

@mnajdova mnajdova added bug 🐛 Something doesn't work package: styled-engine-sc Specific to styled-components umbrella For grouping multiple issues to provide a holistic view labels Oct 14, 2021
@mnajdova mnajdova changed the title [DO NOT REVIEW][styled-engine] Moves styled types to the styled engiene packages [umbrella] Track issues related to @mui/styled-engine-sc Oct 14, 2021
@mnajdova mnajdova changed the title [umbrella] Track issues related to @mui/styled-engine-sc [system] Fix various issues reported by using @mui/styled-engine-sc Oct 15, 2021
@mnajdova
Copy link
Member Author

mnajdova commented Oct 15, 2021

Latest commit using @mui/styled-engine-sc as a dependency of the @mui/system - 8bfb23b

The failing CI checks are because of the unresolved issues described in the PR description. There is nothing we can do about them at this moment, but the important bits are that those are not revelnt to the users of the packages.

@mnajdova mnajdova marked this pull request as ready for review October 15, 2021 12:17
</Box>
</ThemeProvider>
</CacheProvider>
<StyleSheetManager stylisPlugins={[rtlPluginSc]}>
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the StyleSheetManager too so that we can support styled-components in the future too.

@@ -537,10 +537,11 @@ describe('styled', () => {

const classList = Array.from(container.firstChild.classList);
const regExp = new RegExp(`.*-MuiComponent-slot$`);
const regExpSC = new RegExp(`MuiComponent-slot.*`);
Copy link
Member Author

Choose a reason for hiding this comment

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

emotion appends, but styled-components prepends the label.

}

export function shouldForwardProp(propName: PropertyKey): boolean;
export type CreateMUIStyled<T extends object = DefaultTheme> = CreateMUIStyledStyledEngine<
Copy link
Member Author

Choose a reason for hiding this comment

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

This is now using the CreateMUIStyled coming from the styled engine.

@@ -6,3 +10,170 @@ export { default as StyledEngineProvider } from './StyledEngineProvider';

export { default as GlobalStyles } from './GlobalStyles';
export * from './GlobalStyles';

export interface SerializedStyles {
Copy link
Member Author

Choose a reason for hiding this comment

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

These are basically just copied from the packages/mui-system/createStyled.d.ts.

export { default as GlobalStyles } from './GlobalStyles';
export * from './GlobalStyles';

// These are the same as the ones in @mui/styled-engine
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the same as the ones in @mui/styled-engine just using styled-components.

@@ -95,7 +95,7 @@ const StoreTemplateLink = React.forwardRef<

const StoreTemplateImage = React.forwardRef<
HTMLImageElement,
{ brand: TemplateBrand } & JSX.IntrinsicElements['img']
{ brand: TemplateBrand } & Omit<JSX.IntrinsicElements['img'], 'ref'>
Copy link
Member Author

Choose a reason for hiding this comment

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

The changes on the refs are related to this issue: https://codesandbox.io/s/elegant-matan-k7mw4?file=/src/App.tsx
See styled-components/styled-components#3191 (comment)

We can also use React.ComponentPropsWithoutRef<'img'> instead. I will update if we decide to go with this option.

Copy link
Member

@siriwatknp siriwatknp Oct 19, 2021

Choose a reason for hiding this comment

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

We can also use React.ComponentPropsWithoutRef<'img'> instead. I will update if we decide to go with this option.

Sounds good to me.

@mnajdova mnajdova requested review from a team and removed request for oliviertassinari and siriwatknp October 15, 2021 12:26
@@ -120,7 +121,7 @@ const monthMap = [
function CalendarPickerSkeleton(props: CalendarPickerSkeletonProps) {
const { className, ...other } = useThemeProps<
Theme,
JSX.IntrinsicElements['div'],
Omit<JSX.IntrinsicElements['div'], 'ref'> & { ref?: React.Ref<HTMLDivElement> },
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, how is it different from JSX.IntrinsicElements['div']? I saw that JSX.IntrinsicElements['div'] has a ref of type string | Ref<T> - does the string makes a difference that breaks things here?

Copy link
Member

@siriwatknp siriwatknp Oct 19, 2021

Choose a reason for hiding this comment

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

type Ref<T> = RefCallback<T> | RefObject<T> | null;
type LegacyRef<T> = string | Ref<T>; // this is the ref type of JSX.IntrinsicElements

the LegacyRef is wider than Ref, that's why there is a type error. The other way to fix is to define LegacyRef in packages/mui-styled-engine/src/index.d.ts. Not sure if this is a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other way to fix is to define LegacyRef in packages/mui-styled-engine/src/index.d.ts. Not sure if this is a good idea.

I would be scared to do this, mainly because then if you switch to mui's styled() to styled-components styled() it would break, but we would like those two to behave the same.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 18, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 20, 2021
@NikhilKale123
Copy link

NikhilKale123 commented Mar 3, 2022

Not able to integrate make style for v5.2 in typescript.

@mnajdova
Copy link
Member Author

mnajdova commented Mar 7, 2022

Not able to integrate make style for v5.2 in typescript.

@NikhilKale123 please open an issue with a reproduction and we can take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work package: styled-engine-sc Specific to styled-components umbrella For grouping multiple issues to provide a holistic view
Projects
None yet
5 participants