[POC] Use a static build-time generated CSS file as theme#48745
Draft
silviuaavram wants to merge 43 commits into
Draft
[POC] Use a static build-time generated CSS file as theme#48745silviuaavram wants to merge 43 commits into
silviuaavram wants to merge 43 commits into
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spinoff from #48652. Instead of using
CSSThemeProvider, we remove the runtime part entirely, and use CSS generated at build time, with CSS variables, to act as a theme. The changes below are partially the ones from the runtime provider PR.Changes:
Summary
Component CSS
SliderandToolbarfromstyled()arguments to CSS Modules.styled()slot shells so Emotion users retainsx,styled(), andstyleOverrides.:global(.Mui*)selectors to preserve MUI's public class names without CSS Module hashes.@media (--mui-breakpoint-up-sm).CSS Delivery
Provide two mutually exclusive component CSS paths:
Default breakpoints:
buildCssArtifacts.mtscombines component CSS Modules into@mui/material/styles.css.@mui/material/styles.cssonce.Custom breakpoints:
buildCssModulesVariant.mtsgenerates a parallel@mui/material/css-modules/*package tree.@mui/material/styles.css, as that would duplicate styles.CSS Build Tools
@mui/material-css-toolsfor build-time CSS integration.muiMaterialCssModules()to select the parallel package in Vite.muiCustomMedia({ theme })adapters for Vite/Lightning CSS and PostCSS.generateBreakpointCustomMedia()andgetBreakpointCustomMediaDefinitions()for custom bundler integrations.@media (--mui-breakpoint-up-tablet).breakpoint values.
Static Theme Generation
generateThemeCss()to serialize a CSS-variable theme into static CSS.buildDefaultThemeCss.mtsgenerates@mui/material/default-theme.css.theme.cssfrom theme options.@mui/material/styles.cssfor default breakpoints, orstyleOverridesare not serialized into the static theme.sxis ignored by the noop styling engine and emits a development warning.Theme Scoping
ThemeScopeas the DOM boundary for root and nested CSS-variable themes.ThemeProviderusesgetThemeScopeProps()to derive a scope from simple class-basedrootSelectorvalues.ThemeScopedirectly for both root and nested themes.ThemeScopeContextexposes the active class, color scheme, and color-scheme attribute.useThemeScopeProps()copies that scope onto portal roots.ScopedDialogpasses these props throughslotProps.root.Modalor a shared portalcontainer rather than requiring a consumer wrapper.
Color Scheme
useColorSchemeSetup.ThemeProvidercontinues exposing its context-backeduseColorScheme.@mui/material/colorSchemehook.first-paint mismatch.
Tailwind
@mui/tailwindwith Tailwind v3 preset/plugin and Tailwind v4 CSS integration.@mui/material-css-tools:createTailwindPreset(theme)for Tailwind v3.generateTailwindThemeCss(theme)for Tailwind v4.@mui/tailwind/v4.cssdirectly withoutpostcss-import.Sandboxes
emotion-vite-sandbox: Emotion, runtimeThemeProvider, CSS Modules, PostCSS, customsm=720px, and Tailwind v3.noop-vite-sandbox: static generated theme, noop engine, CSS Modules, Lightning CSS, customsm=720px, and Tailwind v4.noop-default-css-vite-sandbox: static generated theme, noop engine, aggregate@mui/material/styles.css, defaultsm=600px, and Tailwind v4.color-scheme switching, and Tailwind tokens.
Verification