Skip to content

Commit 9434bfd

Browse files
perf(web): default theme adoption compiles with the React Compiler (pingdotgg#20574)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 2bb92ba commit 9434bfd

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎apps/web/src/hooks/useDefaultTheme.ts‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { useAtomValue } from "@effect/atom-react";
2-
import { useEffect } from "react";
2+
import { useEffect, useSyncExternalStore } from "react";
33

44
import { primaryEnvironmentIdAtom } from "../state/primaryEnvironment";
55
import { primaryServerSettingsAtom } from "../state/server";
6-
import { getThemeDefinition, singleAppearanceOf } from "../themePalette";
7-
import { useEnvironmentThemeDefinitions } from "./useEnvironmentTheme";
6+
import { getThemeDefinition, singleAppearanceOf, subscribeToCustomThemes } from "../themePalette";
87
import { useTheme } from "./useTheme";
98

109
const APPLIED_DEFAULT_THEME_STORAGE_PREFIX = "t3code:default-theme-applied:v2:";
@@ -54,12 +53,16 @@ export function useDefaultThemeAdoption(): void {
5453
const settings = useAtomValue(primaryServerSettingsAtom);
5554
const { defaultTheme, defaultThemeSetAt } = settings;
5655
const { setTheme, setAppearanceMode } = useTheme();
57-
const environmentThemes = useEnvironmentThemeDefinitions();
56+
// Re-read when published or custom palettes change, so a theme that resolves late still applies.
57+
const definition = useSyncExternalStore(
58+
subscribeToCustomThemes,
59+
() => getThemeDefinition(defaultTheme),
60+
() => null,
61+
);
5862

5963
useEffect(() => {
6064
if (typeof window === "undefined" || environmentId === null) return;
6165
const storageKey = `${APPLIED_DEFAULT_THEME_STORAGE_PREFIX}${environmentId}`;
62-
const definition = getThemeDefinition(defaultTheme);
6366
const generation = defaultThemeToApply({
6467
environmentId,
6568
defaultTheme,
@@ -81,12 +84,5 @@ export function useDefaultThemeAdoption(): void {
8184
// light half with no retry.
8285
if (half !== null && !setAppearanceMode(half)) return;
8386
writeAppliedGeneration(storageKey, generation);
84-
}, [
85-
environmentId,
86-
defaultTheme,
87-
defaultThemeSetAt,
88-
environmentThemes,
89-
setTheme,
90-
setAppearanceMode,
91-
]);
87+
}, [environmentId, defaultTheme, defaultThemeSetAt, definition, setTheme, setAppearanceMode]);
9288
}

0 commit comments

Comments
 (0)