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

[material-ui] Remove use client from the index styles #41131

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/mui-material/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client';
// do not remove the following import (https://github.com/microsoft/TypeScript/issues/29808#issuecomment-1320713018)
/* eslint-disable @typescript-eslint/no-unused-vars */
// @ts-ignore
import * as React from 'react';
import { unstable_createCssVarsProvider as createCssVarsProvider, SxProps } from '@mui/system';
Copy link
Member

Choose a reason for hiding this comment

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

Dead logic?

Suggested change
import * as React from 'react';

Copy link
Member Author

@siriwatknp siriwatknp Feb 19, 2024

Choose a reason for hiding this comment

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

Required, see https://ci.codesandbox.io/status/mui/material-ui/pr/41131/builds/473769.

stdout: "../mui-material/src/styles/CssVarsProvider.tsx(15,9): error TS2742: The inferred type of 'CssVarsProvider' cannot be named without a reference to 'packages/mui-types/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.\n" +
"../mui-material/src/styles/getInitColorSchemeScript.ts(13,25): error TS2742: The inferred type of 'getInitColorSchemeScript' cannot be named without a reference to 'packages/mui-types/node_modules/@types/react'. This is likely not portable. A type annotation is necessary.\n",
stderr: '

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, @Janpot left a comment about this above. The .d.ts file generated https://unpkg.com/browse/@mui/[email protected]/styles/CssVarsProvider.d.ts needs this import.

Copy link
Member

Choose a reason for hiding this comment

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

Would the following work as well without the @ts-ignore?

/// <reference types="react" />

import { SxProps } from '@mui/system';
import createCssVarsProvider from '@mui/system/cssVars';
import styleFunctionSx from '@mui/system/styleFunctionSx';
import experimental_extendTheme, {
SupportedColorScheme,
Expand All @@ -12,18 +12,19 @@ import experimental_extendTheme, {
import createTypography from './createTypography';
import excludeVariablesFromRoot from './excludeVariablesFromRoot';
import THEME_ID from './identifier';
import { CONSTANT } from './getInitColorSchemeScript';

const defaultTheme = experimental_extendTheme();

const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssVarsProvider<
const { CssVarsProvider, useColorScheme } = createCssVarsProvider<
SupportedColorScheme,
typeof THEME_ID
>({
themeId: THEME_ID,
theme: defaultTheme,
attribute: 'data-mui-color-scheme',
modeStorageKey: 'mui-mode',
colorSchemeStorageKey: 'mui-color-scheme',
attribute: CONSTANT.ATTRIBUTE,
modeStorageKey: CONSTANT.MODE_KEY,
colorSchemeStorageKey: CONSTANT.COLOR_SCHEME_KEY,
defaultColorScheme: {
light: 'light',
dark: 'dark',
Expand All @@ -46,8 +47,4 @@ const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssV
excludeVariablesFromRoot,
});

export {
useColorScheme,
getInitColorSchemeScript,
CssVarsProvider as Experimental_CssVarsProvider,
};
export { useColorScheme, CssVarsProvider as Experimental_CssVarsProvider };
1 change: 0 additions & 1 deletion packages/mui-material/src/styles/defaultTheme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import createTheme from './createTheme';

const defaultTheme = createTheme();
Expand Down
29 changes: 29 additions & 0 deletions packages/mui-material/src/styles/getInitColorSchemeScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// do not remove the following import (https://github.com/microsoft/TypeScript/issues/29808#issuecomment-1320713018)
/* eslint-disable @typescript-eslint/no-unused-vars */
// @ts-ignore
import * as React from 'react';
import { getInitColorSchemeScript as systemGetInitColorSchemeScript } from '@mui/system/cssVars';

const ATTRIBUTE = 'data-mui-color-scheme';
const MODE_KEY = 'mui-mode';
const COLOR_SCHEME_KEY = 'mui-color-scheme';

export const CONSTANT = {
ATTRIBUTE,
MODE_KEY,
COLOR_SCHEME_KEY,
};

export default function getInitColorSchemeScript(
...params: Parameters<typeof systemGetInitColorSchemeScript>
) {
return systemGetInitColorSchemeScript({
attribute: ATTRIBUTE,
colorSchemeStorageKey: COLOR_SCHEME_KEY,
defaultMode: 'light',
defaultLightColorScheme: 'light',
defaultDarkColorScheme: 'dark',
modeStorageKey: MODE_KEY,
...params,
});
}
1 change: 1 addition & 0 deletions packages/mui-material/src/styles/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export { default as withStyles } from './withStyles';
export { default as withTheme } from './withTheme';

export * from './CssVarsProvider';
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';

export { default as experimental_extendTheme } from './experimental_extendTheme';
export type {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/styles/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import MuiError from '@mui-internal/babel-macros/MuiError.macro';

export { default as THEME_ID } from './identifier';
Expand Down Expand Up @@ -45,6 +44,7 @@ export { default as withStyles } from './withStyles';
export { default as withTheme } from './withTheme';

export * from './CssVarsProvider';
export { default as getInitColorSchemeScript } from './getInitColorSchemeScript';
export { default as experimental_extendTheme } from './experimental_extendTheme';
export { default as getOverlayAlpha } from './getOverlayAlpha';
export { default as shouldSkipGeneratingVar } from './shouldSkipGeneratingVar';
Expand Down
Loading