-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Add InitColorSchemeScript
for Next.js App Router
#42247
Merged
siriwatknp
merged 25 commits into
mui:next
from
siriwatknp:feat/init-color-scheme-component
Jun 14, 2024
Merged
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
82d7240
add InitColorSchemeScript
siriwatknp 38de969
Revert "add InitColorSchemeScript"
siriwatknp c2ce63d
Revert "Revert "add InitColorSchemeScript""
siriwatknp f876485
Merge branch 'next' of https://github.com/mui/material-ui into feat/i…
siriwatknp 8006268
Merge branch 'next' of https://github.com/mui/material-ui into feat/i…
siriwatknp e18a6d0
reexport InitColorSchemeScript as component
siriwatknp 10683e6
add test
siriwatknp 394b59e
update docs
siriwatknp 1ef5f65
spec
siriwatknp bef0a77
add nonce type
siriwatknp 9582d24
ignore CssVarsProvider from rsc
siriwatknp 285b3cc
Merge branch 'next' of https://github.com/mui/material-ui into feat/i…
siriwatknp 8fa07a0
split InitColorSchemeScript
siriwatknp 34eab69
fix path
siriwatknp d480e9c
fix ignore path
siriwatknp 00129fe
fix lint
siriwatknp 334d09e
update docs
siriwatknp d3859a0
add InitColorSchemeScript to joy
siriwatknp 92493b2
use InitColorSchemeScript in docs
siriwatknp 3256350
update docs
siriwatknp 2471c88
fix joy rsc ignore
siriwatknp 52dddfd
trigger build
siriwatknp 1b3cd47
Merge branch 'next' of https://github.com/mui/material-ui into feat/i…
siriwatknp c11fb6b
skip demo for InitColorSchemeScript
siriwatknp 0e38328
pnpm install
siriwatknp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
4 changes: 4 additions & 0 deletions
4
packages/mui-material/src/InitColorSchemeScript/InitColorSchemeScript.spec.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as React from 'react'; | ||
import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'; | ||
|
||
<InitColorSchemeScript nonce="foo-bar" />; |
13 changes: 13 additions & 0 deletions
13
packages/mui-material/src/InitColorSchemeScript/InitColorSchemeScript.test.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { createRenderer } from '@mui/internal-test-utils'; | ||
import InitColorSchemeScript from '@mui/material/InitColorSchemeScript'; | ||
|
||
describe('InitColorSchemeScript', () => { | ||
const { render } = createRenderer(); | ||
|
||
it('should render as expected', () => { | ||
const { container } = render(<InitColorSchemeScript />); | ||
expect(container.firstChild).to.have.tagName('script'); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { InitColorSchemeScript as default } from '../styles/CssVarsProvider'; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ export interface GetInitColorSchemeScriptOptions { | |
* @default 'data-color-scheme' | ||
*/ | ||
attribute?: string; | ||
/** Nonce string to pass to the inline script for CSP headers */ | ||
nonce?: string | undefined; | ||
} | ||
|
||
export default function getInitColorSchemeScript(options?: GetInitColorSchemeScriptOptions) { | ||
|
@@ -51,10 +53,13 @@ export default function getInitColorSchemeScript(options?: GetInitColorSchemeScr | |
colorSchemeStorageKey = DEFAULT_COLOR_SCHEME_STORAGE_KEY, | ||
attribute = DEFAULT_ATTRIBUTE, | ||
colorSchemeNode = 'document.documentElement', | ||
nonce, | ||
} = options || {}; | ||
return ( | ||
<script | ||
key="mui-color-scheme-init" | ||
suppressHydrationWarning | ||
nonce={typeof window === 'undefined' ? nonce : ''} | ||
Comment on lines
+66
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={{ | ||
__html: `(function() { | ||
|
This file contains 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
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.
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.
Should we deprecate
getInitColorSchemeScript
? Or do we expect users to still use it?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.
Good point. I think it can be removed but I'd do it in a separate PR and add note to the migration doc in the same PR.