Skip to content

Commit 6dd6305

Browse files
committed
fix(web): wallpaper and theme CSS pass main's lint and compiler checks
The wallpaper image import moves its throwing steps out of the component so React Compiler can optimize it, the header measurement uses observeResize, the CSS editor ring stays inside its border, and the code foreground color token is declared again for the editor.
1 parent c707092 commit 6dd6305

5 files changed

Lines changed: 72 additions & 67 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,9 @@ export default function ChatView(props: ChatViewProps) {
570570
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- measures the header DOM element so wallpaper rows can scroll beneath it
571571
useLayoutEffect(() => {
572572
if (!chatHeaderElement || !hasTimelineBackground) return;
573-
const measure = () => setChatHeaderHeight(chatHeaderElement.getBoundingClientRect().height);
574-
measure();
575-
const observer = new ResizeObserver(measure);
576-
observer.observe(chatHeaderElement);
577-
return () => observer.disconnect();
573+
return observeResize(chatHeaderElement, () =>
574+
setChatHeaderHeight(chatHeaderElement.getBoundingClientRect().height),
575+
);
578576
}, [chatHeaderElement, hasTimelineBackground]);
579577
const timelineUnderHeader = hasTimelineBackground && !embedded;
580578
const timelineHeaderInset = timelineUnderHeader ? chatHeaderHeight : 0;

‎apps/web/src/components/settings/ThemeCssEditor.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ThemeCssEditor({
7575

7676
return (
7777
<div className="space-y-2">
78-
<div className="overflow-hidden rounded-lg border border-input bg-code text-code-foreground focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/24">
78+
<div className="overflow-hidden rounded-lg border border-input bg-code text-code-foreground focus-within:border-ring focus-within:ring-3 focus-within:ring-inset focus-within:ring-ring/24">
7979
<textarea
8080
aria-label="Custom CSS"
8181
aria-describedby={hintId}

‎apps/web/src/components/settings/TimelineBackgroundSettings.tsx‎

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
2525

2626
const MAX_BLUR = 30;
2727

28+
async function resolveWallpaperImage(source: string | File): Promise<string> {
29+
let nextImage: string;
30+
if (typeof source === "string") {
31+
const parsed = new URL(source.trim());
32+
if (!["https:", "http:"].includes(parsed.protocol)) {
33+
throw new Error("Use an http or https image URL, or choose a local file.");
34+
}
35+
nextImage = parsed.href;
36+
} else {
37+
const result = await compressImageForWallpaper(source);
38+
if (!result.ok) {
39+
throw new Error(
40+
result.reason === "too-large"
41+
? "Choose an image no larger than 50 MB and 64 megapixels."
42+
: "Could not read this image. Choose a PNG, JPEG, GIF, or WebP file.",
43+
);
44+
}
45+
nextImage = result.image.dataUrl;
46+
}
47+
await new Promise<void>((resolve, reject) => {
48+
const probe = new Image();
49+
const timeout = window.setTimeout(() => finish(false), 15000);
50+
function finish(loaded: boolean) {
51+
window.clearTimeout(timeout);
52+
probe.removeEventListener("load", onLoad);
53+
probe.removeEventListener("error", onError);
54+
if (loaded) resolve();
55+
else reject(new Error("Could not load this image. Check the URL or choose another file."));
56+
}
57+
const onLoad = () => finish(true);
58+
const onError = () => finish(false);
59+
probe.addEventListener("load", onLoad);
60+
probe.addEventListener("error", onError);
61+
probe.src = nextImage;
62+
});
63+
return nextImage;
64+
}
65+
66+
function wallpaperErrorMessage(cause: unknown): string {
67+
if (cause instanceof TypeError) return "Enter a full image URL, or choose a local file.";
68+
return cause instanceof Error ? cause.message : "Could not load this image.";
69+
}
70+
2871
export function TimelineBackgroundSettings() {
2972
const image = useClientSettings((settings) => settings.timelineBackgroundImage);
3073
const opacity = useClientSettings((settings) => settings.timelineBackgroundOpacity);
@@ -71,6 +114,7 @@ export function TimelineBackgroundSettings() {
71114
if (value !== shadowBlur) updateSettings({ timelineTextShadowBlur: value });
72115
}
73116

117+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- invalidates an in-flight image import on unmount so it cannot write settings afterwards
74118
useEffect(
75119
() => () => {
76120
request.current++;
@@ -82,68 +126,28 @@ export function TimelineBackgroundSettings() {
82126
const generation = ++request.current;
83127
setBusy(true);
84128
setError("");
85-
try {
86-
let nextImage: string;
87-
if (typeof source === "string") {
88-
const parsed = new URL(source.trim());
89-
if (!["https:", "http:"].includes(parsed.protocol)) {
90-
throw new Error("Use an http or https image URL, or choose a local file.");
91-
}
92-
nextImage = parsed.href;
93-
} else {
94-
const result = await compressImageForWallpaper(source);
95-
if (!result.ok) {
96-
throw new Error(
97-
result.reason === "too-large"
98-
? "Choose an image no larger than 50 MB and 64 megapixels."
99-
: "Could not read this image. Choose a PNG, JPEG, GIF, or WebP file.",
100-
);
101-
}
102-
nextImage = result.image.dataUrl;
103-
}
104-
if (generation !== request.current) return;
105-
await new Promise<void>((resolve, reject) => {
106-
const probe = new Image();
107-
const timeout = window.setTimeout(() => finish(false), 15000);
108-
function finish(loaded: boolean) {
109-
window.clearTimeout(timeout);
110-
probe.removeEventListener("load", onLoad);
111-
probe.removeEventListener("error", onError);
112-
if (loaded) resolve();
113-
else
114-
reject(new Error("Could not load this image. Check the URL or choose another file."));
115-
}
116-
const onLoad = () => finish(true);
117-
const onError = () => finish(false);
118-
probe.addEventListener("load", onLoad);
119-
probe.addEventListener("error", onError);
120-
probe.src = nextImage;
121-
});
122-
if (generation !== request.current) return;
123-
try {
124-
await persistClientSettingsUpdate((current) =>
125-
generation === request.current
126-
? { ...current, timelineBackgroundImage: nextImage }
127-
: current,
128-
);
129-
} catch {
130-
throw new Error(
131-
"Could not save this image. Client storage may be full. Try a smaller image.",
132-
);
133-
}
134-
} catch (cause) {
135-
if (generation === request.current) {
136-
setError(
137-
cause instanceof TypeError
138-
? "Enter a full image URL, or choose a local file."
139-
: cause instanceof Error
140-
? cause.message
141-
: "Could not load this image.",
142-
);
143-
}
144-
} finally {
145-
if (generation === request.current) setBusy(false);
129+
const resolved = await resolveWallpaperImage(source).then(
130+
(nextImage) => ({ nextImage, error: null }),
131+
(cause: unknown) => ({ nextImage: null, error: wallpaperErrorMessage(cause) }),
132+
);
133+
if (generation !== request.current) return;
134+
const { nextImage } = resolved;
135+
if (nextImage === null) {
136+
setError(resolved.error);
137+
setBusy(false);
138+
return;
146139
}
140+
const saved = await persistClientSettingsUpdate((current) =>
141+
generation === request.current ? { ...current, timelineBackgroundImage: nextImage } : current,
142+
).then(
143+
() => true,
144+
() => false,
145+
);
146+
if (generation !== request.current) return;
147+
if (!saved) {
148+
setError("Could not save this image. Client storage may be full. Try a smaller image.");
149+
}
150+
setBusy(false);
147151
}
148152

149153
function removeImage() {

‎apps/web/src/index.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
276276
--color-card-foreground: var(--contrast-card-foreground);
277277
--color-card: var(--card);
278278
--color-code: var(--code-background);
279+
--color-code-foreground: var(--code-foreground);
279280
--color-foreground: var(--contrast-foreground);
280281
--color-background: var(--background);
281282
--color-message: var(--message-surface);

‎apps/web/src/themePalette.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,9 @@ describe("context chip colors", () => {
666666
const properties = new Map<string, string>();
667667
vi.stubGlobal("window", { localStorage: { getItem: () => null } });
668668
vi.stubGlobal("document", {
669+
querySelector: () => null,
669670
documentElement: {
671+
classList: { toggle: vi.fn() },
670672
dataset: {},
671673
style: {
672674
setProperty: (name: string, value: string) => properties.set(name, value),

0 commit comments

Comments
 (0)