mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 23:27:55 -05:00
Fix theme inject warning
This commit is contained in:
@@ -14,6 +14,22 @@
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="theme-color" content="#010115" />
|
||||
%sveltekit.head%
|
||||
<script>
|
||||
(() => {
|
||||
const cl = document.documentElement.classList;
|
||||
if (cl.contains("light") || cl.contains("dark")) return;
|
||||
|
||||
const theme = window.matchMedia("(prefers-color-scheme: light)").matches
|
||||
? "light"
|
||||
: "dark";
|
||||
cl.add(theme);
|
||||
|
||||
const meta = document.querySelector("meta[name=color-scheme]");
|
||||
if (meta) {
|
||||
meta.content = theme === "dark" ? "dark light" : "light dark";
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
%sveltekit.body%
|
||||
|
||||
@@ -8,34 +8,13 @@ interface Props {
|
||||
|
||||
let { theme }: Props = $props();
|
||||
|
||||
// when following the system theme the blocking script in app.html corrects
|
||||
// this before first paint
|
||||
const metaColorScheme = $derived(
|
||||
theme === "light" ? "light dark" : "dark light",
|
||||
);
|
||||
|
||||
// applied before first paint when no explicit theme is set, so the page
|
||||
// never flashes the wrong theme; the html class is otherwise SSR'd
|
||||
const CLIENT_THEME_SCRIPT = `
|
||||
;(() => {
|
||||
const theme = window.matchMedia("(prefers-color-scheme: light)").matches
|
||||
? 'light'
|
||||
: 'dark';
|
||||
const cl = document.documentElement.classList;
|
||||
const themeAlreadyApplied = cl.contains('light') || cl.contains('dark');
|
||||
if (!themeAlreadyApplied) {
|
||||
cl.add(theme);
|
||||
}
|
||||
const meta = document.querySelector('meta[name=color-scheme]');
|
||||
if (meta) {
|
||||
meta.content = theme === 'dark' ? 'dark light' : 'light dark';
|
||||
}
|
||||
})();
|
||||
`;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta name="color-scheme" content={metaColorScheme} />
|
||||
{#if theme === null}
|
||||
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
||||
{@html `<script>${CLIENT_THEME_SCRIPT}</script>`}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
Reference in New Issue
Block a user