Skip to content

Write HTML. Render video. Built for agents.

perf(studio): the lint error badge pulses three times, then holds (#4594)

Miguel Ángeld6e8542a3801
diff --git a/packages/studio/src/App.tsx b/packages/studio/src/App.tsx
index eb7c2b15a6..a026d797f5 100644
--- a/packages/studio/src/App.tsx
+++ b/packages/studio/src/App.tsx
@@ -344,8 +344,7 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: St
effectiveTimelineDuration,
});
const compositionDimensions = useCompositionDimensions(previewIframeRef);
- const { lintModal, linting, handleLint, closeLintModal, findingsByFile, hasLintError } =
- useLintModal(projectId, refreshKey);
+ const lint = useLintModal(projectId, refreshKey);
const frameCapture = useFrameCapture({
projectId,
activeCompPath,
@@ -500,11 +499,11 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: St
onSelectComposition={handleSelectComposition}
onAddBlock={handleAddBlock}
onPreviewBlock={setBlockPreview}
- onLint={handleLint}
- linting={linting}
- lintFindingCount={lintModal?.length ?? findingsByFile.size}
- lintFindingsByFile={findingsByFile}
- lintHasError={hasLintError}
+ onLint={lint.handleLint}
+ linting={lint.linting}
+ lintFindingCount={lint.lintFindingCount}
+ lintFindingsByFile={lint.findingsByFile}
+ lintHasError={lint.hasLintError}
onAddAssetToTimeline={handleAddAssetAtPlayhead}
onAddCompositionToTimeline={handleAddCompositionAtPlayhead}
/>
@@ -577,8 +576,8 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: St
<StudioOverlays
projectId={projectId}
projectDir={fileManager.projectDir}
- lintModal={lintModal}
- closeLintModal={closeLintModal}
+ lintModal={lint.lintModal}
+ closeLintModal={lint.closeLintModal}
consoleErrors={consoleErrors}
clearConsoleErrors={() => setConsoleErrors(null)}
domEditSession={domEditSession}
diff --git a/packages/studio/src/components/sidebar/SidebarLintButton.test.tsx b/packages/studio/src/components/sidebar/SidebarLintButton.test.tsx
index 3df6a35cf9..3fa3953e53 100644
--- a/packages/studio/src/components/sidebar/SidebarLintButton.test.tsx
+++ b/packages/studio/src/components/sidebar/SidebarLintButton.test.tsx
@@ -44,6 +44,35 @@ describe("SidebarLintButton badge", () => {
expect(badge?.textContent).toContain("including errors");
});
+ it("pulses a few times and then holds still, so an idle Studio paints nothing", () => {
+ const badge = renderBadge(true);
+ expect(badge?.style.animationIterationCount).toBe("3");
+ });
+
+ it("pulses again when the finding count changes", () => {
+ const host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ const render = (findingCount: number) =>
+ act(() => {
+ root?.render(
+ <SidebarLintButton
+ onLint={vi.fn()}
+ linting={false}
+ findingCount={findingCount}
+ hasError
+ />,
+ );
+ });
+ render(2);
+ const first = host.querySelector("[data-lint-badge]");
+ render(2);
+ expect(host.querySelector("[data-lint-badge]")).toBe(first);
+ render(3);
+ // A new element restarts its CSS animation; a text change on the old one would not.
+ expect(host.querySelector("[data-lint-badge]")).not.toBe(first);
+ });
+
it("stays still when the findings are warnings only", () => {
const badge = renderBadge(false);
expect(badge?.dataset.lintBadge).toBe("warning");
diff --git a/packages/studio/src/components/sidebar/SidebarLintButton.tsx b/packages/studio/src/components/sidebar/SidebarLintButton.tsx
index 2e978deb06..de34e38486 100644
--- a/packages/studio/src/components/sidebar/SidebarLintButton.tsx
+++ b/packages/studio/src/components/sidebar/SidebarLintButton.tsx
@@ -1,3 +1,5 @@
+const ERROR_PULSES_BEFORE_IDLE = 3;
+
export function SidebarLintButton({
onLint,
linting,
@@ -31,7 +33,9 @@ export function SidebarLintButton({
{linting ? "Linting…" : "Lint"}
{!linting && findingCount != null && findingCount > 0 && (
<span
+ key={findingCount}
data-lint-badge={hasError ? "error" : "warning"}
+ style={hasError ? { animationIterationCount: ERROR_PULSES_BEFORE_IDLE } : undefined}
className={
hasError
? "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"
diff --git a/packages/studio/src/hooks/useLintModal.test.tsx b/packages/studio/src/hooks/useLintModal.test.tsx
index 44003580dc..15227a118d 100644
--- a/packages/studio/src/hooks/useLintModal.test.tsx
+++ b/packages/studio/src/hooks/useLintModal.test.tsx
@@ -69,6 +69,21 @@ describe("useLintModal hasLintError", () => {
});
});
+describe("useLintModal lintFindingCount", () => {
+ it("counts findings, not files, with the result open and after it closes", async () => {
+ const findings = ["a", "b", "c"].map((message) => ({
+ severity: "warning",
+ message,
+ file: "index.html",
+ }));
+ await mountWithLint(async () => ({ json: async () => ({ findings }) }));
+ expect(latest?.lintFindingCount).toBe(3);
+ act(() => latest?.closeLintModal());
+ expect(latest?.findingsByFile.size).toBe(1);
+ expect(latest?.lintFindingCount).toBe(3);
+ });
+});
+
describe("useLintModal background lint", () => {
it("waits for the live preview to boot before asking the server to lint", async () => {
usePlayerStore.setState({ previewBooted: false });
diff --git a/packages/studio/src/hooks/useLintModal.ts b/packages/studio/src/hooks/useLintModal.ts
index 7aed688186..b4466b9e09 100644
--- a/packages/studio/src/hooks/useLintModal.ts
+++ b/packages/studio/src/hooks/useLintModal.ts
@@ -98,8 +98,10 @@ 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");
+ // The badge counts findings, not files: the manual result when present, else the background one.
+ const badgeFindings = lintModal ?? backgroundFindings;
+ const lintFindingCount = badgeFindings.length;
+ const hasLintError = badgeFindings.some((f) => f.severity === "error");
// Sync lint findings directly to the player store — eliminates the
// mirroring useEffect that was previously in App.tsx.
@@ -115,6 +117,7 @@ export function useLintModal(projectId: string | null, refreshKey?: number) {
backgroundFindings,
findingsByElement,
findingsByFile,
+ lintFindingCount,
hasLintError,
};
}