Reports

#7815 · Repeated font completion events trigger redundant terminal measurements

BugPriority: MediumEffort: Lowui · perf · partial-reproGitHub issue

November 19, 2026 · trusted main df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2

Verdict: PARTIALLY REPRODUCED. Root-cause confidence: high for the redundant-measurement mechanism. The Safari/WebKit event cadence, actual style mutation rate, blank frames, and cursor behavior were not verified.

1. TL;DR

The report describes terminal flicker when WebKit uses the DOM renderer. Trusted main registers a font-loading listener that invokes a terminal measurement on every completion event, without checking which font faces completed or whether they were already measured. A direct test of the real application helpers delivered ten duplicate events for the same face and observed ten unnecessary measurements and twenty additional font-family writes. The same agent repeated the test in a second clean checkout and got the same failure. This confirms the event-amplification mechanism, not the complete browser rendering symptom: no usable browser backend was available, so this report deliberately remains partial.

2. Claims vs findings

ClaimFindingEvidence
Each font completion event forces another measurement.VerifiedThe real observer and measurement helpers produce 12 measurements: ready, first event, then ten duplicates.
Repeated events for the same loaded face keep changing font options.Verified at the helper boundary20 extra font-family assignments in each clean run, using a stable face object.
The DOM renderer rewrites styles after font options change.Supported by installed dependency sourcexterm 6.1.0-beta.292 subscribes to all option changes; its DOM handler updates dimensions and injects CSS.
WebKit itself repeatedly emits events around every 50 ms.UnverifiedThe test supplies events; it does not prove the browser schedules them.
Blank frames and missing cursor blink are caused by this loop.UnverifiedNo browser capture was possible. The separately reported initial-mount blank has not been investigated.
Chromium and WebGL are unaffected.UnverifiedNo cross-renderer or cross-browser comparison was performed.

3. Environment

4. Minimal reproduction

  1. Create a clean checkout at the recorded trusted commit:
    CHECKOUT=$(mktemp -d)
    git clone https://github.com/get-bb/bb.git "$CHECKOUT"
    cd "$CHECKOUT"
    git checkout --detach df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2
    pnpm install --frozen-lockfile --prefer-offline
  2. Save the following test as apps/app/src/components/thread/terminal/terminal-font-loading.repro.test.ts. It imports existing production exports, uses a real EventTarget, and models one stable loaded font face. The measurement callback uses the real measurement helper, with observable option setters and refresh recording instead of a browser renderer.
    import { expect, it, vi } from "vitest";
    import {
      forceTerminalFontMeasurement,
      observeTerminalFontLoading,
    } from "./ThreadTerminalView";
    
    it("does not remeasure an already loaded font face on repeated completion events", async () => {
      const loadedFace = { family: "Loaded Mono", status: "loaded" };
      const faces = new Set([loadedFace]);
      const events = new EventTarget();
      let finishLoading = () => {};
      const ready = new Promise<FontFaceSet>((resolve) => {
        finishLoading = () => resolve(fontSet as FontFaceSet);
      });
      const fontSet = Object.assign(events, {
        ready,
        [Symbol.iterator]: () => faces.values(),
      });
      let currentFamily = "Loaded Mono, monospace";
      let optionWrites = 0;
      const terminal = {
        options: {
          get fontFamily() {
            return currentFamily;
          },
          set fontFamily(value: string | undefined) {
            currentFamily = value ?? "";
            optionWrites += 1;
          },
        },
        rows: 24,
        clearTextureAtlas: vi.fn(),
        refresh: vi.fn(),
      };
      const dispose = observeTerminalFontLoading(fontSet, () => {
        forceTerminalFontMeasurement(terminal);
      });
      try {
        finishLoading();
        await fontSet.ready;
        expect(terminal.refresh).toHaveBeenCalledTimes(1);
        const dispatchLoadedFace = () => {
          const event = new Event("loadingdone");
          Object.defineProperty(event, "fontfaces", { value: [loadedFace] });
          fontSet.dispatchEvent(event);
        };
        dispatchLoadedFace();
        expect(terminal.refresh).toHaveBeenCalledTimes(2);
        const writesAfterFirstEvent = optionWrites;
        for (let eventIndex = 0; eventIndex < 10; eventIndex += 1) {
          dispatchLoadedFace();
        }
        console.log(JSON.stringify({
          repeatedEvents: 10,
          measurements: terminal.refresh.mock.calls.length,
          writesAfterFirstEvent,
          extraOptionWrites: optionWrites - writesAfterFirstEvent,
        }));
        expect(terminal.refresh).toHaveBeenCalledTimes(2);
        expect(optionWrites).toBe(writesAfterFirstEvent);
      } finally {
        dispose();
      }
    });
    
  3. Run through the repository's normal orchestration:
    pnpm exec turbo run test --filter=@bb/app -- src/components/thread/terminal/terminal-font-loading.repro.test.ts

Expected: the ready promise and first face event cause two measurements; repeated completion events for that same face do not cause additional option writes.

Actual, verbatim diagnostic and assertion, both runs:

{"repeatedEvents":10,"measurements":12,"writesAfterFirstEvent":4,"extraOptionWrites":20}
AssertionError: expected "vi.fn()" to be called 2 times, but got 12 times
Test Files  1 failed (1)
Tests  1 failed (1)

The assertion failure is the intended reproduction result, not a build/import failure. Events are delivered synchronously to make redundant work deterministic. No claim about a natural 50 ms browser loop follows from these synthetic events. No screenshot of blank terminal frames is provided because that symptom was not reproduced.

5. Root cause

The font-loading observer (lines 373–392) registers its unconditional refresh callback for every loadingdone event and also for fontSet.ready. It does not inspect event font faces or remember faces already handled:

fontSet.addEventListener("loadingdone", refresh);
void fontSet.ready.then(refresh);

The terminal's production caller (lines 875–884) turns every callback into forced measurement and a scheduled fit. Forced measurement (lines 360–371) deliberately changes the font family twice:

const fontFamily = terminal.options.fontFamily;
terminal.options.fontFamily = `${fontFamily} `;
terminal.options.fontFamily = fontFamily;
terminal.clearTextureAtlas();
terminal.refresh(0, terminal.rows - 1);

These are distinct option values, so xterm's OptionsService emits changes even though the final family is unchanged. In the installed dependency, src/browser/renderer/dom/DomRenderer.ts:91 subscribes to option changes; _handleOptionsChanged at line 493 calls _updateDimensions and _injectCss. Those methods replace style text (lines 171 and 312). This is source-level corroboration, not an observed browser mutation count.

The missing duplicate-face guard therefore amplifies repeated notifications into real renderer work. Whether that work causes WebKit to schedule the next notification, and whether paint suppression explains the blank frames, still requires a WebKit experiment.

6. Proposed fix

Make the existing observer coalesce completion notifications for already processed FontFace objects, recording a face before calling code that can trigger another font event. Preserve the initial ready measurement, measurements for genuinely new late-loading faces, and disposal behavior. Do not remove late-font support or rely on a timer that merely slows the loop. Add a regression for duplicate completion notifications alongside the existing lifecycle tests, then verify with WebKit and the real DOM renderer, including a late theme font.

No fix was attempted here: the overall issue is only partially reproduced and an open linked pull request already covers it.

7. Linked PR review

PR #7816 — static scope check only

GitHub metadata identifies this ready, open PR as closing #7815. Its read-only diff changes the existing observer and tests: it introduces per-face identity tracking before refresh and exercises repeated notifications and lifecycle behavior. That direction matches the verified amplification mechanism. The production caller and initial ready callback are retained. No linked branch was checked out, no PR test was run, and this is not a merge-readiness or visual-fix approval. In particular, initial mount blank frames and the actual WebKit cadence remain unverified.

8. Related work

PR #7816 is the existing implementation candidate. No duplicate PR was opened and no other issue was processed.

9. Verification

The same agent created a second clean temporary worktree at df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2, confirmed its clean status before adding the test, performed a separate frozen installation, copied the newly authored reproduction test byte-for-byte, and ran the same Turbo command. No server means no ports or instance data could be reused. The second run failed for the same intended assertion and produced the identical counts above. This is a repeated clean verification by the same agent, not independent verification.

RunTrusted production changesResult
Checkout ANoneExpected 2 refreshes; observed 12, with 20 redundant option writes.
Checkout BNoneSame expected failure and counts.
Existing terminal suite, checkout ANone28 tests passed in ThreadTerminalView.test.ts.

No correction to the helper-level claim was needed after the second run. The verdict is partial because browser-specific claims were intentionally not promoted to verified findings.

10. Appendix and boundaries

Existing coverage command:

pnpm exec turbo run test --filter=@bb/app -- src/components/thread/terminal/ThreadTerminalView.test.ts
Test Files  1 passed (1)
Tests  28 passed (28)

The initial full Turbo build encountered missing plugin SDK runtime entries in the GitHub plugin. The documented SDK type build and its runtime build were then run before retrying the full build. The retry succeeded: 72 successful tasks out of 72, including the app and desktop builds. This bootstrap condition is not evidence for the reported bug. Reproduction and existing terminal tests also completed through Turbo.

The issue content and linked diff were treated as untrusted claims. No issue-provided command, script, patch, URL, branch, or test was executed. The test above was authored from trusted main's observer and measurement contracts before reading the linked diff. Raw local logs, reproduction files, temporary paths, and machine identifiers are not published. No new dependency, production edit, or target-repository commit was created.