-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
[system] Missing quotes in InitColorSchemeScript.tsx
#43416
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
Comments
InitColorSchemeScript.tsx
InitColorSchemeScript.tsx
I think this is not a bug (may be a documentation improvement). You missed the single quote -<InitColorSchemeScript attribute="[data-color-scheme=%s]" />
+<InitColorSchemeScript attribute="[data-color-scheme='%s']" /> |
+1 for solving this using the docs, I didn't find one in https://next.mui.com/material-ui/customization/css-theme-variables/configuration/. Also there seems that we are missing the API page for the @siriwatknp This isn't valid JavaScript though, it crashes, maybe there should be a defensive logic. ![]() (function() {
try {
var mode = localStorage.getItem('mui-mode') || 'system';
var colorScheme = '';
var dark = localStorage.getItem('mui-color-scheme-dark') || 'dark';
var light = localStorage.getItem('mui-color-scheme-light') || 'light';
if (mode === 'system') {
// handle system mode
var mql = window.matchMedia('(prefers-color-scheme: dark)');
if (mql.matches) {
colorScheme = dark
} else {
colorScheme = light
}
}
if (mode === 'light') {
colorScheme = light;
}
if (mode === 'dark') {
colorScheme = dark;
}
if (colorScheme) {
document.documentElement.setAttribute('data-color-scheme'.replace('%s', colorScheme), %s.replace('%s', colorScheme));
}
} catch(e){}})(); |
Ah okay. I was going off of the comment on this line: material-ui/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx Line 73 in 9f4b846
Also, @oliviertassinari it is mentioned in the docs page you linked, you just have to click on the little tabs here: ![]() But yeah it took me quite a while before I found that. It would be nice if the docs around |
@brandongit2 Oh, I couldn't find it, thanks. So if we summarily the next step, it looks like solving this issue is about the docs:
diff --git a/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx b/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx
index 7320bb7c10..c0f6eca59f 100644
--- a/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx
+++ b/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx
@@ -70,7 +70,7 @@ export default function InitColorSchemeScript(options?: InitColorSchemeScriptPro
setter += `${colorSchemeNode}.classList.remove('${selector}'.replace('%s', light), '${selector}'.replace('%s', dark));
${colorSchemeNode}.classList.add('${selector}'.replace('%s', colorScheme));`;
}
- const matches = attribute.match(/\[([^\]]+)\]/); // case [data-color-scheme=%s] or [data-color-scheme]
+ const matches = attribute.match(/\[([^\]]+)\]/); // case [data-color-scheme='%s'] or [data-color-scheme]
if (matches) {
const [attr, value] = matches[1].split('=');
if (!value) {
|
InitColorSchemeScript.tsx
InitColorSchemeScript.tsx
Steps to reproduce
Link to live example: https://stackblitz.com/edit/github-xk9wmf?file=src%2FApp.tsx
Steps:
<script>
tag under<div id="app">
. You should see that on the second-last line of the script, there is a bare%s
with no quotes around it. This throws aSyntaxError
in my browser.Current behavior
No response
Expected behavior
No response
Context
material-ui/packages/mui-system/src/InitColorSchemeScript/InitColorSchemeScript.tsx
Line 81 in 9f4b846
needs to have quotes around
${value}
.Your environment
System:
OS: macOS 14.6.1
Binaries:
Node: 18.19.1 - ~/.asdf/installs/nodejs/18.19.1/bin/node
npm: 10.2.4 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 9.7.1 - ~/.asdf/installs/nodejs/18.19.1/bin/pnpm
Browsers:
Chrome: 127.0.6533.120
Edge: Not Found
Safari: 17.6
npmPackages:
@emotion/react: 11.13.3 => 11.13.3
@emotion/styled: 11.13.0 => 11.13.0
@mui/icons-material: 6.0.0-rc.0 => 6.0.0-rc.0
@mui/lab: 6.0.0-beta.7 => 6.0.0-beta.7
@mui/material: 6.0.0-rc.0 => 6.0.0-rc.0
@mui/system: 6.0.0-rc.0 => 6.0.0-rc.0
@mui/x-data-grid: 7.14.0 => 7.14.0
@mui/x-date-pickers: 7.14.0 => 7.14.0
@mui/x-tree-view: 7.14.0 => 7.14.0
@types/react: 18.3.4 => 18.3.4
react: 18.3.1 => 18.3.1
react-dom: 18.3.1 => 18.3.1
typescript: ^5.2.2 => 5.3.2
Search keywords: css variables, InitColorSchemeScript, %s
The text was updated successfully, but these errors were encountered: