[POC] Use a static build-time generated CSS file as theme#48745
Draft
silviuaavram wants to merge 41 commits into
Draft
[POC] Use a static build-time generated CSS file as theme#48745silviuaavram wants to merge 41 commits into
silviuaavram wants to merge 41 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:
@mui/tailwindpackage.docs/data/material/integrations/tailwindcss/tailwindcss-components.md.postcss-importanymore, as it also broke the import from @mui/tailwind.SliderandToolbarto use css files instead of using styled arguments.Toolbaralso has custom breakpoints inside the css file, with variables that should be replaced at build.buildCssArtifacts.mts@mui/material/components.css.components-source.cssand use a transpiler to change the custom breakpoint variables with actual values. In our PoC, I used thevite.configdirectly, viaresolveMuiCustomMedia.@mui/styled-engine-noopand use it in non-emotion vite appsgenerateThemeCsstakes the theme and generates the CSS based on the values in the theme object.buildDefaultThemeCss.mtscreates the actual css file, in @mui/material using the defaults, could be imported directly if user wants MUI theme.buildThemeCss.mtsis the consumer equivalent, that builds the same css file, but with the user's theme, check out the dedicated Vite app.ThemeScopeto create a wrapping div element with aclassNameandcolorSchemeAttributethat are used by the theme to apply the nested values for the css variables.ThemeScopeContextto passclassName,colorSchemeAttributeandcolorSchemeto portal elements. In this PoC I'm using a ScopedDialog to show to the final version will look like in our portal components.className,colorSchemeAttributeandcolorSchemethrough a helper functiongetThemeScopePropsthat ThemeProvider uses to get those props from the theme objects.ThemeProviderandstatic theme, as well as 2 experiments in the docs app (css + emotion)useColorSchemesupport for both examplesuseColorSchemeis now abstracted inuseColorSchemeSetup.sx,styleOverridesandstyletag to changeSlider.sxwill not do anything apart from showing a console warning.styleOverrideson the theme object won't work, since there's no Emotion to parse them into styles.Toolbarimported, custom breakpoints override in the themes, so you can check the custom breakpoints.Testing:
style-noopin the case of CssThemeProvider, runpnpm -F @mui-internal/noop-vite-sandbox devandpnpm -F @mui-internal/emotion-vite-sandbox dev. Check the links provided by the commands.pnpm -F @mui-internal/emotion-vite-sandbox buildandpnpm -F @mui-internal/noop-vite-sandbox build.