Skip to content

fix: use proper react hook for favicon theme #10094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
17 changes: 8 additions & 9 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ export const WorkspaceReadyPage = ({
...templateVersion(workspace.template_active_version_id),
enabled: workspace.outdated,
});
const [systemTheme] = useState(() => {
if (typeof window.matchMedia === "undefined") {
// Default to dark mode!
return "dark";
const [faviconTheme, setFaviconTheme] = useState<"light" | "dark">("dark");
useEffect(() => {
if (typeof window === "undefined" || !window.matchMedia) {
return;
}
const isDark = window.matchMedia("(prefers-color-scheme: dark)");
return isDark ? "dark" : "light";
});

setFaviconTheme(isDark ? "dark" : "light");
}, []);
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id);
const shouldDisplayBuildLogs =
hasJobError(workspace) ||
Expand All @@ -132,12 +131,12 @@ export const WorkspaceReadyPage = ({
<link
rel="alternate icon"
type="image/png"
href={`/favicons/${favicon}-${systemTheme}.png`}
href={`/favicons/${favicon}-${faviconTheme}.png`}
/>
<link
rel="icon"
type="image/svg+xml"
href={`/favicons/${favicon}-${systemTheme}.svg`}
href={`/favicons/${favicon}-${faviconTheme}.svg`}
/>
</Helmet>

Expand Down