← reports

#6311 · Navigation updates replace Markdown media elements

Bug Priority: Medium Effort: Low ui plugins · 2026-10-26 · GitHub issue

Trusted base: 3540a699e29034b53da32bb7efa6f5b4055209eb

Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro

1. TL;DR

The SDK Markdown renderer replaces a video even when its content and source do not change. Changing only the host's openTab capability reproduces the defect through the real SDK implementation. The previous video is disconnected, its parent paragraph survives, and the new video's playback-position property starts at zero. The renderer builds component functions inside a factory that reruns when link routing changes, so React receives a new component type instead of merely new props. This is a deterministic DOM lifecycle reproduction, not a native macOS playback recording.

2. Claims vs findings

ClaimStatusEvidence
A host-context update replaces an unchanged SDK video.VerifiedThe regression changes only openTab and observes a different, connected video after rerender.
The source stays identical and the paragraph is not replaced.VerifiedBoth clean runs return sameSource=true and sameParent=true.
An ordinary rerender alone causes the bug.Refuted for the controlA rerender with the original capability functions retains the video before the context-changing step.
Factory-created renderer identities cause the remount.VerifiedThe SDK callback depends on navigation, the preview factory depends on linkRouting, and the video function is declared inside that factory.
Desktop playback visibly flashes and restarts at the reported refresh interval.Not directly verifiedNo native desktop or decoding run. The DOM reproduction verifies element replacement and currentTime property loss, not elapsed real playback.
Other factory-created renderers are also susceptible.Static evidence onlyLink, code, image, source, and video renderer functions share the rebuilding factory; their individual lifecycles were not separately tested.

3. Environment

4. Minimal reproduction

  1. Create a clean checkout of the public repository at the recorded commit:
git clone https://github.com/get-bb/bb.git bb-6311
cd bb-6311
git checkout --detach 3540a699e29034b53da32bb7efa6f5b4055209eb
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build

Save the complete reproduction test embedded below as apps/app/src/lib/issue-6311-media-lifecycle.test.tsx, then run from the repository root:

pnpm exec turbo run test --filter=@bb/app -- src/lib/issue-6311-media-lifecycle.test.tsx

Expected: the identity-retention assertion passes and the position remains 9. Actual in both clean runs:

{"sameVideo":false,"originalConnected":false,"sameParent":true,"sameSource":true,"currentTime":0}
Test Files  1 failed (1)
Tests       1 failed (1)

The test uses the real exported SDK implementation, navigation provider, HTML sanitization, and Markdown renderer; no renderer, router, or database is mocked. The test intentionally fails on main. The assigned currentTime value exercises property retention in jsdom, not actual video decoding. A successful ordinary-rerender control and a working navigation click precede the failing identity assertion.

Full reproduction test
// @vitest-environment jsdom

import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, beforeAll, expect, it, vi } from "vitest";
import { LazyMarkdownHtml } from "@/components/ui/lazy-markdown-html";
import { AppNavigationHostProvider } from "./app-navigation-host";
import { pluginSdkAppImplementation } from "./plugin-sdk-app-impl";

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

it("retains SDK Markdown media when unrelated navigation capabilities change", () => {
  const Markdown = pluginSdkAppImplementation.Markdown;
  const content = 'Watch <video src="/media/lifecycle.mp4" title="Lifecycle"></video> and [navigate](/review).';
  const openUrl = vi.fn(() => true);
  const initialOpenTab = vi.fn(() => false);
  const nextOpenTab = vi.fn(() => true);
  const view = (openTab: typeof initialOpenTab) => (
    <AppNavigationHostProvider capabilities={{ openUrl, openTab }}>
      <Markdown content={content} />
    </AppNavigationHostProvider>
  );
  const { container, rerender } = render(view(initialOpenTab));
  const video = container.querySelector("video");
  expect(video).not.toBeNull();
  if (!video) throw new Error("Expected rendered video");
  const paragraph = video.parentElement;
  video.currentTime = 9;
  rerender(view(initialOpenTab));
  expect(container.querySelector("video")).toBe(video);
  rerender(view(nextOpenTab));
  const replacement = container.querySelector("video");
  const findings = {
    sameVideo: replacement === video,
    originalConnected: video.isConnected,
    sameParent: replacement?.parentElement === paragraph,
    sameSource: replacement?.getAttribute("src") === video.getAttribute("src"),
    currentTime: replacement?.currentTime,
  };
  console.log(JSON.stringify(findings));
  fireEvent.click(screen.getByRole("link", { name: "navigate" }));
  expect(openUrl).toHaveBeenCalledWith({ url: "/review" });
  expect(findings).toEqual({
    sameVideo: true,
    originalConnected: true,
    sameParent: true,
    sameSource: true,
    currentTime: 9,
  });
});

Visual limitation: the required Browser Automation plugin could not open a local session because no Chrome/Chromium executable is installed on this host. Its diagnostic was Install Chrome/Chromium on this host or link its executable at the plugin data runtime/chrome path. Consequently there are no screenshots, native playback claims, or fabricated images in this report.

