Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(studio): the Lint badge pulses while an error finding exists (#4152)
Miguel Ángelf50df37671b9
diff --git a/packages/studio/src/App.tsx b/packages/studio/src/App.tsxindex 1877673daf..cd696541c1 100644--- a/packages/studio/src/App.tsx+++ b/packages/studio/src/App.tsx@@ -324,10 +324,8 @@ export function StudioApp() {effectiveTimelineDuration,});const compositionDimensions = useCompositionDimensions(previewIframeRef);- const { lintModal, linting, handleLint, closeLintModal, findingsByFile } = useLintModal(- projectId,- refreshKey,- );+ const { lintModal, linting, handleLint, closeLintModal, findingsByFile, hasLintError } =+ useLintModal(projectId, refreshKey);const frameCapture = useFrameCapture({projectId,activeCompPath,@@ -479,6 +477,7 @@ export function StudioApp() {linting={linting}lintFindingCount={lintModal?.length ?? findingsByFile.size}lintFindingsByFile={findingsByFile}+ lintHasError={hasLintError}onAddAssetToTimeline={handleAddAssetAtPlayhead}onAddCompositionToTimeline={handleAddCompositionAtPlayhead}/>diff --git a/packages/studio/src/components/StudioLeftSidebar.tsx b/packages/studio/src/components/StudioLeftSidebar.tsxindex 3c549b4bee..26fc82fe94 100644--- a/packages/studio/src/components/StudioLeftSidebar.tsx+++ b/packages/studio/src/components/StudioLeftSidebar.tsx@@ -17,6 +17,7 @@ export interface StudioLeftSidebarProps {onLint: () => void;linting: boolean;lintFindingCount?: number;+ lintHasError?: boolean;lintFindingsByFile?: Map<string, { count: number; messages: string[] }>;onAddAssetToTimeline?: (path: string) => void;onAddCompositionToTimeline?: (path: string) => void;@@ -31,6 +32,7 @@ export function StudioLeftSidebar({onLint,linting,lintFindingCount,+ lintHasError,lintFindingsByFile,onAddAssetToTimeline,onAddCompositionToTimeline,@@ -160,6 +162,7 @@ export function StudioLeftSidebar({onLint={onLint}linting={linting}lintFindingCount={lintFindingCount}+ lintHasError={lintHasError}lintFindingsByFile={lintFindingsByFile}onToggleCollapse={toggleLeftSidebar}onAddBlock={onAddBlock}diff --git a/packages/studio/src/components/sidebar/LeftSidebar.lintBadge.test.tsx b/packages/studio/src/components/sidebar/LeftSidebar.lintBadge.test.tsxnew file mode 100644index 0000000000..57a9913fe1--- /dev/null+++ b/packages/studio/src/components/sidebar/LeftSidebar.lintBadge.test.tsx@@ -0,0 +1,58 @@+// @vitest-environment happy-dom++import { act } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, describe, expect, it, vi } from "vitest";+import { LeftSidebar } from "./LeftSidebar";++Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });+(+ window as unknown as { happyDOM: { settings: { disableIframePageLoading: boolean } } }+).happyDOM.settings.disableIframePageLoading = true;++let root: Root | null = null;++afterEach(() => {+ if (root) act(() => root?.unmount());+ root = null;+ document.body.innerHTML = "";+});++function renderBadge(lintHasError: boolean): HTMLElement | null {+ const host = document.createElement("div");+ document.body.append(host);+ root = createRoot(host);+ act(() => {+ root?.render(+ <LeftSidebar+ projectId="demo"+ compositions={["index.html"]}+ assets={[]}+ fileTree={["index.html"]}+ activeComposition={null}+ onSelectComposition={vi.fn()}+ onLint={vi.fn()}+ lintFindingCount={2}+ lintHasError={lintHasError}+ />,+ );+ });+ return host.querySelector<HTMLElement>("[data-lint-badge]");+}++describe("LeftSidebar lint badge", () => {+ it("pulses, and stops for reduced motion, while an error finding exists", () => {+ const badge = renderBadge(true);+ expect(badge?.dataset.lintBadge).toBe("error");+ expect(badge?.className).toContain("animate-pulse");+ expect(badge?.className).toContain("motion-reduce:animate-none");+ expect(badge?.textContent).toContain("including errors");+ });++ it("stays still when the findings are warnings only", () => {+ const badge = renderBadge(false);+ expect(badge?.dataset.lintBadge).toBe("warning");+ expect(badge?.className).not.toContain("animate-pulse");+ expect(badge?.textContent).toContain("warnings only");+ });+});diff --git a/packages/studio/src/components/sidebar/LeftSidebar.tsx b/packages/studio/src/components/sidebar/LeftSidebar.tsxindex c2f96b5ffa..798dbe6e73 100644--- a/packages/studio/src/components/sidebar/LeftSidebar.tsx+++ b/packages/studio/src/components/sidebar/LeftSidebar.tsx@@ -74,6 +74,7 @@ interface LeftSidebarProps {onLint?: () => void;linting?: boolean;lintFindingCount?: number;+ lintHasError?: boolean;lintFindingsByFile?: Map<string, { count: number; messages: string[] }>;onToggleCollapse?: () => void;onAddBlock?: (blockName: string) => void | Promise<void>;@@ -108,6 +109,7 @@ export const LeftSidebar = memo(onLint,linting,lintFindingCount,+ lintHasError,lintFindingsByFile,onToggleCollapse,onAddBlock,@@ -319,8 +321,20 @@ export const LeftSidebar = memo(</svg>{linting ? "Linting…" : "Lint"}{!linting && lintFindingCount != null && lintFindingCount > 0 && (- <span className="ml-1 min-w-[16px] rounded-full bg-amber-500/20 px-1 text-[9px] font-bold text-amber-400">+ <span+ data-lint-badge={lintHasError ? "error" : "warning"}+ className={+ lintHasError+ ? "ml-1 min-w-[16px] rounded-full bg-panel-danger/25 px-1 text-[9px] font-bold text-panel-danger animate-pulse motion-reduce:animate-none"+ : "ml-1 min-w-[16px] rounded-full bg-amber-500/20 px-1 text-[9px] font-bold text-amber-400"+ }+ >{lintFindingCount}+ <span className="sr-only">+ {lintHasError+ ? " lint findings, including errors"+ : " lint findings, warnings only"}+ </span></span>)}</button>diff --git a/packages/studio/src/hooks/useLintModal.test.tsx b/packages/studio/src/hooks/useLintModal.test.tsxnew file mode 100644index 0000000000..e85494abe2--- /dev/null+++ b/packages/studio/src/hooks/useLintModal.test.tsx@@ -0,0 +1,65 @@+// @vitest-environment happy-dom++import { act } from "react";+import { createRoot, type Root } from "react-dom/client";+import { afterEach, describe, expect, it, vi } from "vitest";+import { useLintModal } from "./useLintModal";++(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++let root: Root | null = null;+let latest: ReturnType<typeof useLintModal> | null = null;++function Probe() {+ latest = useLintModal("demo");+ return null;+}++afterEach(() => {+ if (root) act(() => root?.unmount());+ root = null;+ latest = null;+ vi.unstubAllGlobals();+});++async function mountWithLint(response: () => Promise<unknown>) {+ vi.stubGlobal("fetch", vi.fn(response));+ root = createRoot(document.createElement("div"));+ await act(async () => root?.render(<Probe />));+ await act(async () => {+ await latest?.handleLint();+ });+}++const lintResponse = (findings: Array<{ severity: string; message: string }>) => async () => ({+ json: async () => ({ findings }),+});++describe("useLintModal hasLintError", () => {+ it("is true when a finding is an error and false for warnings only", async () => {+ await mountWithLint(lintResponse([{ severity: "error", message: "nested" }]));+ expect(latest?.hasLintError).toBe(true);+ act(() => root?.unmount());+ root = null;+ await mountWithLint(lintResponse([{ severity: "warning", message: "soft" }]));+ expect(latest?.hasLintError).toBe(false);+ });++ it("is true for a mixed error and warning list", async () => {+ await mountWithLint(+ lintResponse([+ { severity: "warning", message: "soft" },+ { severity: "error", message: "nested" },+ ]),+ );+ expect(latest?.hasLintError).toBe(true);+ });++ it("is true when the manual lint itself fails, matching the badge count", async () => {+ await mountWithLint(async () => {+ throw new Error("offline");+ });+ expect(latest?.lintModal).toHaveLength(1);+ expect(latest?.hasLintError).toBe(true);+ });+});diff --git a/packages/studio/src/hooks/useLintModal.ts b/packages/studio/src/hooks/useLintModal.tsindex a2e234f215..43ee501514 100644--- a/packages/studio/src/hooks/useLintModal.ts+++ b/packages/studio/src/hooks/useLintModal.ts@@ -96,6 +96,8 @@ export function useLintModal(projectId: string | null, refreshKey?: number) {const findingsByElement = useMemo(() => groupFindings((f) => f.elementId), [groupFindings]);const findingsByFile = useMemo(() => groupFindings((f) => f.file), [groupFindings]);+ // Reads the list the badge count reads: the manual result when present, else the background one.+ const hasLintError = (lintModal ?? backgroundFindings).some((f) => f.severity === "error");// Sync lint findings directly to the player store — eliminates the// mirroring useEffect that was previously in App.tsx.@@ -111,5 +113,6 @@ export function useLintModal(projectId: string | null, refreshKey?: number) {backgroundFindings,findingsByElement,findingsByFile,+ hasLintError,};}