--mui-* css vars are undefined when augmented theme contains property with URL value
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start with the linked StackBlitz example in src/App.tsx and reproduce the failure with cssVariables enabled and URL-valued theme properties. Trace the theme CSS-variable generation used by createTheme, then add or update a focused regression test for URL values. Done means MUI components remain styled and the generated --mui-* variables are defined, or a helpful error is reported.
Written by the indexing model from the issue text.
Description
Steps to reproduce
While attempting to adopt cssVars for an existing project, I believe I found a bug. When you augment the theme with properties, if the augmented property value contains a url (specifically the double slash), the --mui- css vars are undefined and thus the mui components are unstyled.
Steps:
- Open this link to live example: https://stackblitz.com/edit/github-r5aeyhfa?file=src%2FApp.tsx
- Notice the unstyled Buttons
- Uncomment the custom theme properties that do not contain urls.
- See properly styled buttons.
This seems to be the case in mui7 and mui9.
For the record, I am not wanting to access these values as cssVars, just via theme.propertyName.
Ideally, this either works or throws some sort of helpful error.
Here is the theme from the code example above:
const theme = createTheme({
cssVariables: true,
// Example: With Urls -> cssVars are UNdefined
// Nested attribute object with property with a url = breaks css vars
backgrounds: {
default: 'https://picsum.photos/200/300',
},
// top level attribute with a url = breaks css vaers
default_background: 'https://picsum.photos/200/300',
// EXAMPLE: W/O URLS
// Uncomment this and the cssVars are no longer undefined
// backgrounds: {
// default: 'sunset.jpg',
// },
// default_background: 'sunset.jpg',
});
Current behavior
When a theme property contains a url (specifically a "//"), the --mui-* variables are undefined.
Expected behavior
The --mui-* them properties either are defined or there is a helpful compilation error. Alternately, a way to defined theme properties without having them need to be cssVars would be cool too.
Context
Theme contains images that are different per theme. The custom theme properties defined the path to these images.
Your environment
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: cssVars, theme augmentation
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mui/material-ui
-
type: new feature waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#48254 · 3 comments · 1 reaction ·
-
has workaround scope: avatar waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mui/material-ui#48190 · 5 comments ·
-
has workaround scope: typography type: new feature waiting for 👍
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
mui/material-ui#46488 · 2 comments · 1 reaction ·
-
has workaround scope: text field type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#37216 · 6 comments ·
-
docs scope: autocomplete
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
mui/material-ui#35713 · 5 comments ·
Similar issues
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100