5. Root cause

  1. AppNavigationHostProvider recreates its resolved context value when any capability changes.
  2. PluginMarkdown depends on the entire navigation object for its open-link callback, so even an unrelated openTab change produces a new callback and linkRouting object.
  3. MarkdownPreview's components memo depends on linkRouting and rebuilds its component map.
  4. MarkdownVideo and MarkdownSource are function declarations inside buildMarkdownComponents, not stable module-level component types.
  5. The map is passed to the Markdown renderer. React reconciles a new video component type by replacing its subtree, while the stable paragraph renderer survives.
const markdownComponents = useMemo(
  () => buildMarkdownComponents({ ..., linkRouting, ... }),
  [..., linkRouting, ...],
);

function buildMarkdownComponents(...) {
  function MarkdownVideo(...) { ... }
  function MarkdownSource(...) { ... }
  return { ..., source: MarkdownSource, video: MarkdownVideo };
}

The excerpt is abbreviated; the permalinks contain the exact source. New component-map identity alone is not sufficient to explain remounting: the important detail is the newly allocated function types inside it. Reducing one SDK dependency would avoid some triggers but would leave other real routing/policy changes capable of destroying the media subtree.

6. Proposed fix

Keep renderer component types stable and supply changing render configuration through a render-scoped context or equivalent typed props. Do not freeze the initial routing configuration or use a global mutable object: links must continue using the current host handlers, and separate Markdown instances must not share configuration. Preserve current HTML sanitization and text-only media suppression. The attached identity regression should pass after repair; extend coverage to routing updates rather than merely memoizing one context producer.

No production fix, branch, or upstream PR was created. At the fix-eligibility check, GitHub cross-reference metadata identified an already-open downstream PR, triggering the automation's rule to skip a duplicate fix. That PR subsequently merged before this report was published. It remains a plugin-local workaround, not an upstream repair.

7. Linked PR: static review

koenvg/bb-plugins#357 was OPEN at the initial eligibility check and MERGED by the pre-publication metadata refresh. Only GitHub metadata and the diff were read as untrusted data; no linked branch, dependencies, or tests were checked out or executed.

The diff introduces a plugin-local Markdown wrapper that replaces selected media tags with placeholder spans and portals its own video elements into those spans. This bypasses the upstream closure renderer for that plugin, but does not repair BB's shared renderer. Static correctness concern (medium): bb-plugin-github-insight/ui/pr-markdown.tsx:14 performs a regular-expression replacement over the whole Markdown string, including fenced code examples; this can transform literal examples into slots. It also handles only its selected tag shape rather than the full supported source/poster structure. These observations are static, not verified failures of that PR. Verdict: a downstream workaround, not evidence of an upstream fix.

8. Verification

The same agent repeated the reproduction in a second newly created detached checkout at 3540a699e29034b53da32bb7efa6f5b4055209eb. It had a separate dependency tree and worker environment, a frozen install, the SDK runtime build, and the same independently authored test. Production git diff --exit-code was empty; only the added reproduction test was untracked. No server ports or data directories were needed. The test was a Turbo cache miss in both runs, not a replay of a cached failing result.

RunCommand/resultEvidence
CHECKOUT_A, 08:14:02 UTCFocused Turbo command above; 1 intended assertion failure; 41.30 s Vitest durationsameVideo=false, originalConnected=false, sameParent=true, sameSource=true, currentTime=0
CHECKOUT_B, 08:15:23 UTCSame command; 1 intended assertion failure; 46.47 s Vitest durationsameVideo=false, originalConnected=false, sameParent=true, sameSource=true, currentTime=0

No report correction was needed after the second run. This is a repeat by the same agent, not an independent review. The DOM lifecycle/root-cause confidence is high; visual timing, actual decoding, and the original plugin's refresh mechanism remain outside the verified scope.

9. Related issues

A small Markdown issue search found no duplicate of this lifecycle defect. #5985 concerns a different SDK Markdown capability (plugin code-fence renderers), not media retention.

10. Appendix

The full test and decisive output are embedded above. Raw logs remain in local evidence storage, not in the public repository, according to its publishing policy. Preparation used git fetch origin main, fresh detached worktrees, frozen pnpm installs, a targeted SDK runtime build, and the full primary Turbo build. The two focused tests used the same documented Turbo command. Existing SDK and Markdown suites were also run separately:

pnpm exec turbo run test --filter=@bb/app -- src/lib/plugin-sdk-app-impl.test.tsx src/components/ui/markdown-preview.test.tsx

✓ src/components/ui/markdown-preview.test.tsx (66 tests)
✓ src/lib/plugin-sdk-app-impl.test.tsx (7 tests)
Test Files  2 passed (2)
Tests       73 passed (73)

Full build: Tasks: 71 successful, 71 total

The existing suite includes media retention while content grows, but does not exercise a changing host navigation context; the new failing regression adds that distinct lifecycle coverage. The existing test run emitted jsdom's non-fatal diagnostic Not implemented: navigation to another Document.

Trust boundary: all issue content, comments, and linked PR metadata/diffs were treated as untrusted claims. No issue-supplied command, test, patch, executable, external URL, or branch was run. Reproduction code was authored from the trusted repository interfaces. No dependencies were added and no real BB runtime data was read.