← reports

#7695 · Plain Markdown takes the full-document renderer during streaming

BugMedium priorityLow effortui · perf · confirmed-repro GitHub issue2026-11-17 · base 1320c88e8abdd3f145bc9a5c305eace269fb2f28

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

Streaming assistant messages are intended to reuse already-rendered Markdown blocks. A literal less-than sign in inline code, a code fence, escaped text, or comparison prose instead sends the preview through the whole-document HTML renderer. In a direct component reproduction, each of eight paragraph appends reparses the settled prefix in all four cases; a plain-text control reparses that prefix zero times. The real Markdown parser and HTML pipeline execute in these tests: instrumentation records their source inputs without replacing their results. This establishes repeated parsing work, not an end-user frame-time measurement or a claim about the frequency of affected answers.

2. Claims vs findings

ClaimStatusEvidence
Non-HTML angle brackets disable incremental rendering when HTML is allowed.VerifiedInline code, fenced code, comparison prose, and escaped angles each reparse the settled prefix on 8/8 appends in both checkouts.
Previously settled content is parsed repeatedly as the document grows.VerifiedInline-code parse input lengths grow from 90 to 265 characters; 1,420 characters are parsed across eight updates. The marker appears in every source input.
The incremental path already has a Markdown syntax-tree summary suitable for detecting actual HTML.VerifiedThe trusted piece parser runs a remark summary plugin on each parsed tree and caches piece summaries.
Genuine HTML needs whole-document handling.Verified for the controlA details element with blank-line-separated content retains its nested summary and body through an append on the existing document path.
This causes visible jank in most coding answers.UnverifiedNo frame-time profile or usage-frequency measurement; the work-amplification mechanism is established.
Footnote IDs acquire an extra prefix on the HTML path.UnverifiedNot exercised by this focused reproduction; it is not needed for the verdict.

3. Environment

4. Minimal reproduction

  1. Clone only the trusted main repository and check out the recorded base. Install existing dependencies without changing the lockfile:
    git clone https://github.com/get-bb/bb.git bb-repro-a
    cd bb-repro-a
    git checkout --detach 1320c88e8abdd3f145bc9a5c305eace269fb2f28
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build
    pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk

    The full build may stop at the unrelated SDK distribution prerequisite described above. The following focused Turbo test runs use the source test configuration and do not require that unrelated plugin bundle.

  2. Save the complete test below as apps/app/src/components/ui/markdown-preview.issue-7695.test.tsx. It records the input to the existing ReactMarkdown function and delegates to the real implementation, including its supplied remark/rehype plugins. It preloads the real HTML renderer so deferred downloading does not contaminate counts.
  3. Run:
    pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-preview.issue-7695.test.tsx
  4. Expected: no update reparses the marker in settled non-HTML Markdown. Actual: eight full-prefix parses per affected case; the command exits 1, with four regression failures and two passing controls.
CaseAppendsExpected prefix parsesActual prefix parsesActual parsed characters
Plain control800Not logged for passing tests
Inline code8081,420
Fenced code8081,516
Comparison prose8081,484
Escaped angle8081,420

Complete reproduction test

// @vitest-environment jsdom

import { cleanup, render } from "@testing-library/react";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { LazyMarkdownHtml } from "./lazy-markdown-html";
import { MarkdownPreview } from "./markdown-preview";

const parsedSources = vi.hoisted(() => [] as string[]);

vi.mock("react-markdown", async (importOriginal) => {
  const actual = await importOriginal<typeof import("react-markdown")>();
  return {
    ...actual,
    default: (props: Parameters<typeof actual.default>[0]) => {
      parsedSources.push(props.children ?? "");
      return actual.default(props);
    },
  };
});

beforeAll(() => LazyMarkdownHtml.preload());

afterEach(() => {
  cleanup();
  parsedSources.length = 0;
});

