Skip to content

Commit 09b9e68

Browse files
committed
fix: use proper react hook for favicon theme
I was using `useState` before, which didn't re-render on load.
1 parent 127f65c commit 09b9e68

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ export const WorkspaceReadyPage = ({
9898
...templateVersion(workspace.template_active_version_id),
9999
enabled: workspace.outdated,
100100
});
101-
const [systemTheme] = useState(() => {
102-
if (typeof window.matchMedia === "undefined") {
103-
// Default to dark mode!
104-
return "dark";
101+
const [faviconTheme, setFaviconTheme] = useState<"light" | "dark">("dark")
102+
useEffect(() => {
103+
if (typeof window === "undefined" || !window.matchMedia) {
104+
return
105105
}
106106
const isDark = window.matchMedia("(prefers-color-scheme: dark)");
107-
return isDark ? "dark" : "light";
108-
});
109-
107+
setFaviconTheme(isDark ? "dark" : "light")
108+
}, [])
110109
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id);
111110
const shouldDisplayBuildLogs =
112111
hasJobError(workspace) ||
@@ -132,12 +131,12 @@ export const WorkspaceReadyPage = ({
132131
<link
133132
rel="alternate icon"
134133
type="image/png"
135-
href={`/favicons/${favicon}-${systemTheme}.png`}
134+
href={`/favicons/${favicon}-${faviconTheme}.png`}
136135
/>
137136
<link
138137
rel="icon"
139138
type="image/svg+xml"
140-
href={`/favicons/${favicon}-${systemTheme}.svg`}
139+
href={`/favicons/${favicon}-${faviconTheme}.svg`}
141140
/>
142141
</Helmet>
143142

0 commit comments

Comments
 (0)