-
-
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
[docs-infra] Fix dark/light mode #39077
base: v5.x
Are you sure you want to change the base?
Conversation
Netlify deploy previewhttps://deploy-preview-39077--material-ui.netlify.app/ Bundle size report |
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.
What I can notice
MarkdownDocsV2
should be handled too.
@@ -46,10 +54,22 @@ export default function MarkdownDocs(props) { | |||
const localizedDoc = docs[userLanguage] || docs.en; | |||
|
|||
const isJoy = canonicalAs.startsWith('/joy-ui/') && !disableCssVarsProvider; |
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 we should rely on PageContext
productId to know the docs environment we are into. It's likely more idiomatic.
pageContext.productId === 'joy-ui'
@@ -46,10 +54,22 @@ export default function MarkdownDocs(props) { | |||
const localizedDoc = docs[userLanguage] || docs.en; | |||
|
|||
const isJoy = canonicalAs.startsWith('/joy-ui/') && !disableCssVarsProvider; | |||
const CssVarsProvider = isJoy ? JoyCssVarsProvider : React.Fragment; | |||
const Wrapper = isJoy ? BrandingProvider : React.Fragment; | |||
const isMui = canonicalAs.startsWith('/material-ui/') && !disableCssVarsProvider; |
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.
Not the same
const isMui = canonicalAs.startsWith('/material-ui/') && !disableCssVarsProvider; | |
const isMaterialUi = canonicalAs.startsWith('/material-ui/') && !disableCssVarsProvider; |
@@ -12,16 +19,17 @@ import BrandingProvider from 'docs/src/BrandingProvider'; | |||
import Ad from 'docs/src/modules/components/Ad'; | |||
import AdGuest from 'docs/src/modules/components/AdGuest'; | |||
|
|||
function JoyModeObserver({ mode }) { | |||
function ModeObserver({ mode, useColorScheme }) { | |||
const { setMode } = useColorScheme(); | |||
React.useEffect(() => { |
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.
A layout effect would make more sense. See the current bug:
React.useEffect(() => { | |
useEnhancedEffect(() => { |
Screen.Recording.2023-09-20.at.18.05.57.mov
But the pattern used feels wrong in the first place. I would expect that when we change the mode, to change the mode instantly, so useColorScheme
shouldn't be called here in an effect. Instead, it should be called where we set the dark/light mode. Could we try that instead?
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.
Hi @oliviertassinari ,
After trying to fix following your comment, I found bugs related to using Experimental_CssVarsProvider
of mui-material/styles. the reason is object defaultTheme
of material-ui is experimental.
So I think in the scope of this bug #38575, we should only update the attribute "data-mui-color-scheme" by using js function setAttribute. And move optimizing material-ui defaultTheme to another issue which has label customization: theme
f7913d9
to
cbc7ff3
Compare
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.
We need to fix the root
72965fa
to
c3d8bb2
Compare
The docs theming pattern needs to be restructured. I will need to create a new issue with some proposal to move forward. |
Fix #38575
Preview: https://deploy-preview-39077--material-ui.netlify.app/material-ui/experimental-api/css-theme-variables/usage/#getting-started