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][joy-ui] Remove warning from getInitColorSchemeScript #42838

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions docs/pages/_document.js
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { ServerStyleSheets as JSSServerStyleSheets } from '@mui/styles';
import { ServerStyleSheet } from 'styled-components';
import Document, { Html, Head, Main, NextScript } from 'next/document';
import GlobalStyles from '@mui/material/GlobalStyles';
import MuiInitColorSchemeScript from '@mui/material/InitColorSchemeScript';
import JoyInitColorSchemeScript from '@mui/joy/InitColorSchemeScript';
import { getInitColorSchemeScript as getMuiInitColorSchemeScript } from '@mui/material/styles';
import { getInitColorSchemeScript as getJoyInitColorSchemeScript } from '@mui/joy/styles';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import createEmotionCache from 'docs/src/createEmotionCache';
import { getMetaThemeColor } from '@mui/docs/branding';
Expand Down Expand Up @@ -173,8 +173,8 @@ export default class MyDocument extends Document {
/>
</Head>
<body>
<MuiInitColorSchemeScript defaultMode="system" />
<JoyInitColorSchemeScript defaultMode="system" />
{getMuiInitColorSchemeScript({ defaultMode: 'system' })}
{getJoyInitColorSchemeScript({ defaultMode: 'system' })}
<Main />
<script
// eslint-disable-next-line react/no-danger
Expand Down
27 changes: 4 additions & 23 deletions packages/mui-joy/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import type { SupportedColorScheme } from './types';
import THEME_ID from './identifier';
import { defaultConfig } from '../InitColorSchemeScript/InitColorSchemeScript';

const {
CssVarsProvider,
useColorScheme,
getInitColorSchemeScript: deprecatedGetInitColorSchemeScript,
} = createCssVarsProvider<SupportedColorScheme, typeof THEME_ID>({
const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssVarsProvider<
SupportedColorScheme,
typeof THEME_ID
>({
themeId: THEME_ID,
theme: defaultTheme,
attribute: defaultConfig.attribute,
Expand All @@ -25,22 +24,4 @@ const {
},
});

let warnedInitScriptOnce = false;

const getInitColorSchemeScript: typeof deprecatedGetInitColorSchemeScript = (params) => {
if (!warnedInitScriptOnce) {
console.warn(
[
'MUI: The getInitColorSchemeScript function has been deprecated.',
'',
"You should use `import InitColorSchemeScript from '@mui/joy/InitColorSchemeScript'`",
'and replace the function call with `<InitColorSchemeScript />` instead.',
].join('\n'),
);

warnedInitScriptOnce = true;
}
return deprecatedGetInitColorSchemeScript(params);
};

export { CssVarsProvider, useColorScheme, getInitColorSchemeScript };
28 changes: 4 additions & 24 deletions packages/mui-material/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import { defaultConfig } from '../InitColorSchemeScript/InitColorSchemeScript';

const defaultTheme = experimental_extendTheme();

const {
CssVarsProvider,
useColorScheme,
getInitColorSchemeScript: deprecatedGetInitColorSchemeScript,
} = createCssVarsProvider<SupportedColorScheme, typeof THEME_ID>({
const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssVarsProvider<
Copy link
Member

Choose a reason for hiding this comment

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

We should add the @deprecated tag to getInitColorSchemeScript to hint at it in IDEs

Copy link
Member

Choose a reason for hiding this comment

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

Also suggested here: #42247 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

SupportedColorScheme,
typeof THEME_ID
>({
themeId: THEME_ID,
theme: defaultTheme,
attribute: defaultConfig.attribute,
Expand All @@ -45,25 +44,6 @@ const {
excludeVariablesFromRoot,
});

let warnedInitScriptOnce = false;

// TODO: remove in v7
const getInitColorSchemeScript: typeof deprecatedGetInitColorSchemeScript = (params) => {
if (!warnedInitScriptOnce) {
console.warn(
[
'MUI: The getInitColorSchemeScript function has been deprecated.',
'',
"You should use `import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'`",
'and replace the function call with `<InitColorSchemeScript />` instead.',
].join('\n'),
);

warnedInitScriptOnce = true;
}
return deprecatedGetInitColorSchemeScript(params);
};

export {
useColorScheme,
getInitColorSchemeScript,
Expand Down
Loading