#7332 · Code-fence host schedules a synchronous portal follow-up commit
PARTIALLY REPRODUCED · Root-cause confidence: medium
1. TL;DR
A plugin-rendered fence is initially an empty placeholder. The host receives its content in a layout effect, then performs another synchronous React commit to render the portal, even when the plugin produces no visible output. A deterministic test confirms that behavior twice on the current trusted main commit. This establishes the extra commit in the fence subsystem, not the reported wall-clock regression: no browser trace or two-pane layout-duration comparison was collected. The claimed 1.2–1.3 second cost and repeated ancestor row measurements remain unverified, so no production fix or PR is proposed as already validated.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| A renderer that produces nothing still creates a follow-up commit. | Verified at the host boundary | The unclaimed control has phase ["mount"]. The claimed empty renderer has ["mount", "nested-update"] in both clean checkouts. |
| The attach call changes React state. | Refined for current main | attach mutates a Map and places a container. The separate update call changes block from null and calls the reducer, scheduling the React update. |
| Every fence forces a separate full-page layout and reruns ancestor row effects. | Unverified | The test exercises the real host/placeholder/slot boundary, not timeline ancestors. A nested subtree commit alone does not establish that ancestors rendered again or that the browser performed layout. |
| Two panes add 1.2–1.3 seconds, including most of the plugin cost. | Unverified | No Chromium performance trace, Long Animation Frame timings, or comparable two-pane fixture was measured in this investigation. |
| Removing registration avoids the host follow-up. | Verified in the minimal boundary control only | The same placeholder and host with an empty registry mount once and retain the original content. This is not an end-to-end uninstall benchmark. |
3. Environment
- Trusted public repository: get-bb/bb; main commit
f39378659af3e75b0aa35788e70e5a0c086a4c34. Main was fetched from the canonical repository and checked again after both runs. - Linux 4.19.0-gvisor, Node v22.19.0, pnpm 9.15.0, Vitest 4.1.12, jsdom. Workspace Plugin SDK version 0.6.137.
- Two distinct detached worktrees were created clean at the recorded commit. Production source was not edited. Only locally authored test changes were introduced.
- No real user threads, plugin installation, runtime store, model providers, HTTP servers, ports, or persistent data directories were used. No screenshot is supplied: this is commit-scheduling evidence, not visual or browser-timing evidence.
- Frozen installs succeeded. The initial all-workspace build failed because the GitHub plugin reached unbuilt SDK runtime entries. Building the existing SDK first and then the app succeeded in both worktrees. That build-order failure is not attributed to this issue.
4. Minimal reproduction
The test was authored from the trusted host, placeholder, registry, and existing slot fixture contracts. It does not run the issue's plugin sample, scripts, or any linked branch. It uses an inert original element to avoid unrelated code-block UI effects masking the fence-specific commit.
- Create a clean checkout and install/build the existing workspace:
git clone https://github.com/get-bb/bb.git bb-7332 cd bb-7332 git checkout --detach f39378659af3e75b0aa35788e70e5a0c086a4c34 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@bb/app
- Save the complete reproduction test as
apps/app/src/components/ui/markdown-code-fence-commit-repro.test.tsx. - Run:
pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-code-fence-commit-repro.test.tsx
- Expect the no-follow-up assertion to fail on this base, after the unclaimed control and DOM assertions pass:
AssertionError: expected [ 'mount', 'nested-update' ] to deeply equal [ 'mount' ] - Expected + Received [ "mount", + "nested-update", ]
This is an intentionally failing regression candidate, not a passing benchmark. It neither measures elapsed time nor installs an external plugin. The host still invokes its normal plugin crash boundary and portal path.
Complete reproduction test
// @vitest-environment jsdom
import { Profiler } from "react";
import { cleanup, render } from "@testing-library/react";
import { afterEach, expect, it } from "vitest";
import type { PluginCodeFenceRendererSlot } from "@/lib/plugin-slots";
import {
buildCodeFenceRendererRegistry,
CodeFencePlaceholder,
CodeFenceRendererHost,
type CodeFenceRendererRegistry,
} from "./markdown-code-fence-renderers";
function EmptyFence() {
return null;
}
const registration: PluginCodeFenceRendererSlot = {
id: "commit-probe",
pluginId: "repro",
generation: 1,
languages: ["ui"],
component: EmptyFence,
};
function fenceTree(registry: CodeFenceRendererRegistry) {
return (
<CodeFenceRendererHost
registry={registry}
message={{ id: "message", threadId: "thread", turnId: null, projectId: null }}
streaming={false}
>
Before
<CodeFencePlaceholder
closed={true}
code="sample payload"
language="ui"
offset={0}
original={<pre>sample payload</pre>}
/>
After
</CodeFenceRendererHost>
);
}
afterEach(cleanup);
it("mounts a null fence renderer without a synchronous follow-up commit", () => {
const controlPhases: string[] = [];
const control = render(
<Profiler id="control" onRender={(_id, phase) => controlPhases.push(phase)}>
{fenceTree(buildCodeFenceRendererRegistry([]))}
</Profiler>,
);
expect(control.container.textContent).toContain("sample payload");
control.unmount();
const rendererPhases: string[] = [];
const renderer = render(
<Profiler id="renderer" onRender={(_id, phase) => rendererPhases.push(phase)}>
{fenceTree(buildCodeFenceRendererRegistry([registration]))}
</Profiler>,
);
expect(renderer.container.textContent).toContain("Before");
expect(renderer.container.textContent).not.toContain("sample payload");
expect(controlPhases).toEqual(["mount"]);
expect(rendererPhases).toEqual(controlPhases);
});
5. Root cause
The host starts with an empty entry Map and a reducer. On the first render there are no entries to turn into portals. The placeholder then attaches and updates in layout effects:
host.attach(offset, element);
...
host.update(offset, { closed, code, language, original });
attach creates an entry whose block is null. update replaces that block and always schedules the first follow-up:
const previous = entry.block;
entry.block = block;
if (
previous === null ||
previous.code !== block.code ||
previous.closed !== block.closed ||
previous.language !== block.language
) {
rerender();
}
The follow-up render materializes the portal, even if the plugin component itself returns null. This causally explains the observed nested-update phase. It does not establish a 1.2-second delay, one commit per fence, ancestor layout-effect execution, or full-page reflow.
Root-cause confidence is high for this narrow bridge lifecycle and medium for its relationship to the full reported performance defect. The current timeline already has a ResizeObserver measurement path; the more general suggestion to replace all measurement effects is not a validated fix.
6. Proposed fix / next experiment
Next, create a synthetic two-pane fixture on current main and capture Chromium traces with and without the registration, attributing layout work to exact stacks. Separate initial code-block UI updates from host updates. If the portal lifecycle is responsible, move enough fence metadata into the initial render to eliminate the extra update, while retaining per-language indices, streaming state across markdown-region transitions, Original fallback, crash isolation, and delayed detach cleanup. Those invariants are already exercised by the existing renderer suite; a one-line effect deferral is not established as safe.
No fix PR: only the scheduling mechanism was reproduced, not the full performance defect on trusted main. The rule's reproduction prerequisite for a simple production fix is therefore not met. No fix branch was pushed. No linked or matching open PR was found in the issue timeline or the issue-number search.
7. Verification
The same agent repeated the test in a second newly created clean detached checkout of the recorded base. It had its own frozen install and app build; it did not reuse a running app or runtime data. Only the locally authored reproduction files were copied. No servers were needed, so there were no ports or application data directories to reuse.
| Check | Result |
|---|---|
| First checkout, 2026-11-10 02:22:20 UTC; focused Turbo command above | Expected failure at rendererPhases comparison, control passed; mount + nested-update. Sanitized log. |
| Second checkout, 2026-11-10 02:22:32 UTC; same focused command | Same expected failure at the same assertion; control passed. Sanitized log. |
| Existing code-fence renderer tests, excluding the exploratory regression | 24 passed. Covers streaming identity, fence ordering, language collisions, removal, status, and fallback. Log. |
| Diff hygiene | git diff --check passed for the local reproduction changes. No production edits, dependency additions, or runtime data access. |
Report correction during investigation: a first exploratory Profiler around the full assistant/Markdown tree also observed a nested update in the no-renderer control. That was not evidence for a renderer-specific slowdown. The final test isolates the actual host and placeholder with an inert original element, where the control mounts once and the claimed renderer schedules the additional commit. The broader claims remain explicitly unverified. This repeat run is not described as independent verification.
8. Related issues
#5268 requested the original fence slot. #5985 concerns rendering plugin fences inside plugin Markdown. These were discovered through repository issue search; neither establishes a fix for this performance report.
9. Appendix / command record
Read-only GitHub metadata queries inspected the issue, comments (none), Type/fields/labels, allowed classifications, comparable issues, and open cross-referenced PRs (none). Classification writes used the supplied SlopCop GitHub wrapper. The issue's content was treated only as untrusted claims; its suggestions, executable snippets, and links were not executed or fetched as instructions.
git fetch https://github.com/get-bb/bb.git main git rev-parse FETCH_HEAD git worktree add --detach <first-temp-checkout> f39378659af3e75b0aa35788e70e5a0c086a4c34 git worktree add --detach <second-temp-checkout> f39378659af3e75b0aa35788e70e5a0c086a4c34 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@bb/app pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-code-fence-renderers.test.tsx -t 'mounts a null fence renderer' pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-code-fence-renderers.test.tsx -t '^(?!.*mounts a null fence renderer)' pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-code-fence-commit-repro.test.tsx git diff --check git ls-remote https://github.com/get-bb/bb.git refs/heads/main
The initial all-workspace build was attempted only in the first checkout. Both checkouts then built the SDK and app successfully. The exploratory renderer-suite modification was not proposed as a production change; the downloadable standalone test is the canonical final reproduction artifact.