From d3bb330f57cc297c2a41043be78f3b366965d73b Mon Sep 17 00:00:00 2001 From: chengyongru Date: Mon, 16 Nov 2026 10:54:08 +0800 Subject: [PATCH] fix(webui): preserve goal background without property registration --- webui/browser/goal-island-background.spec.ts | 64 ++++++++++++++++++++ webui/src/components/thread/goal-island.css | 3 + 2 files changed, 67 insertions(+) create mode 100644 webui/browser/goal-island-background.spec.ts diff --git a/webui/browser/goal-island-background.spec.ts b/webui/browser/goal-island-background.spec.ts new file mode 100644 index 000000000..25586e492 --- /dev/null +++ b/webui/browser/goal-island-background.spec.ts @@ -0,0 +1,64 @@ +import { expect, test, type Locator, type Page } from "@playwright/test"; + +async function disableGoalPropertyRegistration(page: Page) { + await page.route("**/goal-island.css", async route => { + const response = await route.fetch(); + const source = await response.text(); + const declarations = source.match(/@property --goal-island-/g) ?? []; + expect(declarations).toHaveLength(3); + await route.fulfill({ response, body: source.replaceAll("@property --goal-island-", "@unknown --goal-island-") }); + }); +} + +async function expectBackgroundToCover(page: Page, owner: Locator) { + const surface = owner.locator(":scope > .goal-island-surface"); + const [ownerBox, surfaceBox, background] = await Promise.all([ + owner.boundingBox(), + surface.boundingBox(), + surface.evaluate(el => { + const style = getComputedStyle(el, "::before"); + return { color: style.backgroundColor, clip: style.clipPath }; + }), + ]); + expect(ownerBox).not.toBeNull(); + expect(surfaceBox).not.toBeNull(); + expect(surfaceBox!.width).toBeCloseTo(ownerBox!.width, 1); + expect(surfaceBox!.height).toBeCloseTo(ownerBox!.height, 1); + expect(background.color).not.toBe("rgba(0, 0, 0, 0)"); + expect(background.clip).not.toBe("none"); + + const image = await page.screenshot({ clip: { x: ownerBox!.x + 12, y: ownerBox!.y + 10, width: 1, height: 1 } }); + const pixel = await page.evaluate(async bytes => { + const bitmap = await createImageBitmap(new Blob([new Uint8Array(bytes)], { type: "image/png" })); + const canvas = document.createElement("canvas"); + canvas.width = canvas.height = 1; + const context = canvas.getContext("2d")!; + context.drawImage(bitmap, 0, 0); + return Array.from(context.getImageData(0, 0, 1, 1).data); + }, Array.from(image)); + expect(pixel.slice(0, 3).every(channel => channel > 180)).toBe(true); +} + +for (const reducedMotion of ["no-preference", "reduce"] as const) { + test(`goal background covers the content without registered properties (${reducedMotion})`, async ({ page }) => { + await page.emulateMedia({ reducedMotion }); + await page.addInitScript(() => { localStorage.setItem("nanobot.locale", "en"); }); + await disableGoalPropertyRegistration(page); + await page.goto("/browser/fixture.html?case=session-transition&preview&topic=goal"); + await page.addStyleTag({ content: '[data-testid="thread-header"] { background: black !important; }' }); + + const trigger = page.getByRole("button", { name: "Show full goal" }); + await expect(trigger).toBeVisible(); + await expectBackgroundToCover(page, trigger); + + await trigger.click(); + const panel = page.getByRole("dialog", { name: "Goal", exact: true }); + await expect(panel).toBeVisible(); + await panel.evaluate(async el => { await Promise.all(el.getAnimations({ subtree: true }).map(animation => animation.finished)); }); + await expectBackgroundToCover(page, panel); + + await page.keyboard.press("Escape"); + await expect(panel).toHaveCount(0); + await expectBackgroundToCover(page, trigger); + }); +} diff --git a/webui/src/components/thread/goal-island.css b/webui/src/components/thread/goal-island.css index a59fbc963..9371778f1 100644 --- a/webui/src/components/thread/goal-island.css +++ b/webui/src/components/thread/goal-island.css @@ -36,6 +36,9 @@ } .goal-island, .goal-island-panel { + --goal-island-width: 100%; + --goal-island-height: 100%; + --goal-island-radius: 16px; --goal-surface: hsl(var(--sidebar) / 94%); --goal-highlight: rgb(255 255 255 / 80%); --goal-shadow: rgb(20 20 24 / 10%);