Skip to content
TypeScript

perf(web): the font picker compiles with the React Compiler (#20594)

Julius Marminge855cd1650c73
diff --git a/apps/web/src/components/settings/FontFamilyPicker.tsx b/apps/web/src/components/settings/FontFamilyPicker.tsx
index 73faa75bb87..fb871af826b 100644
--- a/apps/web/src/components/settings/FontFamilyPicker.tsx
+++ b/apps/web/src/components/settings/FontFamilyPicker.tsx
@@ -1,6 +1,6 @@
import { LegendList, type LegendListRef } from "@legendapp/list/react";
import { CheckIcon } from "lucide-react";
-import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
+import { useEffect, useRef, useState, useSyncExternalStore } from "react";
import { isMonospaceFamily, queryInstalledFontFamilies } from "../../appearanceFonts";
import {
Combobox,
@@ -103,9 +103,11 @@ export function FontFamilyPicker({
// its open state never receives Base UI's entrance style baseline, so the
// exit transition on close has no style delta, never fires transitionend,
// and the popup lingers on screen forever.
+ const [openAfterMount] = useState(initialOpen);
useEffect(() => {
- if (initialOpen) setOpen(true);
- }, []);
+ // oxlint-disable-next-line react/set-state-in-effect -- Base UI needs one closed commit first to record the popup's entrance style.
+ if (openAfterMount) setOpen(true);
+ }, [openAfterMount]);
const listRef = useRef<LegendListRef | null>(null);
const enumeration = useFontEnumeration();
@@ -114,12 +116,9 @@ export function FontFamilyPicker({
if (nextOpen) setQuery("");
};
- const families = useMemo(() => {
- if (enumeration.status !== "granted") return [];
- return enumeration.families;
- }, [enumeration]);
+ const families = enumeration.status === "granted" ? enumeration.families : [];
- const items = useMemo(() => {
+ const items = (() => {
const trimmedQuery = query.trim().toLowerCase();
const result: string[] = [];
if (trimmedQuery.length === 0) result.push(DEFAULT_FONT_VALUE);
@@ -129,7 +128,7 @@ export function FontFamilyPicker({
),
);
return result;
- }, [query, families]);
+ })();
const selectedValue = selectedFamily.length === 0 ? DEFAULT_FONT_VALUE : selectedFamily;