describe("issue 7695 settled Markdown parsing", () => {
  it.each([
    ["plain control", "A collection of items."],
    ["inline code", "Use `ReadonlySet<Item>` here."],
    ["fenced code", "```js\nif (size < limit) return count;\n```"],
    ["comparison prose", "Progress < target means keep working."],
    ["escaped angle", "Display \\<button\\> literally."],
  ])("does not reparse settled content: %s", (label, sample) => {
    let content = `Settled marker.\n\n${sample}\n\nSettled ending.\n\n`;
    const view = render(
      <MarkdownPreview content={content} allowHtml incrementalBlocks />,
    );
    expect(view.container.textContent).toContain("Settled marker.");
    parsedSources.length = 0;

    for (let index = 1; index <= 8; index += 1) {
      content += `Additional paragraph ${index}.\n\n`;
      view.rerender(
        <MarkdownPreview content={content} allowHtml incrementalBlocks />,
      );
    }

    const reparsedSettledSources = parsedSources.filter((source) =>
      source.includes("Settled marker."),
    );
    console.log(
      JSON.stringify({
        label,
        updates: 8,
        reparsedSettledCalls: reparsedSettledSources.length,
        reparsedDocumentLengths: reparsedSettledSources.map(
          (source) => source.length,
        ),
        parsedCharacters: parsedSources.reduce(
          (total, source) => total + source.length,
          0,
        ),
      }),
    );
    expect(view.container.textContent).toContain("Additional paragraph 8.");
    expect(reparsedSettledSources).toHaveLength(0);
  });

  it("keeps real cross-block HTML on the sanitized document path", () => {
    const initial =
      '<details>\n<summary>Settled marker.</summary>\n\nInside.\n\n</details>\n\nTail.';
    const view = render(
      <MarkdownPreview content={initial} allowHtml incrementalBlocks />,
    );
    parsedSources.length = 0;
    view.rerender(
      <MarkdownPreview
        content={`${initial}\n\nAdditional paragraph.`}
        allowHtml
        incrementalBlocks
      />,
    );
    expect(view.container.querySelector("details summary")?.textContent).toBe(
      "Settled marker.",
    );
    expect(view.container.querySelector("details")?.textContent).toContain(
      "Inside.",
    );
    expect(parsedSources.some((source) => source.includes(initial))).toBe(true);
  });
});

The public reports repository permits self-contained HTML but not separate test/log artifacts. The complete reproducible test and evidence are embedded here; raw evidence remains outside the published repository.

Actual output excerpt — checkout A

