+
+ ### Avoiding Dark Mode Flicker
+
+ Applications that support dark mode may briefly render the default colour scheme before the user's preferred mode is applied.
+
+ #### SSR Applications
+
+ To prevent a flash of incorrect theme in SSR applications, use MUI's `InitColorSchemeScript` and place it before your application content so the correct colour scheme is applied before hydration.
+ For example, for Next.js App Router:
+ ```tsx filename="layout.tsx"
+ import InitColorSchemeScript from '@mui/material/InitColorSchemeScript';
+
+ export default function RootLayout(props: { children: React.ReactNode }) {
+ return (
+
+
+
+ {props.children}
+
+
+ );
+ }
+ ```
+ If your app renders into `index.html`, place the script at the top of the body so the mode is set before React mounts.
+ For more info see MUI's documentation on [InitColorSchemeScript](https://v7.mui.com/material-ui/react-init-color-scheme-script/).
+
+ #### Client-Side Applications (Vite etc.)
+
+ For client-side applications, initialise the mode before React mounts:
+ ```
+
+
+
+
+
+ ```
+
+ This ensures the correct DiamondDS token set is applied before the first paint, avoiding a flash of the default colour scheme when a saved preference exists.
+
+ DiamondDS uses:
+ ```
+
+ ```
+ or
+ ```
+
+ ```
+ and should be configured with
+ ```
+ colorSchemeSelector: '[data-mode="%s"]'
+ ```