WFDASH-WEBAPP/src/components/theme-bootstrap.tsx

23 lines
714 B
TypeScript
Raw Normal View History

/**
* Inline script that runs in <head> before hydration.
*
* Reads the persisted theme id from localStorage and applies it to
* <html> so the user never sees a flash of the default theme.
*
* MUST stay dependency-free — it's bundled as a string and inlined.
*/
export function ThemeBootstrapScript() {
const code = `
(function() {
try {
var themeId = localStorage.getItem('wfdash-theme') || 'wfdash';
var root = document.documentElement;
root.setAttribute('data-theme', themeId);
} catch (e) {
// localStorage may be blocked — fall back to the SSR-rendered theme
}
})();
`;
return <script dangerouslySetInnerHTML={{ __html: code }} />;
}