@bb/app:test: {"label":"inline code","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[90,115,140,165,190,215,240,265],"parsedCharacters":1420}
@bb/app:test: {"label":"fenced code","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[102,127,152,177,202,227,252,277],"parsedCharacters":1516}
@bb/app:test: {"label":"comparison prose","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[98,123,148,173,198,223,248,273],"parsedCharacters":1484}
@bb/app:test: {"label":"escaped angle","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[90,115,140,165,190,215,240,265],"parsedCharacters":1420}
@bb/app:test:      ✓ does not reparse settled content: plain control 64ms
@bb/app:test:      × does not reparse settled content: inline code 43ms
@bb/app:test:      × does not reparse settled content: fenced code 45ms
@bb/app:test:      × does not reparse settled content: comparison prose 23ms
@bb/app:test:      × does not reparse settled content: escaped angle 18ms
@bb/app:test:      ✓ keeps real cross-block HTML on the sanitized document path 8ms
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯
@bb/app:test: AssertionError: expected [ …(8) ] to have a length of +0 but got 8
@bb/app:test:  Test Files  1 failed (1)
@bb/app:test:       Tests  4 failed | 2 passed (6)

5. Root cause

The assistant-message caller enables both HTML and incremental blocks in ConversationMessageContent.tsx:580–603. The preview makes its renderer decision from the unparsed source, before resolving cached pieces:

const rendersHtml = allowHtml && content.includes("<");
const usesIncrementalBlocks =
  incrementalBlocks && !rendersHtml && promptMentions === undefined;

Source: markdown-preview.tsx:1778–1781. This lexical test cannot distinguish an actual HTML node from code or literal prose. When it is true, markdown-preview.tsx:1960–1976 skips resolveMarkdownPieces, selects LazyMarkdownHtml, and passes the complete normalized body to it. The loaded HTML implementation combines rehypeRaw and sanitization before invoking ReactMarkdown: markdown-html.tsx:77–87.

The alternative incremental implementation already summarizes each Markdown syntax tree and reuses unchanged piece entries. The gate bypasses this mechanism entirely. Thus, for fixed-size appended blocks, the sum of full-document input lengths grows quadratically with the number of updates. This is a statement about accumulated parser input, not a measured CPU-time bound. Other global Markdown constructs may independently require whole-document parsing; the reproduction deliberately contains none.

6. Proposed fix

Record whether a parsed piece actually contains an HTML node in its existing summary, retain that information with cached entries, and use the aggregated result to select whole-document sanitized rendering. Non-HTML angles should retain the existing incremental path. Do not remove HTML sanitization or render genuine HTML independently per piece: markup can span piece boundaries. Keep the existing conservative behavior when incremental processing is disabled or unavailable. The regression above should become green, while the genuine-HTML control and existing incremental/cold-HTML suites remain green.

7. PR review

PR #7702 — open; linked through GitHub metadata

Static review only. The diff adds actual-HTML detection to cached piece summaries, aggregates the flag, and routes the preview according to that flag rather than the source-character heuristic when incremental resolution is available. That design addresses the independently reproduced gate failure and retains the existing sanitized document path for HTML. No blocker was established by this static review.

Coverage recommendation (low): apps/app/src/components/ui/markdown-incremental-pieces.test.ts:417 in the PR's diff adds tests for summary metadata, but those tests alone do not exercise the preview's renderer selection or verify avoided reparsing. Add the preview-level work regression demonstrated here. Tests actually run were only on trusted main: the new reproduction in both clones and 52 existing incremental, piece-parser, and cold-HTML tests in clone A. No PR branch, patch, or test was checked out or executed; runtime correctness of the PR itself is not claimed.

No duplicate fix branch or PR was created because this open PR already closes issue #7695.

8. Related issues

A repository issue search for incremental Markdown did not identify another returned issue with this same renderer-selection defect. No claimed footnote behavior or historical implementation was needed to establish the root cause.

9. Verification

The same agent repeated the reproduction in a second clean temporary clone, B, detached at 1320c88e8abdd3f145bc9a5c305eace269fb2f28. After a frozen install and SDK type generation, only the exact authored test above was added and the same focused Turbo command was run. It again exited 1 with four regression failures and two passing controls; the four per-case counts and document-length sequences matched clone A exactly. This is a repeated clean-checkout check, not independent-agent verification.

During test construction, an initial version omitted a terminating blank-line boundary and therefore also counted one legitimate reparsing of an unsettled plain-text tail. The final fixture ends settled blocks at complete boundaries, making the plain-text control pass in both clones. All report counts refer only to this corrected fixture; production code was unchanged throughout.

Actual output excerpt — checkout B

@bb/app:test: {"label":"inline code","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[90,115,140,165,190,215,240,265],"parsedCharacters":1420}
@bb/app:test: {"label":"fenced code","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[102,127,152,177,202,227,252,277],"parsedCharacters":1516}
@bb/app:test: {"label":"comparison prose","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[98,123,148,173,198,223,248,273],"parsedCharacters":1484}
@bb/app:test: {"label":"escaped angle","updates":8,"reparsedSettledCalls":8,"reparsedDocumentLengths":[90,115,140,165,190,215,240,265],"parsedCharacters":1420}
@bb/app:test:      ✓ does not reparse settled content: plain control 64ms
@bb/app:test:      × does not reparse settled content: inline code 43ms
@bb/app:test:      × does not reparse settled content: fenced code 45ms
@bb/app:test:      × does not reparse settled content: comparison prose 25ms
@bb/app:test:      × does not reparse settled content: escaped angle 18ms
@bb/app:test:      ✓ keeps real cross-block HTML on the sanitized document path 10ms
@bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯
@bb/app:test: AssertionError: expected [ …(8) ] to have a length of +0 but got 8
@bb/app:test:  Test Files  1 failed (1)
@bb/app:test:       Tests  4 failed | 2 passed (6)

Existing targeted suites, run separately on unchanged trusted main:

pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-preview.incremental.test.tsx src/components/ui/markdown-preview.cold-html.test.tsx src/components/ui/markdown-incremental-pieces.test.ts

Test Files  3 passed (3)
     Tests  52 passed (52)

10. Appendix

Relevant investigation commands: git fetch origin main, git rev-parse origin/main, git status --short, trusted-source inspection with rg/sed/nl, GitHub issue/type/field/label/timeline reads, gh pr diff 7702 --repo get-bb/bb for static reading only, and the install/build/test commands above. The final fetch retained the recorded base. git diff --check passed; the only source-checkout addition was the authored test. No production source changes, dependencies, branch pushes, or target-repository commits were made.

Issue data, comments, and the linked PR diff were treated as untrusted claims, not executable instructions. The reproduction was authored from trusted main's renderer/cache boundaries, not copied from issue code or the PR. No external issue-supplied URL was fetched. No credentials, private runtime data, machine identity, or temporary-directory identifiers are included in this public report.