You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/joy/customization/dark-mode/dark-mode.md
+31-7
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,10 @@ When you change the `defaultMode` to another value, you must clear the local sto
12
12
13
13
{{"demo": "DarkModeByDefault.js"}}
14
14
15
-
For server-side applications, check out the framework setup in [the section below](#server-side-rendering) and provide the same value to the `getInitColorSchemeScript` function:
15
+
For server-side applications, check out the framework setup in [the section below](#server-side-rendering) and provide the same value to the `InitColorSchemeScript` component:
16
16
17
17
```js
18
-
getInitColorSchemeScript({ defaultMode:'dark' });
18
+
<InitColorSchemeScript defaultMode="dark"/>
19
19
```
20
20
21
21
## Matching device's preference
@@ -28,10 +28,10 @@ import { CssVarsProvider } from '@mui/joy/styles';
For server-side applications, check out the framework setup in [the section below](#server-side-rendering) and provide the same value to the `getInitColorSchemeScript` function:
31
+
For server-side applications, check out the framework setup in [the section below](#server-side-rendering) and provide the same value to the `InitColorSchemeScript` component:
@@ -121,23 +121,47 @@ If you try to render your UI based on the server, before mounting on the client,
121
121
122
122
### Avoiding screen flickering
123
123
124
-
To [prevent the UI from flickering](/joy-ui/main-features/dark-mode-optimization/#the-problem-flickering-on-first-load), apply `getInitColorSchemeScript()` before the main application script-it varies across frameworks:
124
+
To [prevent the UI from flickering](/joy-ui/main-features/dark-mode-optimization/#the-problem-flickering-on-first-load), apply `<InitColorSchemeScript />` before the main application script-it varies across frameworks:
125
+
126
+
### Next.js App Router
127
+
128
+
To use the Joy UI API with a Next.js project with the App Router, add the following code to the [`app/layout.js`](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#layouts) file in order to prevent flickering:
To use the Joy UI API with a Next.js project, add the following code to the custom [`pages/_document.js`](https://nextjs.org/docs/pages/building-your-application/routing/custom-document) file:
Copy file name to clipboardExpand all lines: docs/data/joy/main-features/dark-mode-optimization/dark-mode-optimization.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -27,22 +27,22 @@ Solving this problem required us to take a novel approach to styling and theming
27
27
28
28
Thanks to Joy UI's built-in support for CSS variables, your app can render all of its color schemes at build time, so that the user's preference can be injected _before_ the DOM is rendered in the browser.
29
29
30
-
Joy UI provides the `getInitColorSchemeScript()` function to make this flash-free dark mode possible with React frameworks like Next.js or Remix.
30
+
Joy UI provides the `InitColorSchemeScript` component to make this flash-free dark mode possible with React frameworks like Next.js or Remix.
31
31
This function must be placed before the main script so it can apply the correct stylesheet before your components are rendered.
32
32
33
33
The code snippet below shows how this works with the Next.js Pages Router:
Copy file name to clipboardExpand all lines: docs/data/material/experimental-api/css-theme-variables/customization.md
+2-4
Original file line number
Diff line number
Diff line change
@@ -289,12 +289,10 @@ function App() {
289
289
}
290
290
```
291
291
292
-
For a server-side application, provide the same value to [`getInitColorSchemeScript()`](/material-ui/experimental-api/css-theme-variables/usage/#server-side-rendering):
292
+
For a server-side application, provide the same value to [`InitColorSchemeScript`](/material-ui/customization/css-theme-variables/usage/#server-side-rendering):
Copy file name to clipboardExpand all lines: docs/data/material/experimental-api/css-theme-variables/usage/usage.md
+26-8
Original file line number
Diff line number
Diff line change
@@ -116,23 +116,42 @@ The structure of this object is nearly identical to the theme structure, the onl
116
116
117
117
## Server-side rendering
118
118
119
-
Place `getInitColorSchemeScript()` before the `<Main />` tag to prevent the dark-mode SSR flickering during the hydration phase.
119
+
Place `<InitColorSchemeScript />` before the `<Main />` tag to prevent the dark-mode SSR flickering during the hydration phase.
120
+
121
+
### Next.js App Router
122
+
123
+
Add the following code to the [root layout](https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#root-layout-required) file:
-`setMode: mode => {…}` - Function for setting the `mode`. The `mode` is saved to internal state and local storage; if `mode` is null, it will be reset to the default mode
Copy file name to clipboardExpand all lines: docs/pages/blog/first-look-at-joy.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -93,20 +93,20 @@ You're still able to override the style completely via the usual CSS overrides,
93
93
Joy UI provides an effective way to prevent UI flicker when users refresh or re-enter a page with dark mode enabled.
94
94
The out-of-the-box CSS variables support allows every color scheme to be rendered at build time, inserting the selected color scheme and mode before the browser renders the DOM.
95
95
96
-
What's more, it provides a function called `getInitColorSchemeScript()` that enables you to have perfect functioning dark mode in various React frameworks, such as Next.js, Gatsby, and Remix.
96
+
What's more, it provides a component called `InitColorSchemeScript` that enables you to have perfect functioning dark mode in various React frameworks, such as Next.js, Gatsby, and Remix.
0 commit comments