Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
content="width=device-width, initial-scale=1.0, viewport-fit=cover, interactive-widget=resizes-content"
/>
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#161616" media="(prefers-color-scheme: dark)" />
<meta name="theme-color" content="#161616" />
<meta name="theme-color" content="#0a0a0a" media="(prefers-color-scheme: dark)" />
<meta name="theme-color" content="#0a0a0a" />
<link rel="icon" href="/favicon.ico" sizes="48x48" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<script>
(() => {
const LIGHT_BACKGROUND = "#ffffff";
const DARK_BACKGROUND = "#161616";
const DARK_BACKGROUND = "#0a0a0a";
const themeColorMeta = document.querySelector('meta[name="theme-color"]');
try {
const storedTheme = window.localStorage.getItem("t3code:theme");
Expand Down Expand Up @@ -58,7 +58,7 @@
}

html.dark body {
background: #161616;
background: #0a0a0a;
color: #f5f5f5;
}

Expand Down
15 changes: 4 additions & 11 deletions apps/web/src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_THEME_SNAPSHOT: ThemeSnapshot = {
};
const THEME_COLOR_META_NAME = "theme-color";
const DYNAMIC_THEME_COLOR_SELECTOR = `meta[name="${THEME_COLOR_META_NAME}"][data-dynamic-theme-color="true"]`;
const APP_CHROME_BACKGROUND_PROPERTY = "--app-chrome-background";

export class ThemeStorageError extends Schema.TaggedErrorClass<ThemeStorageError>()(
"ThemeStorageError",
Expand Down Expand Up @@ -151,21 +152,13 @@ function normalizeThemeColor(value: string | null | undefined): string | null {
return value?.trim() ?? null;
}

function resolveBrowserChromeSurface(): HTMLElement {
return (
document.querySelector<HTMLElement>("main[data-slot='sidebar-inset']") ??
document.querySelector<HTMLElement>("[data-slot='sidebar-inner']") ??
document.body
);
}

export function syncBrowserChromeTheme() {
if (typeof document === "undefined" || typeof getComputedStyle === "undefined") return;
const surfaceColor = normalizeThemeColor(
getComputedStyle(resolveBrowserChromeSurface()).backgroundColor,
const appChromeColor = normalizeThemeColor(
getComputedStyle(document.documentElement).getPropertyValue(APP_CHROME_BACKGROUND_PROPERTY),
);
const fallbackColor = normalizeThemeColor(getComputedStyle(document.body).backgroundColor);
const backgroundColor = surfaceColor ?? fallbackColor;
const backgroundColor = appChromeColor ?? fallbackColor;
if (!backgroundColor) return;

document.documentElement.style.backgroundColor = backgroundColor;
Expand Down
Loading