-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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] Add warning when using noSsr
incorrectly
#44624
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy previewhttps://deploy-preview-44624--material-ui.netlify.app/ Bundle size report |
noSsr
incorrectlynoSsr
incorrectly
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 think this is more accurate:
MUI: The
noSsr
prop must be used withcssVariables: true
.
As that's the provider that supports the noSsr
prop.
console.error( | ||
[ | ||
'MUI: The `noSsr` prop must be used with the theme that contains light and dark colorSchemes.', | ||
'See https://mui.com/material-ui/customization/dark-mode/#built-in-support for more details.', |
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.
Same feedback as in #43783 (comment).
export default function ThemeProviderNoVars<Theme = DefaultTheme>({ | ||
theme: themeInput, | ||
...props | ||
}: ThemeProviderNoVarsProps<Theme>): React.ReactElement<ThemeProviderNoVarsProps<Theme>> { | ||
const scopedTheme = THEME_ID in themeInput ? themeInput[THEME_ID] : undefined; | ||
if (process.env.NODE_ENV !== 'production') { | ||
// @ts-ignore | ||
if (process.env.NODE_ENV !== 'test' && props.noSsr && !warnedOnceNoSsr) { |
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.
The test env check seems suspicious. Do we have leaks in our own tests?
if (process.env.NODE_ENV !== 'test' && props.noSsr && !warnedOnceNoSsr) { | |
if (props.noSsr && !warnedOnceNoSsr) { |
export default function ThemeProviderNoVars<Theme = DefaultTheme>({ | ||
theme: themeInput, | ||
...props | ||
}: ThemeProviderNoVarsProps<Theme>): React.ReactElement<ThemeProviderNoVarsProps<Theme>> { | ||
const scopedTheme = THEME_ID in themeInput ? themeInput[THEME_ID] : undefined; | ||
if (process.env.NODE_ENV !== 'production') { |
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.
Would it make sense to run this test inside ThemeProvider.tsx
rather than in this file? It seems that it could be easier to refactor down the line.
closes #44576