Skip to content

Commit

Permalink
Revert "add InitColorSchemeScript"
Browse files Browse the repository at this point in the history
This reverts commit 82d7240.
  • Loading branch information
siriwatknp committed May 17, 2024
1 parent 82d7240 commit 38de969
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
47 changes: 24 additions & 23 deletions packages/mui-material/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,35 @@ import THEME_ID from './identifier';

const defaultTheme = experimental_extendTheme();

const { CssVarsProvider, useColorScheme, getInitColorSchemeScript, InitColorSchemeScript } =
createCssVarsProvider<SupportedColorScheme, typeof THEME_ID>({
themeId: THEME_ID,
theme: defaultTheme,
attribute: 'data-mui-color-scheme',
modeStorageKey: 'mui-mode',
colorSchemeStorageKey: 'mui-color-scheme',
defaultColorScheme: {
light: 'light',
dark: 'dark',
},
resolveTheme: (theme) => {
const newTheme = {
...theme,
typography: createTypography(theme.palette, theme.typography),
};
const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssVarsProvider<
SupportedColorScheme,
typeof THEME_ID
>({
themeId: THEME_ID,
theme: defaultTheme,
attribute: 'data-mui-color-scheme',
modeStorageKey: 'mui-mode',
colorSchemeStorageKey: 'mui-color-scheme',
defaultColorScheme: {
light: 'light',
dark: 'dark',
},
resolveTheme: (theme) => {
const newTheme = {
...theme,
typography: createTypography(theme.palette, theme.typography),
};

newTheme.unstable_sx = function sx(props: SxProps<CssVarsTheme>) {
return styleFunctionSx({ sx: props, theme: this });
};
newTheme.unstable_sx = function sx(props: SxProps<CssVarsTheme>) {
return styleFunctionSx({ sx: props, theme: this });
};

return newTheme;
},
});
return newTheme;
},
});

export {
useColorScheme,
getInitColorSchemeScript,
CssVarsProvider as Experimental_CssVarsProvider,
InitColorSchemeScript,
};
3 changes: 0 additions & 3 deletions packages/mui-system/src/cssVars/createCssVarsProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ export interface CreateCssVarsProviderResult<
) => React.ReactElement;
useColorScheme: () => ColorSchemeContextValue<ColorScheme>;
getInitColorSchemeScript: typeof getInitColorSchemeScript;
InitColorSchemeScript: (
props: Parameters<typeof getInitColorSchemeScript>[0],
) => React.ReactElement;
}

export default function createCssVarsProvider<
Expand Down
6 changes: 1 addition & 5 deletions packages/mui-system/src/cssVars/createCssVarsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,5 @@ export default function createCssVarsProvider(options) {
...params,
});

const InitColorSchemeScript = React.memo(function InitColorSchemeScript(props) {
return getInitColorSchemeScript(props);
});

return { CssVarsProvider, useColorScheme, getInitColorSchemeScript, InitColorSchemeScript };
return { CssVarsProvider, useColorScheme, getInitColorSchemeScript };
}
5 changes: 0 additions & 5 deletions packages/mui-system/src/cssVars/getInitColorSchemeScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export interface GetInitColorSchemeScriptOptions {
* @default 'data-color-scheme'
*/
attribute?: string;
/** Nonce string to pass to the inline script for CSP headers */
nonce?: string | undefined;
}

export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions) {
Expand All @@ -53,13 +51,10 @@ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScr
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY,
attribute = DEFAULT_ATTRIBUTE,
colorSchemeNode = 'document.documentElement',
nonce,
} = options || {};
return (
<script
key="mui-color-scheme-init"
suppressHydrationWarning
nonce={typeof window === 'undefined' ? nonce : ''}
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `(function() {
Expand Down

0 comments on commit 38de969

Please sign in to comment.