Skip to content

Your lightweight open-source personal agent.

fix(webui): crossfade theme changes as one page (#6459)

chengyongru83b611284362
diff --git a/webui/browser/appearance.spec.ts b/webui/browser/appearance.spec.ts
index 126f249f1..744fb16ba 100644
--- a/webui/browser/appearance.spec.ts
+++ b/webui/browser/appearance.spec.ts
@@ -10,17 +10,21 @@ test("system theme stays live, explicit choices persist, and tabs agree", async
await expect(page.getByRole("radio", { name: "System", exact: true })).toBeChecked();
await page.emulateMedia({ colorScheme: "dark" });
await expect(page.locator("html")).toHaveClass(/dark/);
- await page.getByRole("radio", { name: "Light", exact: true }).check();
+ // Native theme snapshots commit the selected preference after capture.
+ await page.getByRole("radio", { name: "Light", exact: true }).click();
+ await expect(page.getByRole("radio", { name: "Light", exact: true })).toBeChecked();
await expect(page.locator("html")).not.toHaveClass(/dark/);
await page.reload();
await expect(page.getByRole("radio", { name: "Light", exact: true })).toBeChecked();
await expect(page.locator("html")).not.toHaveClass(/dark/);
- await page.getByRole("radio", { name: "System", exact: true }).check();
+ await page.getByRole("radio", { name: "System", exact: true }).click();
+ await expect(page.getByRole("radio", { name: "System", exact: true })).toBeChecked();
await expect(page.locator("html")).toHaveClass(/dark/);
const other = await context.newPage();
await other.goto("/browser/fixture.html?case=appearance");
await expect(other.getByRole("radio", { name: "System", exact: true })).toBeChecked();
- await other.getByRole("radio", { name: "Light", exact: true }).check();
+ await other.getByRole("radio", { name: "Light", exact: true }).click();
+ await expect(other.getByRole("radio", { name: "Light", exact: true })).toBeChecked();
await expect(page.getByRole("radio", { name: "Light", exact: true })).toBeChecked();
await expect(page.locator("html")).not.toHaveClass(/dark/);
});
diff --git a/webui/browser/theme-toggle-fixture.tsx b/webui/browser/theme-toggle-fixture.tsx
index 29fdf4a01..11db63275 100644
--- a/webui/browser/theme-toggle-fixture.tsx
+++ b/webui/browser/theme-toggle-fixture.tsx
@@ -1,3 +1,11 @@
+import { useState } from "react";
+import { createPortal } from "react-dom";
+import { Sidebar } from "@/components/Sidebar";
+import { PaneWorkbench } from "@/components/workbench/PaneWorkbench";
+import { ThreadViewport } from "@/components/thread/ThreadViewport";
+import { ThreadHistoryStatus } from "@/components/thread/ThreadHistoryStatus";
+import { formatQuotedUserMessage } from "@/lib/user-message-quote";
+import type { ChatSummary, UIMessage } from "@/lib/types";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
import { ThreadHeader } from "@/components/thread/ThreadHeader";
import { ThemeProvider, useTheme } from "@/hooks/useTheme";
@@ -6,15 +14,56 @@ export function ThemeToggleFixture() {
const { theme, toggle } = useTheme();
return (
<ThemeProvider theme={theme}>
- <main className="thread-workspace relative flex h-screen flex-col justify-center gap-8 bg-background px-6">
- <ThreadHeader title="Theme preview" hideTitle theme={theme} onToggleTheme={toggle} onToggleSidebar={() => {}} />
- <div className="workbench-body bg-background">
- <section className="workbench-pane flex flex-col gap-8 bg-background">
- <h1 data-testid="hero-greeting" className="text-center text-4xl text-foreground">Where should we start?</h1>
- <ThreadComposer variant="hero" onSend={() => {}} />
- </section>
- </div>
- </main>
+ {new URLSearchParams(location.search).has("chat") ? <ThemeChatFixture theme={theme} toggle={toggle} /> : (
+ <main data-theme-surface className="thread-workspace relative flex flex-col justify-center gap-8 bg-background px-6" style={{ height: "100vh" }}>
+ <div className="absolute inset-x-0 top-0">
+ <ThreadHeader title="Theme preview" hideTitle theme={theme} onToggleTheme={toggle} onToggleSidebar={() => {}} />
+ </div>
+ <div className="workbench-body">
+ <section data-theme-surface className="workbench-pane flex flex-col gap-8 bg-background">
+ <h1 data-testid="hero-greeting" data-theme-ink className="text-center text-4xl text-foreground">Where should we start?</h1>
+ <ThreadComposer variant="hero" onSend={() => {}} />
+ </section>
+ </div>
+ </main>
+ )}
</ThemeProvider>
);
}
+
+const sessions: ChatSummary[] = ["Theme chat", "Another chat"].map((title, index) => ({
+ key: `websocket:theme-${index}`, channel: "websocket", chatId: `theme-${index}`,
+ title, preview: "", createdAt: null, updatedAt: null,
+}));
+const messages: UIMessage[] = [
+ { id: "user", role: "user", content: formatQuotedUserMessage("Keep the surface layers in sync.", "Quoted context has its own translucent fill."), createdAt: 1 },
+ { id: "answer", role: "assistant", content: "An existing conversation with a portaled composer.", createdAt: 2 },
+ { id: "session", role: "user", content: "An incoming session message.", createdAt: 3,
+ sessionMessage: { message_id: "incoming", session: { id: "handle_0123456789abcdef0123456789abcdef", name: "nori" } } },
+];
+const noop = () => {};
+
+function ThemeChatFixture({ theme, toggle }: { theme: "light" | "dark"; toggle: () => void }) {
+ const [activeKey, setActiveKey] = useState(sessions[0].key);
+ const composer = <ThreadComposer onSend={noop} />;
+ return <main data-theme-surface className="flex bg-background" style={{ height: "100vh" }}>
+ <aside className="hidden w-64 shrink-0 sm:block">
+ <Sidebar sessions={sessions} activeKey={activeKey} onSelect={setActiveKey} loading={false} newChatActive={false}
+ onNewChat={noop} onRequestDelete={noop} onTogglePin={noop} onRequestRename={async () => {}}
+ onToggleArchive={noop} onToggleGroup={noop} onRequestRenameProject={noop} onNewChatInProject={noop}
+ onOpenSettings={noop} onOpenApps={noop} onOpenSkills={noop} onOpenAutomations={noop}
+ onOpenChannels={noop} onOpenSearch={noop} onToggleArchived={noop} />
+ </aside>
+ <div className="min-w-0 flex-1">
+ <PaneWorkbench panes={[{ key: "theme", title: "Theme chat" }]} activePaneKey="theme" layout="columns"
+ showLayoutControl={false} onActivatePane={noop} onAddPane={noop} onLayoutChange={noop} onPaneOrderChange={noop}
+ renderPane={(_pane, context) => <div className="relative flex min-h-0 flex-1 flex-col">
+ <ThreadHeader title="Theme chat" hideTitle theme={theme} onToggleTheme={toggle} onToggleSidebar={noop} />
+ <ThreadViewport messages={messages} isStreaming={false} conversationKey={activeKey}
+ navigationFrame={context.navigationFrame} composer={null} />
+ <ThreadHistoryStatus loading={false} error={null} exhausted onRetry={noop} />
+ {context.composerPortalTarget && createPortal(composer, context.composerPortalTarget)}
+ </div>} />
+ </div>
+ </main>;
+}
diff --git a/webui/browser/theme-toggle.spec.ts b/webui/browser/theme-toggle.spec.ts
index a43d473ec..62f2a8035 100644
--- a/webui/browser/theme-toggle.spec.ts
+++ b/webui/browser/theme-toggle.spec.ts
@@ -16,10 +16,18 @@ for (const width of [1440, 390]) {
expect(await icon.evaluate(node => node.getAnimations({ subtree: true }).length)).toBe(0);
const initialBox = await toggle.boundingBox();
- await toggle.click();
- await expect(page.locator("html")).toHaveClass(/dark/);
const intermediate = await icon.evaluate(async node => {
- await new Promise(requestAnimationFrame);
+ const changed = new Promise<void>(resolve => {
+ const observer = new MutationObserver(() => {
+ if (node.getAttribute("data-theme") !== "dark") return;
+ observer.disconnect();
+ resolve();
+ });
+ observer.observe(node, { attributes: true, attributeFilter: ["data-theme"] });
+ });
+ node.closest<HTMLButtonElement>("button")!.click();
+ await changed;
+ // Sample in the commit microtask, before a protocol round-trip can outlive the morph.
const transitions = node.getAnimations({ subtree: true });
for (const transition of transitions) {
transition.pause();
@@ -31,6 +39,7 @@ for (const width of [1440, 390]) {
for (const transition of transitions) transition.play();
return result;
});
+ await expect(page.locator("html")).toHaveClass(/dark/);
expect(intermediate.count).toBeGreaterThan(0);
expect(intermediate.radius).toBeGreaterThan(5);
expect(intermediate.radius).toBeLessThan(8);
@@ -38,7 +47,8 @@ for (const width of [1440, 390]) {
expect(intermediate.opacity).toBeLessThan(1);
expect(await toggle.boundingBox()).toEqual(initialBox);
- await toggle.click();
+ const toggleBox = (await toggle.boundingBox())!;
+ await page.mouse.click(toggleBox.x + toggleBox.width / 2, toggleBox.y + toggleBox.height / 2);
await expect(icon).toHaveAttribute("data-theme", "dark");
const input = page.getByRole("textbox");
await input.fill("Typing stays available during the theme change");
@@ -93,3 +103,206 @@ test("reduced motion keeps the canvas fade but switches the icon directly", asyn
await expect(core).toHaveCSS("r", "5px");
expect(await icon.evaluate(node => node.getAnimations({ subtree: true }).length)).toBe(0);
});
+
+for (const width of [1440, 390]) {
+ for (const initial of ["light", "dark"] as const) {
+ test(`reduced motion fades existing chat surfaces together from ${initial} at ${width}px`, async ({ page }) => {
+ await page.emulateMedia({ reducedMotion: "reduce" });
+ await page.setViewportSize({ width, height: 844 });
+ await page.addInitScript((theme) => {
+ localStorage.setItem("nanobot.locale", "en");
+ localStorage.setItem("nanobot-webui.theme", theme);
+ }, initial);
+ await page.goto("/browser/fixture.html?case=theme-toggle&chat");
+ const input = page.getByRole("textbox");
+ await input.fill("Keep this draft while changing theme");
+ const inputBox = await input.boundingBox();
+ await expect(page.locator("[data-user-text-bubble]").first()).toBeInViewport();
+ const selectors = [
+ ".thread-workspace", ".workbench-pane", ".thread-composer-surface",
+ "[data-testid='thread-header'] > div:last-child", "[data-user-text-bubble] p",
+ "blockquote", "[data-session-message] > div:last-child",
+ ];
+ const readPaint = () => page.evaluate((targets) => targets.map(selector =>
+ getComputedStyle(document.querySelector(selector)!).backgroundColor), selectors);
+ const before = await readPaint();
+ await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
+ const middle = await page.evaluate(async (targets) => {
+ await new Promise(requestAnimationFrame);
+ const transitions = document.getAnimations().filter(animation => animation instanceof CSSTransition);
+ for (const transition of transitions) {
+ transition.pause();
+ transition.currentTime = 140;
+ }
+ const style = (selector: string) => getComputedStyle(document.querySelector(selector)!);
+ const result = {
+ paint: targets.map(selector => style(selector).backgroundColor),
+ footer: style(".workbench-composer-footer").backgroundColor,
+ sidebarFooter: style("nav > div:last-child").backgroundColor,
+ gradient: style(".thread-history-status").getPropertyValue("--thread-history-background"),
+ highlight: style("[data-testid='chats-selection-highlight']").transitionProperty,
+ rowAction: style(".sidebar-action-trigger").transitionProperty,
+ };
+ for (const transition of transitions) transition.finish();
+ return result;
+ }, selectors);
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
+ const after = await readPaint();
+ for (const [index, selector] of selectors.entries()) {
+ expect(middle.paint[index], `${selector} must not snap to the target palette`).not.toBe(after[index]);
+ expect(middle.paint[index], `${selector} must leave the old palette`).not.toBe(before[index]);
+ }
+ // These in-flow wrappers now reveal their painted parent instead of adding a second canvas.
+ expect(middle.footer).toBe("rgba(0, 0, 0, 0)");
+ expect(middle.sidebarFooter).toBe("rgba(0, 0, 0, 0)");
+ expect(middle.gradient).toBe(middle.paint[0]);
+ expect(middle.highlight).toContain("background-color");
+ expect(middle.rowAction).toBe("opacity");
+ await expect(input).toHaveValue("Keep this draft while changing theme");
+ expect(await input.boundingBox()).toEqual(inputBox);
+ });
+ }
+}
+
+for (const width of [1440, 390]) {
+ for (const initial of ["light", "dark"] as const) {
+ test(`crossfades the whole ${initial === "light" ? "dark" : "light"} palette without a blank stage at ${width}px`, async ({ page }) => {
+ await page.setViewportSize({ width, height: 844 });
+ await page.addInitScript((theme) => {
+ localStorage.setItem("nanobot.locale", "en");
+ if (!localStorage.getItem("nanobot-webui.theme")) localStorage.setItem("nanobot-webui.theme", theme);
+ }, initial);
+ await page.goto("/browser/fixture.html?case=theme-toggle&chat");
+ const toggle = page.getByRole("button", { name: "Toggle theme from header", exact: true });
+ const input = page.getByRole("textbox");
+ await input.fill("Crossfade keeps the draft and layout");
+ const box = await input.boundingBox();
+ await expect(page.locator("[data-user-text-bubble]").first()).toBeInViewport();
+ await toggle.focus();
+ await page.keyboard.press("Space");
+ await expect.poll(() => page.evaluate(() => document.getAnimations().filter(animation => animation instanceof CSSAnimation
+ && animation.animationName.startsWith("theme-crossfade-")).length)).toBe(2);
+ const middle = await page.evaluate(() => {
+ const root = document.documentElement;
+ const fades = document.getAnimations().filter(animation => animation instanceof CSSAnimation
+ && animation.animationName.startsWith("theme-crossfade-"));
+ for (const fade of fades) {
+ fade.pause();
+ fade.currentTime = 100;
+ }
+ const oldTheme = getComputedStyle(root, "::view-transition-old(root)");
+ const newTheme = getComputedStyle(root, "::view-transition-new(root)");
+ return {
+ durations: fades.map(fade => fade.effect!.getTiming().duration),
+ canvas: getComputedStyle(document.querySelector(".workbench-pane")!).backgroundColor,
+ bubble: getComputedStyle(document.querySelector("[data-user-text-bubble] p")!).backgroundColor,
+ oldOpacity: Number(oldTheme.opacity), newOpacity: Number(newTheme.opacity),
+ oldBlend: oldTheme.mixBlendMode, newBlend: newTheme.mixBlendMode,
+ isolation: getComputedStyle(root, "::view-transition-image-pair(root)").isolation,
+ mask: newTheme.maskImage, clip: newTheme.clipPath,
+ };
+ });
+ expect(middle.durations).toEqual([200, 200]);
+ expect(middle.canvas).toBe(initial === "light" ? "rgb(48, 48, 48)" : "rgb(255, 255, 255)");
+ expect(middle.bubble).toBe(initial === "light" ? "rgba(56, 56, 56, 0.7)" : "rgba(245, 245, 245, 0.7)");
+ expect(middle.oldOpacity).toBeCloseTo(0.5);
+ expect(middle.newOpacity).toBeCloseTo(0.5);
+ expect(middle.oldOpacity + middle.newOpacity).toBeCloseTo(1);
+ expect(middle.oldBlend).toBe("plus-lighter");
+ expect(middle.newBlend).toBe("plus-lighter");
+ expect(middle.isolation).toBe("isolate");
+ expect(middle.mask).toBe("none");
+ expect(middle.clip).toBe("none");
+ await expect(toggle).toBeFocused();
+ expect(await input.boundingBox()).toEqual(box);
+ await page.screenshot({ path: test.info().outputPath(`crossfade-${width}-${initial}-mid.png`), animations: "allow" });
+ // Keyboard input still reaches the live DOM while the native snapshots are paused.
+ await page.keyboard.press("Space");
+ for (let step = 0; step < 20 && !await input.evaluate(node => node === document.activeElement); step++) {
+ await page.keyboard.press("Tab");
+ }
+ await expect(input).toBeFocused();
+ await page.keyboard.type(" — typed during the crossfade");
+ await expect(input).toHaveValue("Crossfade keeps the draft and layout — typed during the crossfade");
+ await page.evaluate(() => document.getAnimations().filter(animation => animation instanceof CSSAnimation
+ && animation.animationName.startsWith("theme-crossfade-")).forEach(animation => animation.finish()));
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-snapshot")).toBeNull();
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
+ await expect(toggle.locator("svg")).toHaveAttribute("data-theme", initial === "light" ? "dark" : "light");
+ await page.reload();
+ await expect(toggle.locator("svg")).toHaveAttribute("data-theme", initial === "light" ? "dark" : "light");
+ expect(await page.evaluate(() => document.getAnimations().some(animation => animation instanceof CSSAnimation
+ && animation.animationName.startsWith("theme-crossfade-")))).toBe(false);
+ });
+ }
+}
+
+test("browsers without View Transitions keep a working palette fade", async ({ page }) => {
+ await page.addInitScript(() => {
+ localStorage.setItem("nanobot-webui.theme", "light");
+ Object.defineProperty(document, "startViewTransition", { value: undefined });
+ });
+ await page.goto("/browser/fixture.html?case=theme-toggle&chat");
+ await page.getByRole("button", { name: "Toggle theme from header", exact: true }).click();
+ await expect(page.locator("html")).toHaveClass(/dark/);
+ const midpoint = await page.locator(".workbench-pane").evaluate(async node => {
+ await new Promise(requestAnimationFrame);
+ const paint = node.getAnimations().filter(animation => animation instanceof CSSTransition);
+ paint.forEach(animation => { animation.pause(); animation.currentTime = 140; });
+ const color = getComputedStyle(node).backgroundColor;
+ paint.forEach(animation => animation.finish());
+ return color;
+ });
+ expect(midpoint).not.toBe("rgb(48, 48, 48)");
+ expect(midpoint).not.toBe("rgb(255, 255, 255)");
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
+ await expect(page.getByRole("textbox")).toBeEditable();
+});
+
+test("a browser-skipped transition still applies the theme and releases the toggle", async ({ page }) => {
+ await page.addInitScript(() => {
+ localStorage.setItem("nanobot-webui.theme", "light");
+ const start = document.startViewTransition.bind(document);
+ document.startViewTransition = (...args) => {
+ const transition = start(...args);
+ transition.skipTransition();
+ return transition;
+ };
+ });
+ await page.goto("/browser/fixture.html?case=theme-toggle&chat");
+ const toggle = page.getByRole("button", { name: "Toggle theme from header", exact: true });
+ await toggle.click();
+ await expect(page.locator("html")).toHaveClass(/dark/);
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-snapshot")).toBeNull();
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
+ await toggle.click();
+ await expect(page.locator("html")).not.toHaveClass(/dark/);
+});
+
+test("selection highlights keep geometry easing and only fade paint with reduced motion", async ({ page }) => {
+ await page.setViewportSize({ width: 1440, height: 844 });
+ await page.addInitScript(() => {
+ localStorage.setItem("nanobot.locale", "en");
+ localStorage.setItem("nanobot-webui.theme", "light");
+ });
+ await page.goto("/browser/fixture.html?case=theme-toggle&chat");
+ const highlight = page.getByTestId("chats-selection-highlight");
+ await expect(highlight).toHaveCSS("transition-property", "transform, width, height, background-color");
+ await expect(highlight).toHaveCSS("transition-duration", "0.3s, 0.3s, 0.3s, 0s");
+ await expect(highlight).toHaveCSS("transition-timing-function", "ease-out, ease-out, ease-out, ease");
+
+ await page.emulateMedia({ reducedMotion: "reduce" });
+ await expect(highlight).toHaveCSS("transition-property", "none");
+ const paint = await highlight.evaluate(node => {
+ document.querySelector<HTMLButtonElement>("button[aria-label='Toggle theme from header']")!.click();
+ const style = getComputedStyle(node);
+ return { property: style.transitionProperty, duration: style.transitionDuration };
+ });
+ expect(paint).toEqual({
+ property: "background-color, border-color, box-shadow",
+ duration: "0.28s, 0.28s, 0.28s",
+ });
+ await expect(page.locator("html")).toHaveClass(/dark/);
+ await expect.poll(() => page.locator("html").getAttribute("data-theme-transition")).toBeNull();
+ await expect(highlight).toHaveCSS("transition-property", "none");
+});
diff --git a/webui/src/App.tsx b/webui/src/App.tsx
index a7e601d35..630203458 100644
--- a/webui/src/App.tsx
+++ b/webui/src/App.tsx
@@ -2889,6 +2889,7 @@ function Shell({
}}
>
<div
+ data-theme-surface
className={cn(
"absolute inset-y-0 left-0 h-full w-full overflow-hidden",
showHostChrome
@@ -2964,6 +2965,7 @@ function Shell({
</Suspense>
) : null}
<main ref={managementMain}
+ data-theme-surface
aria-hidden={managingConnections && remoteConnections?.embeddedManagement || undefined}
{...(managingConnections && remoteConnections?.embeddedManagement ? { inert: "" } : {})}
className={cn(
diff --git a/webui/src/components/ChatList.tsx b/webui/src/components/ChatList.tsx
index 9f6808c2c..8fe290178 100644
--- a/webui/src/components/ChatList.tsx
+++ b/webui/src/components/ChatList.tsx
@@ -1829,7 +1829,7 @@ function ProjectGroupHeader({
function ChatsGroupHeader({ label }: { label: string }) {
return (
- <div className="px-2 pb-2 pt-2 text-[11px] font-medium leading-4 text-sidebar-muted-foreground">
+ <div data-theme-ink className="px-2 pb-2 pt-2 text-[11px] font-medium leading-4 text-sidebar-muted-foreground">
{label}
</div>
);
diff --git a/webui/src/components/MarkdownText.tsx b/webui/src/components/MarkdownText.tsx
index 8b9792293..a59f5e824 100644
--- a/webui/src/components/MarkdownText.tsx
+++ b/webui/src/components/MarkdownText.tsx
@@ -96,6 +96,7 @@ export function MarkdownText({
const plainFallback = (
<div
+ data-theme-ink
className={cn(
"whitespace-pre-wrap break-words text-reading text-foreground/92",
streaming && "streaming-text-fallback",
diff --git a/webui/src/components/MessageBubble.tsx b/webui/src/components/MessageBubble.tsx
index 4525eab6a..23c249157 100644
--- a/webui/src/components/MessageBubble.tsx
+++ b/webui/src/components/MessageBubble.tsx
@@ -387,7 +387,7 @@ function IncomingSessionMessage({
<div className="mb-1.5 flex items-center px-4 text-[12px] text-muted-foreground">
<SessionHandleLabel id={handle.id}>{handleName}</SessionHandleLabel>
</div>
- <div className="relative min-w-0 rounded-floating bg-secondary/70 px-4 py-2">
+ <div data-theme-surface className="relative min-w-0 rounded-floating bg-secondary/70 px-4 py-2">
{contextMenu}
<div data-assistant-selectable="true" className="min-w-0">
<MarkdownText
@@ -489,6 +489,7 @@ export function MessageBubble({
<div data-user-text-bubble className="relative ml-auto w-fit max-w-full min-w-0">
{contextMenu}
<p
+ data-theme-surface
data-temporary-message={temporary ? "true" : undefined}
className={cn(
"ml-auto w-fit max-w-full min-w-0 rounded-floating px-4 py-2",
@@ -561,6 +562,8 @@ export function MessageBubble({
function UserQuotedContext({ text, label }: { text: string; label: string }) {
return (
<blockquote
+ data-theme-surface
+ data-theme-ink
className={cn(
"ml-auto flex w-fit max-w-full min-w-0 items-start gap-2 rounded-control",
"border border-border/60 bg-muted/35 px-3 py-2 text-left text-muted-foreground",
diff --git a/webui/src/components/Sidebar.tsx b/webui/src/components/Sidebar.tsx
index ae513ef8f..172d7e9b3 100644
--- a/webui/src/components/Sidebar.tsx
+++ b/webui/src/components/Sidebar.tsx
@@ -155,6 +155,8 @@ export function Sidebar(props: SidebarProps) {
return (
<nav
+ data-theme-surface
+ data-theme-ink
ref={props.containActionMenus ? setMenuPortalContainer : undefined}
aria-label={t("sidebar.navigation")}
className={cn(
@@ -323,8 +325,10 @@ export function Sidebar(props: SidebarProps) {
onRequestUpdate={props.availableUpdate.onRequestUpdate} installationMethod={props.availableUpdate.installationMethod} />
)}
<div
+ data-theme-surface
className={cn(
- "flex items-center justify-between gap-1 bg-sidebar/55 px-2.5 py-3 text-xs",
+ "flex items-center justify-between gap-1 px-2.5 py-3 text-xs",
+ props.hostChromeInset && "bg-sidebar/55",
collapsed && "w-14 flex-col px-0",
)}
>
diff --git a/webui/src/components/SidebarSelectionHighlight.tsx b/webui/src/components/SidebarSelectionHighlight.tsx
index d93533944..33a4103f0 100644
--- a/webui/src/components/SidebarSelectionHighlight.tsx
+++ b/webui/src/components/SidebarSelectionHighlight.tsx
@@ -121,7 +121,7 @@ export function SidebarSelectionHighlight({
data-testid={`${scope}-selection-highlight`}
data-active-id={activeId ?? undefined}
aria-hidden="true"
- className={cn("pointer-events-none absolute left-0 top-0 z-0 !mt-0 rounded-control bg-sidebar-foreground/[0.055] opacity-0 transition-[transform,width,height] duration-300 ease-out will-change-transform motion-reduce:transition-none dark:bg-white/[0.07]", highlightClassName)}
+ className={cn("sidebar-selection-highlight pointer-events-none absolute left-0 top-0 z-0 !mt-0 rounded-control bg-sidebar-foreground/[0.055] opacity-0 will-change-transform dark:bg-white/[0.07]", highlightClassName)}
/>
</div>
);
diff --git a/webui/src/components/remote/HostSwitcherView.tsx b/webui/src/components/remote/HostSwitcherView.tsx
index ca7ee23eb..bfe208144 100644
--- a/webui/src/components/remote/HostSwitcherView.tsx
+++ b/webui/src/components/remote/HostSwitcherView.tsx
@@ -126,7 +126,7 @@ export function HostSwitcherView({ picker, status, collapsed = false, portalCont
const current = `${identity}, ${currentLabel}`;
const detail = pendingName ? `${current}. ${t("remote.preparing", { name: pendingName })}` : current;
const button = <Button ref={buttonRef} variant="ghost" size="sm" aria-label={t("remote.switchHost")}
- data-host-switcher className={cn("host-no-drag touch-target h-8 min-w-0 gap-2 rounded-xl px-2 text-xs font-normal text-sidebar-content/75 hover:text-sidebar-content",
+ data-host-switcher data-theme-surface data-theme-ink className={cn("host-no-drag touch-target h-8 min-w-0 gap-2 rounded-xl px-2 text-xs font-normal text-sidebar-content/75 hover:text-sidebar-content",
collapsed ? "w-8 justify-center px-0" : "max-w-full flex-1 justify-start")}
onClick={picker.kind === "embedded" ? () => {
const rect = buttonRef.current?.getBoundingClientRect();
diff --git a/webui/src/components/thread/ThreadHeader.tsx b/webui/src/components/thread/ThreadHeader.tsx
index 3b8dacd17..15e9bea8e 100644
--- a/webui/src/components/thread/ThreadHeader.tsx
+++ b/webui/src/components/thread/ThreadHeader.tsx
@@ -75,6 +75,7 @@ export function ThreadHeader({
)}
>
<div
+ data-theme-surface
className={cn(
controlsClassName,
"relative min-w-0",
@@ -111,7 +112,7 @@ export function ThreadHeader({
) : null}
</div>
- <div className={cn(controlsClassName, "ml-auto shrink-0")}>
+ <div data-theme-surface className={cn(controlsClassName, "ml-auto shrink-0")}>
{sessionInfoAction}
{promptNavigatorAction}
{actions}
diff --git a/webui/src/components/thread/ThreadShell.tsx b/webui/src/components/thread/ThreadShell.tsx
index 9aca6fd18..73273693e 100644
--- a/webui/src/components/thread/ThreadShell.tsx
+++ b/webui/src/components/thread/ThreadShell.tsx
@@ -335,6 +335,7 @@ function HeroGreeting({ text }: { text: string }) {
<h1
ref={headingRef}
data-testid="hero-greeting"
+ data-theme-ink
className="select-none whitespace-nowrap text-[34px] font-normal leading-[1.08] tracking-normal text-foreground sm:text-[48px] sm:leading-tight"
>
{text}
diff --git a/webui/src/components/thread/ThreadViewport.tsx b/webui/src/components/thread/ThreadViewport.tsx
index 60ac120d3..3c6179bed 100644
--- a/webui/src/components/thread/ThreadViewport.tsx
+++ b/webui/src/components/thread/ThreadViewport.tsx
@@ -1203,6 +1203,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
<div
ref={composerDockRef}
data-testid="thread-composer-dock"
+ data-theme-surface
onInputCapture={(event) => {
if (event.target instanceof HTMLTextAreaElement) {
threadMotionRef.current?.handleComposerInput();
diff --git a/webui/src/components/workbench/PaneWorkbench.tsx b/webui/src/components/workbench/PaneWorkbench.tsx
index e80d3f2f4..dd4652634 100644
--- a/webui/src/components/workbench/PaneWorkbench.tsx
+++ b/webui/src/components/workbench/PaneWorkbench.tsx
@@ -678,6 +678,7 @@ export function PaneWorkbench({
return (
<section
ref={setNavigationFrame}
+ data-theme-surface
aria-label={t("workbench.aria", { defaultValue: "Conversation workbench" })}
className={cn(
"thread-workspace relative flex h-full min-h-0 flex-col overflow-hidden bg-background",
@@ -693,9 +694,10 @@ export function PaneWorkbench({
/>
</header>
) : null}
- <div className="workbench-body relative min-h-0 flex-1 bg-background">
+ <div className="workbench-body relative min-h-0 flex-1">
<div
ref={gridRef}
+ data-theme-surface
data-testid="pane-grid"
data-layout={effectiveLayout}
className={cn(
@@ -715,6 +717,7 @@ export function PaneWorkbench({
else paneRefs.current.delete(pane.key);
}}
aria-label={pane.title}
+ data-theme-surface
data-active={active ? "true" : "false"}
data-dragging={draggingPaneKey === pane.key ? "true" : undefined}
data-testid={`workbench-pane-${pane.key}`}
@@ -830,7 +833,7 @@ export function PaneWorkbench({
</div>
{chrome ? (
- <footer className="workbench-composer-footer shrink-0 bg-background px-3 pb-[calc(0.5rem+env(safe-area-inset-bottom))] sm:px-4 sm:pb-[calc(0.75rem+env(safe-area-inset-bottom))]">
+ <footer className="workbench-composer-footer shrink-0 px-3 pb-[calc(0.5rem+env(safe-area-inset-bottom))] sm:px-4 sm:pb-[calc(0.75rem+env(safe-area-inset-bottom))]">
<div
ref={setComposerPortalTarget}
data-testid="workbench-composer-host"
diff --git a/webui/src/globals.css b/webui/src/globals.css
index a56719aa4..375a14857 100644
--- a/webui/src/globals.css
+++ b/webui/src/globals.css
@@ -30,6 +30,28 @@
}
}
+/* Only gradient owners need interpolable colors; palette tokens remain unchanged. */
+@property --thread-history-background {
+ syntax: "<color>";
+ inherits: false;
+ initial-value: transparent;
+}
+@property --host-glass-spot {
+ syntax: "<color>";
+ inherits: false;
+ initial-value: transparent;
+}
+@property --host-glass-start {
+ syntax: "<color>";
+ inherits: false;
+ initial-value: transparent;
+}
+@property --host-glass-end {
+ syntax: "<color>";
+ inherits: false;
+ initial-value: transparent;
+}
+
/* Design tokens — HSL form, sourced from shadcn/ui's "neutral" palette. */
@layer base {
:root {
@@ -393,6 +415,12 @@
backdrop-filter: saturate(185%) blur(34px);
}
+ .host-window-shell {
+ transition: --host-glass-spot var(--theme-paint-duration, 0s) linear,
+ --host-glass-start var(--theme-paint-duration, 0s) linear,
+ --host-glass-end var(--theme-paint-duration, 0s) linear;
+ }
+
.host-sidebar-glass {
background: hsl(var(--sidebar) / 0.94);
-webkit-backdrop-filter: saturate(145%) blur(18px);
@@ -444,6 +472,7 @@
--tw-prose-headings: hsl(var(--foreground));
--tw-prose-bold: hsl(var(--foreground));
--tw-prose-lead: hsl(var(--foreground));
+ transition: var(--theme-ink-transition, color 0s);
@apply text-reading;
}
@@ -631,9 +660,12 @@
}
.thread-history-status {
+ --thread-history-background: hsl(var(--background));
height: 48px;
- background: linear-gradient(hsl(var(--background)) 35%, hsl(var(--background) / 0));
+ background: linear-gradient(var(--thread-history-background) 35%, transparent);
color: hsl(var(--muted-foreground));
+ transition: --thread-history-background var(--theme-paint-duration, 0s) linear,
+ var(--theme-ink-transition, color 0s);
}
.thread-history-reveal {
transform: translateY(calc(var(--history-pull, 0px) - 100%));
@@ -1175,12 +1207,23 @@
}
}
+.sidebar-selection-highlight {
+ transition: transform 300ms ease-out, width 300ms ease-out, height 300ms ease-out,
+ var(--theme-paint-transition, background-color 0s);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .sidebar-selection-highlight {
+ transition: var(--theme-paint-transition, none);
+ }
+}
+
/* Composer controls adapt to their actual container, not just the viewport. */
.thread-composer-surface {
--composer-shadow-color: 240 10% 16%;
--tw-shadow: inset 0 0 0 1px hsl(var(--border) / 0.75), 0 4px 18px -8px hsl(var(--composer-shadow-color) / 0.12);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
- transition: background-color 160ms ease-out, box-shadow 160ms ease-out, opacity 160ms ease-out;
+ transition: var(--theme-paint-transition, background-color 160ms ease-out, box-shadow 160ms ease-out), opacity 160ms ease-out;
container-name: thread-composer;
container-type: inline-size;
}
@@ -1190,7 +1233,7 @@
}
@media (prefers-reduced-motion: reduce) {
- .thread-composer-surface { transition: none; }
+ .thread-composer-surface { transition: var(--theme-paint-transition, none); }
}
@media (forced-colors: active) {
diff --git a/webui/src/hooks/theme-transition.css b/webui/src/hooks/theme-transition.css
index c130cbb40..bc278369a 100644
--- a/webui/src/hooks/theme-transition.css
+++ b/webui/src/hooks/theme-transition.css
@@ -6,25 +6,68 @@
--theme-ink-delay: 100ms;
}
-/* Keep text from dissolving into a matching gray while the canvas changes. */
-:root[data-theme-transition] :is(
- body,
- .thread-workspace,
- .workbench-body,
- .workbench-pane,
- main.bg-background,
- .bg-sidebar,
- .text-sidebar-muted-foreground,
- [data-testid="thread-header"] > div,
- [data-testid="hero-greeting"]
-) {
- transition: background-color 280ms linear, border-color 280ms linear, color 0s linear var(--theme-ink-delay);
+/* Paint owners opt in; components with local motion compose these lists instead. */
+:root[data-theme-transition] {
+ --theme-paint-duration: 280ms;
+ --theme-paint-transition: background-color var(--theme-paint-duration) linear, border-color var(--theme-paint-duration) linear, box-shadow var(--theme-paint-duration) linear;
+ --theme-ink-transition: color 0s linear var(--theme-ink-delay);
}
-:root[data-theme-transition] .thread-composer-surface {
- transition: background-color 280ms linear, box-shadow 280ms linear, opacity 160ms ease-out;
+:root[data-theme-transition] [data-theme-surface] {
+ transition: var(--theme-paint-transition);
+}
+
+/* Delay only explicitly colored ink, not every inheriting layout wrapper. */
+:root[data-theme-transition] [data-theme-ink] {
+ transition: var(--theme-ink-transition);
+}
+
+:root[data-theme-transition] :is(body, [data-theme-surface][data-theme-ink]) {
+ transition: var(--theme-paint-transition), var(--theme-ink-transition);
}
:root[data-theme-transition] .thread-composer-surface textarea::placeholder {
transition: color 0s linear var(--theme-ink-delay);
}
+
+/* Blend complete palettes, without a second layer of per-surface paint interpolation. */
+:root[data-theme-snapshot] {
+ --theme-paint-duration: 0s;
+ --theme-ink-delay: 0s;
+}
+
+:root[data-theme-snapshot]::view-transition {
+ pointer-events: none;
+}
+
+:root[data-theme-snapshot]::view-transition-group(root) {
+ animation: none;
+}
+
+/* Complementary alpha adds to one, rather than exposing an empty frame between themes. */
+:root[data-theme-snapshot]::view-transition-image-pair(root) {
+ isolation: isolate;
+}
+
+:root[data-theme-snapshot]::view-transition-old(root),
+:root[data-theme-snapshot]::view-transition-new(root) {
+ mix-blend-mode: plus-lighter;
+}
+
+:root[data-theme-snapshot]::view-transition-old(root) {
+ animation: theme-crossfade-out 200ms ease-in-out both;
+}
+
+:root[data-theme-snapshot]::view-transition-new(root) {
+ animation: theme-crossfade-in 200ms ease-in-out both;
+}
+
+@keyframes theme-crossfade-out {
+ from { opacity: 1; }
+ to { opacity: 0; }
+}
+
+@keyframes theme-crossfade-in {
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
diff --git a/webui/src/hooks/useTheme.ts b/webui/src/hooks/useTheme.ts
index 0213c70ca..65f8a1d5c 100644
--- a/webui/src/hooks/useTheme.ts
+++ b/webui/src/hooks/useTheme.ts
@@ -8,6 +8,7 @@ import {
useState,
type ReactNode,
} from "react";
+import { flushSync } from "react-dom";
import "./theme-transition.css";
import { useMediaQuery } from "@/hooks/useMediaQuery";
@@ -26,6 +27,10 @@ function readStored(): ThemePreference {
}
}
+function resolveTheme(preference: ThemePreference, systemDark: boolean): Theme {
+ return preference === "system" ? (systemDark ? "dark" : "light") : preference;
+}
+
function applyTheme(theme: Theme): void {
const root = document.documentElement;
if (theme === "dark") root.classList.add("dark");
@@ -47,15 +52,19 @@ export function useTheme(): {
} {
const [preference, setPreference] = useState(readStored);
const systemDark = useMediaQuery("(prefers-color-scheme: dark)");
- const theme: Theme = preference === "system" ? (systemDark ? "dark" : "light") : preference;
+ const theme = resolveTheme(preference, systemDark);
const switchTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const viewTransition = useRef<ViewTransition | null>(null);
+ const pendingPreference = useRef<{ value: ThemePreference } | null>(null);
useEffect(() => () => {
- if (switchTimer.current !== null) {
- clearTimeout(switchTimer.current);
- switchTimer.current = null;
- delete document.documentElement.dataset.themeTransition;
- }
+ if (switchTimer.current !== null) clearTimeout(switchTimer.current);
+ switchTimer.current = null;
+ pendingPreference.current = null;
+ viewTransition.current?.skipTransition();
+ viewTransition.current = null;
+ delete document.documentElement.dataset.themeTransition;
+ delete document.documentElement.dataset.themeSnapshot;
}, []);
useEffect(() => {
@@ -66,32 +75,64 @@ export function useTheme(): {
const refresh = (event: StorageEvent) => {
if (event.key !== null && event.key !== STORAGE_KEY) return;
if (event.storageArea && event.storageArea !== window.localStorage) return;
- setPreference(readStored());
+ const value = readStored();
+ if (pendingPreference.current) pendingPreference.current.value = value;
+ else setPreference(value);
};
window.addEventListener("storage", refresh);
return () => window.removeEventListener("storage", refresh);
}, []);
const setTheme = useCallback((value: ThemePreference) => {
- if (value === preference) return;
- const next = value === "system" ? (systemDark ? "dark" : "light") : value;
- // Changing preference without changing the palette must not start or block a transition.
- if (next !== theme) {
- if (switchTimer.current !== null) return;
- document.documentElement.dataset.themeTransition = next;
+ const pending = pendingPreference.current;
+ const selected = pending?.value ?? preference;
+ if (value === selected) return;
+ const next = resolveTheme(value, systemDark);
+ const changesPalette = next !== resolveTheme(selected, systemDark);
+ const root = document.documentElement;
+ // Same-palette choices, such as switching to System, must remain selectable.
+ if (changesPalette) {
+ if (switchTimer.current !== null || viewTransition.current !== null) return;
+ root.dataset.themeTransition = next;
switchTimer.current = setTimeout(() => {
- delete document.documentElement.dataset.themeTransition;
switchTimer.current = null;
+ if (viewTransition.current === null) delete root.dataset.themeTransition;
}, 600);
}
- setPreference(value);
+
+ if (pending) {
+ // A native capture defers the React commit; retain the latest accepted preference.
+ pending.value = value;
+ } else if (changesPalette && document.startViewTransition
+ && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
+ const update = { value };
+ pendingPreference.current = update;
+ root.dataset.themeSnapshot = "";
+ const transition = document.startViewTransition(() => {
+ if (pendingPreference.current !== update) return;
+ pendingPreference.current = null;
+ flushSync(() => setPreference(update.value));
+ });
+ viewTransition.current = transition;
+ // Browser-skipped captures still apply their update and must release the owner.
+ void transition.ready.catch(() => {});
+ const release = () => {
+ if (viewTransition.current !== transition) return;
+ viewTransition.current = null;
+ delete root.dataset.themeSnapshot;
+ if (switchTimer.current === null) delete root.dataset.themeTransition;
+ };
+ void transition.finished.then(release, release);
+ } else {
+ setPreference(value);
+ }
// Only user choices persist. Resolved system changes and other tabs never write back.
try {
localStorage.setItem(STORAGE_KEY, value);
} catch {
// Browser-only preferences should never block the interface.
}
- }, [preference, systemDark, theme]);
+ }, [preference, systemDark]);
const toggle = useCallback(
() => setTheme(theme === "dark" ? "light" : "dark"),
[setTheme, theme],
diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx
index ba287f3c8..9d5bc43d5 100644
--- a/webui/src/tests/app-layout.test.tsx
+++ b/webui/src/tests/app-layout.test.tsx
@@ -2215,12 +2215,7 @@ describe("App layout", () => {
expect(highlight).not.toHaveClass(
"group-data-[resizing=true]/sidebar:transition-none",
);
- expect(highlight).toHaveClass(
- "transition-[transform,width,height]",
- "duration-300",
- "ease-out",
- "motion-reduce:transition-none",
- );
+ expect(highlight).toHaveClass("sidebar-selection-highlight");
}
fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 272 });
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 400 });
diff --git a/webui/src/tests/preview-pane.test.tsx b/webui/src/tests/preview-pane.test.tsx
index af5f8cc60..8e6dad511 100644
--- a/webui/src/tests/preview-pane.test.tsx
+++ b/webui/src/tests/preview-pane.test.tsx
@@ -75,7 +75,7 @@ describe("preview tabs", () => {
const highlight = screen.getByTestId("preview-tabs-selection-highlight");
expect(highlight).toHaveAttribute("data-active-id", "file:data.json");
expect(highlight.className).toContain("bg-sidebar-foreground/[0.055]");
- expect(highlight.className).toContain("motion-reduce:transition-none");
+ expect(highlight).toHaveClass("sidebar-selection-highlight");
await waitFor(() => expect(shell.style.getPropertyValue("--file-preview-slot-width")).toBe("544px"));
fireEvent.click(screen.getByRole("tab", { name: "chart.png" }));
expect(screen.getByTestId("preview-pane")).toBe(shell);
diff --git a/webui/src/tests/useTheme.test.tsx b/webui/src/tests/useTheme.test.tsx
index 325d3b0d8..c57c93e2e 100644
--- a/webui/src/tests/useTheme.test.tsx
+++ b/webui/src/tests/useTheme.test.tsx
@@ -6,6 +6,26 @@ import { useTheme } from "@/hooks/useTheme";
describe("useTheme", () => {
let systemDark = false;
let mediaEvents: EventTarget;
+ let restoreNativeTransition: (() => void) | undefined;
+
+ function deferNativeCapture() {
+ const previous = Object.getOwnPropertyDescriptor(document, "startViewTransition");
+ let update!: () => void;
+ let ready!: () => void;
+ let finish!: () => void;
+ const transition = {
+ ready: new Promise<void>(resolve => { ready = resolve; }),
+ finished: new Promise<void>(resolve => { finish = resolve; }),
+ skipTransition: vi.fn(),
+ };
+ const start = vi.fn((callback: () => void) => { update = callback; return transition; });
+ Object.defineProperty(document, "startViewTransition", { configurable: true, value: start });
+ restoreNativeTransition = () => {
+ if (previous) Object.defineProperty(document, "startViewTransition", previous);
+ else Reflect.deleteProperty(document, "startViewTransition");
+ };
+ return { start, capture: () => { update(); ready(); }, finish };
+ }
function changeSystemTheme(dark: boolean) {
act(() => {
@@ -22,8 +42,8 @@ describe("useTheme", () => {
vi.useFakeTimers();
systemDark = false;
mediaEvents = new EventTarget();
- vi.stubGlobal("matchMedia", vi.fn(() => ({
- get matches() { return systemDark; },
+ vi.stubGlobal("matchMedia", vi.fn((query: string) => ({
+ get matches() { return query === "(prefers-color-scheme: dark)" && systemDark; },
addEventListener: mediaEvents.addEventListener.bind(mediaEvents),
removeEventListener: mediaEvents.removeEventListener.bind(mediaEvents),
})));
@@ -40,6 +60,8 @@ describe("useTheme", () => {
afterEach(() => {
cleanup();
+ restoreNativeTransition?.();
+ restoreNativeTransition = undefined;
vi.clearAllTimers();
vi.useRealTimers();
vi.restoreAllMocks();
@@ -211,6 +233,51 @@ describe("useTheme", () => {
expect(result.current.theme).toBe("light");
});
+ it("retains a same-palette System choice before a native capture commits", async () => {
+ systemDark = true;
+ localStorage.setItem("nanobot-webui.theme", "light");
+ const native = deferNativeCapture();
+ const { result } = renderHook(useTheme);
+
+ act(() => result.current.setTheme("dark"));
+ expect(native.start).toHaveBeenCalledOnce();
+ expect(localStorage.getItem("nanobot-webui.theme")).toBe("dark");
+ act(() => result.current.setTheme("light"));
+ expect(localStorage.getItem("nanobot-webui.theme")).toBe("dark");
+ act(() => result.current.setTheme("system"));
+ expect(localStorage.getItem("nanobot-webui.theme")).toBe("system");
+ act(() => native.capture());
+ expect(result.current.preference).toBe("system");
+ expect(result.current.theme).toBe("dark");
+
+ changeSystemTheme(false);
+ expect(result.current.theme).toBe("light");
+ expect(localStorage.getItem("nanobot-webui.theme")).toBe("system");
+ await act(async () => native.finish());
+ act(() => vi.advanceTimersByTime(600));
+ expect(document.documentElement).not.toHaveAttribute("data-theme-snapshot");
+ expect(document.documentElement).not.toHaveAttribute("data-theme-transition");
+ });
+
+ it("keeps another tab's newer preference when a native capture is pending", async () => {
+ localStorage.setItem("nanobot-webui.theme", "light");
+ const native = deferNativeCapture();
+ const { result } = renderHook(useTheme);
+ act(() => result.current.setTheme("dark"));
+ const write = vi.spyOn(Storage.prototype, "setItem");
+ localStorage.removeItem("nanobot-webui.theme");
+ notifyStorageChange();
+ act(() => native.capture());
+
+ expect(result.current.preference).toBe("system");
+ expect(result.current.theme).toBe("light");
+ expect(document.documentElement).not.toHaveClass("dark");
+ expect(write).not.toHaveBeenCalled();
+ await act(async () => native.finish());
+ act(() => vi.advanceTimersByTime(600));
+ expect(document.documentElement).not.toHaveAttribute("data-theme-snapshot");
+ });
+
it("ignores rapid reversals for 600ms without replaying them later", () => {
localStorage.setItem("nanobot-webui.theme", "light");
const { result } = renderHook(useTheme);