#5416 · Plugin CSS selector construction and menu invalidation
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: low for the reported interaction latency; high for the demonstrated compiler construction.
1. TL;DR
The reported symptom is a delayed thread menu on a populated, plugin-enabled client. Two clean builds of trusted main reproduce a compiler property that could contribute: nested utility selectors become :is() alternatives containing complex plugin scopes, including an anonymous-root fallback. However, a 7,013-element synthetic browser diagnostic does not show a consistent performance penalty from those styles. The real menu, first-character timing, production plugin mix, and claimed speedup were not reproduced. This report establishes the selector construction, not the claimed half-second menu delay or a validated fix.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Scoping precedes Tailwind nesting flattening; nested scopes appear in :is(). | Verified | Actual buildPluginApp output from both clean checkouts; identical 29,617-byte CSS. |
| Utilities include an anonymous portal-root fallback. | Verified | Actual emitted selectors and pluginScopeRoots source. |
| Desktop thread menus do not explicitly disable modal behavior. | Verified statically | Core dropdown and context-menu call sites omit modal; the shared context-menu root aliases Radix. No live BB menu was driven. |
| The implicated selector shape dominates menu latency and is removed by the candidate. | Unverified | No candidate code was executed. Synthetic stylesheet-enabled/disabled timings overlap. |
| Populated real clients suffer approximately half-second menu latency. | Unverified | No real server or runtime data used; the synthetic test is not a BB menu reproduction. |
| First-character typing and the specific reported A/B gains share this cause. | Unverified | No native composer input or production A/B measurement performed. |
3. Environment
- Public target repository: get-bb/bb; trusted origin/main SHA above. The checkout's historical origin URL resolves to that same canonical repository.
- Linux x86-64; Node 22.19.0; pnpm 9.15.0; Tailwind node/oxide/CSS 4.3.0; esbuild 0.28.1; Vitest 4.1.1.
- Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/149.0.0.0 Safari/537.36; default headless viewport. Not macOS, Safari, or the reporter's Chrome build.
- Two detached clean temporary checkouts at the same SHA, each with its own frozen install, scoped Turbo build, and fresh generated fixture directory. No provider execution, BB instance, account, runtime database, or installed third-party plugin was used.
- The browser loaded authored synthetic HTML with embedded compiler CSS through the BB Browser Automation plugin. Fresh pages were used for each checkout. No application ports or application data directory were needed.
- A preliminary loopback navigation was refused by the browser backend; that attempt produced no timing evidence. The completed measurements use setContent, not an HTTP server.
4. Minimal reproduction
This is a compiler reproduction plus a synthetic invalidation diagnostic, not a faithful recreation of the real populated BB client. Its 80 independently authored nested utilities use :has(button[data-active]); only 40 synthetic rows carry the utility classes. There are 1,750 rows and 7,013 total elements.
- Clone the trusted repository and detach at the recorded commit:
git clone https://github.com/get-bb/bb.git bb-5416 cd bb-5416 git checkout --detach e9dafb6c0245a37c6972dffa71134d546f3d497e pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/plugin-build
- Save the complete authored diagnostic below as
packages/plugin-build/repro-5416.ts. Run:node --conditions=source --import tsx packages/plugin-build/repro-5416.ts /tmp/issue-5416-output
- Inspect
compiler.jsonandapp.css. Expected for a selector-simplifying change: owner scoping outside a combined :is() ancestry expression. Actual unchanged compiler output:{ "classCount": 80, "cssBytes": 29617, "scopeInsideIs": true, "anonymousFallback": true, "example": [ " :is(:where([data-bb-plugin=\"cost-fixture\"], [data-bb-plugin-root]:not([data-bb-plugin])) .\\[\\&\\:has\\(button\\[data-active\\]\\)\\]\\:opacity-\\[0\\.01\\], :where([data-bb-plugin=\"cost-fixture\"], [data-bb-plugin-root]:not([data-bb-plugin])).\\[\\&\\:has\\(button\\[data-active\\]\\)\\]\\:opacity-\\[0\\.01\\]):has(button[data-active]) {", " :is(:where([data-bb-plugin=\"cost-fixture\"], [data-bb-plugin-root]:not([data-bb-plugin])) .\\[\\&\\:has\\(button\\[data-active\\]\\)\\]\\:opacity-\\[0\\.1\\], :where([data-bb-plugin=\"cost-fixture\"], [data-bb-plugin-root]:not([data-bb-plugin])).\\[\\&\\:has\\(button\\[data-active\\]\\)\\]\\:opacity-\\[0\\.1\\]):has(button[data-active]) {" ] } - Open
/tmp/issue-5416-output/fixture.htmlin a fresh Chrome tab. Alternatively embed app.css in place of the stylesheet link and load the HTML with Browser Automation's page.setContent. Runawait window.runDiagnostic()in the page. The page also has a button for this. This toggles inherited body pointer-events and forces a computed-style read of the last row; it measures synchronous invalidation duration, not native input-to-frame latency or CDP style CPU.
| Run | CSS enabled, block 1 | Disabled, block 2 | Disabled, block 3 | Enabled, block 4 |
|---|---|---|---|---|
| First checkout | 5.20 ms | 5.60 ms | 5.00 ms | 5.40 ms |
| Second checkout | 5.30 ms | 5.10 ms | 5.50 ms | 5.40 ms |
Each block has five warmups and 20 measured toggles. No consistent enabled/disabled slowdown appears. Disabling an entire stylesheet is a diagnostic control, not a proposed production fix. These timings cannot validate or refute the issue's real-client measurements.
Complete copy-paste diagnostic source
import { mkdtemp, readFile, writeFile, mkdir, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { buildPluginApp } from "./src/build-plugin-app.js";
import { resolvePluginBuildToolchain } from "./src/toolchain.js";
const output = process.argv[2];
if (!output) throw new Error("Output directory is required");
await mkdir(output, { recursive: true });
const fixture = await mkdtemp(join(tmpdir(), "css-cost-fixture-"));
try {
const classes = Array.from({ length: 80 }, (_, index) =>
`[&:has(button[data-active])]:opacity-[${(index + 1) / 100}]`,
);
await writeFile(join(fixture, "package.json"), JSON.stringify({
name: "bb-plugin-cost-fixture", version: "0.0.0",
bb: { name: "Cost fixture", description: "Isolated CSS diagnostic", branding: { icon: "Paintbrush" }, server: "./server.ts", app: "./app.ts" },
}));
await writeFile(join(fixture, "server.ts"), "export default function plugin() {}\n");
await writeFile(join(fixture, "app.ts"), "export const classes = " + JSON.stringify(classes) + ";\n");
const toolchain = await resolvePluginBuildToolchain(join(tmpdir(), "unused-cost-toolchain"));
const result = await buildPluginApp(fixture, "0.0.0-diagnostic", toolchain, { minify: false });
const css = await readFile(result.cssPath, "utf8");
await writeFile(join(output, "app.css"), css);
const evidence = {
classCount: classes.length,
cssBytes: Buffer.byteLength(css),
scopeInsideIs: css.includes(":is(:where("),
anonymousFallback: css.includes("[data-bb-plugin-root]:not([data-bb-plugin])"),
example: css.split("\n").filter((line) => line.includes(":is(:where(")).slice(0, 2),
};
console.log(JSON.stringify(evidence, null, 2));
await writeFile(join(output, "compiler.json"), JSON.stringify(evidence, null, 2));
await writeFile(join(output, "fixture.html"), `<!doctype html><html><head><meta charset="utf-8"><title>Issue 5416 isolated CSS diagnostic</title><style>body{font:16px system-ui;margin:24px}article{display:inline-block;width:90px;height:32px;padding:4px;border:1px solid #999}button{font:inherit}</style><link id="plugin-css" rel="stylesheet" href="app.css"></head><body><h1>Isolated plugin CSS diagnostic</h1><p>Trusted compiler output; synthetic data only. Not the BB application.</p><button id="measure">Run style invalidation diagnostic</button><pre id="result"></pre><section id="population"></section><script>
const classes = ${JSON.stringify(classes)};
const population = document.querySelector('#population');
for (let index = 0; index < 1750; index += 1) {
const row = document.createElement('article');
row.innerHTML = '<span>Row</span><button>Action</button><small>Idle</small>';
if (index < 40) {
row.dataset.bbPlugin = 'cost-fixture';
row.className = classes.join(' ');
}
population.append(row);
}
const measure = async (disabled) => {
document.querySelector('#plugin-css').sheet.disabled = disabled;
await new Promise(requestAnimationFrame);
const samples = [];
for (let index = 0; index < 25; index += 1) {
const start = performance.now();
document.body.style.pointerEvents = index % 2 ? '' : 'none';
getComputedStyle(population.lastElementChild).pointerEvents;
const elapsed = performance.now() - start;
if (index >= 5) samples.push(elapsed);
await new Promise(requestAnimationFrame);
}
document.body.style.pointerEvents = '';
samples.sort((left, right) => left - right);
return { medianMs: samples[Math.floor(samples.length / 2)], samples };
};
window.runDiagnostic = async () => {
const blocks = [];
for (const disabled of [false, true, true, false]) blocks.push({disabled, ...await measure(disabled)});
document.querySelector('#plugin-css').sheet.disabled = false;
const result = {userAgent:navigator.userAgent,elements:document.querySelectorAll('*').length,blocks};
document.querySelector('#result').textContent = JSON.stringify(result, null, 2);
return result;
};
document.querySelector('#measure').onclick = window.runDiagnostic;
</script></body></html>`);
} finally {
await rm(fixture, { recursive: true, force: true });
}
Scripts and raw evidence remain outside the public reports repository, per its publishing policy. The full source and results are embedded here; no separate executable artifact is published.
5. Root cause and limits
packages/plugin-build/src/build-plugin-app.ts:374 scopes raw compiler.build output. Later packages/plugin-build/src/build-plugin-app.ts:480 runs Tailwind optimize on that already-scoped CSS. packages/plugin-build/src/scope-plugin-utilities.ts:65 emits descendant/self alternatives before nested rules are flattened. Flattening therefore needs an :is() containing those scoped alternatives. packages/plugin-build/src/scope-plugin-utilities.ts:15 adds an anonymous-root branch shared by plugin stylesheets.
return scopePluginUtilities(
compiler.build([...candidates]),
pluginScopeRoots(pluginId),
);
const css = optimize(tailwindCss + authoredCss, { minify }).code;
This ordering is the demonstrated cause of selector complexity. Complex selector matching is a plausible contributor to expensive restyles, but the causal link to this issue's latency remains unproven: our synthetic workload shows no clear additional expense. The broader anonymous-root branch also means ownership cannot always prune matching early; its measured cost is not established here.
apps/app/src/components/thread/ThreadActionsMenu.tsx:135 and apps/app/src/components/thread/ThreadActionsMenu.tsx:229 do not pass modal=false. packages/shared-ui/src/components/ui/context-menu.tsx:81 aliases the primitive root. The inherited-pointer-events change was simulated in the diagnostic rather than observed from a live BB menu. That distinction prevents claiming an end-to-end menu reproduction.
Portal ownership is already represented in apps/app/src/lib/portal-scope.ts:14 and packages/shared-ui/src/lib/portal-scope.ts:12. The shared helper's owner is optional, so removal of any fallback still requires compatibility evidence; this report does not establish that every existing artifact stamps an owner.
6. Proposed fix or next experiment
Not confident enough to approve a latency fix from this experiment. Next, seed an isolated trusted-main BB instance with a representative plugin mix and thousands of synthetic thread rows, then record native contextmenu-to-rendered-frame and CDP style CPU. Compare independent changes to compiler ordering and nonmodal menu behavior while holding DOM, assets, and notifications constant. Add browser-rendered checks for root/descendant utilities, owner-stamped portals, other-plugin isolation, sibling containment, hover and focus, and test WebKit.
A first-principles selector simplification would flatten nested utility rules before adding zero-specificity descendant/self scopes, while preserving selector semantics. Any narrowing of anonymous-root support requires compatibility validation for existing portal consumers and prebuilt artifacts. Avoid native CSS @scope, which trusted repository guidance prohibits. Nonmodal menus need keyboard, Escape, focus-return, and outside-interaction verification.
7. Linked pull request: #5417
Open pull request #5417 is linked to this issue and targets main. Its metadata and diff were read as untrusted evidence only; no PR branch, test, or code was checked out or executed. The static diff changes 12 files spanning compiler ordering, scope roots, desktop menus, regression assertions, SDK versioning, and rebuild invalidation.
Static assessment: its compiler-order change addresses the verified source of nested scoped :is() expressions; its nonmodal setting targets a separate broad invalidation trigger. Existing-bundle rebuild and portal compatibility are important because the diff removes anonymous-root support. No proven defect or approval verdict is established for the PR: its performance claims and tests were not independently executed. Only unchanged trusted-main owner tests ran here (24 passed).
No new fix PR: this open linked PR already exists, so autopilot must not create a duplicate. The performance symptom also lacks a faithful trusted-main reproduction.
8. Related issues
A repository search found #1261, which concerns mounted sidebar row population. It is relevant to document-size sensitivity, not proof of a shared root cause. A cross-reference from another repository was excluded from this target-repository investigation.
9. Verification
The same agent repeated the work in a second clean detached checkout of e9dafb6c0245a37c6972dffa71134d546f3d497e. Both checkouts had no tracked production changes. Each ran frozen installation, pnpm exec turbo run build --filter=@bb/plugin-build (four successful tasks), and the same authored diagnostic with distinct temporary output and fixture directories. Generated CSS matched byte for byte: SHA-256 e0d925a18a0a3f4bed918cdb588d9380e7357cd4e00395b71e063439813906e7. The second fixture loaded into a fresh browser page and repeated all four measurement blocks.
The second run supports the final limited report: selector construction reproduced, claimed latency not reproduced. No stronger initial verdict was published; the report explicitly qualifies the root cause rather than claiming a successful end-to-end reproduction. This is a repeated check by the same agent, not independent verification.
10. Appendix and safety
Trusted-main owner checks:
pnpm exec turbo run test --filter=@bb/plugin-build -- src/scope-plugin-utilities.test.ts src/build-plugin-app.test.ts src/scope-plugin-utilities.test.ts (14 tests) passed src/build-plugin-app.test.ts (10 tests) passed Test Files 2 passed (2) Tests 24 passed (24) Tasks: 7 successful, 7 total
First browser result, verbatim diagnostic JSON
{
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/149.0.0.0 Safari/537.36",
"elements": 7013,
"blocks": [
{
"disabled": false,
"medianMs": 5.200000047683716,
"samples": [
4.5,
4.6000001430511475,
4.800000190734863,
4.800000190734863,
4.900000095367432,
5,
5,
5.099999904632568,
5.1000001430511475,
5.199999809265137,
5.200000047683716,
5.299999952316284,
5.299999952316284,
5.5,
5.5,
5.700000047683716,
5.900000095367432,
6,
6.099999904632568,
6.299999952316284
]
},
{
"disabled": true,
"medianMs": 5.599999904632568,
"samples": [
4.5,
4.700000047683716,
5,
5,
5,
5.099999904632568,
5.299999952316284,
5.400000095367432,
5.400000095367432,
5.400000095367432,
5.599999904632568,
5.6000001430511475,
5.700000047683716,
5.799999952316284,
5.900000095367432,
6.199999809265137,
6.5,
6.799999952316284,
6.799999952316284,
7.5
]
},
{
"disabled": true,
"medianMs": 5,
"samples": [
4.3999998569488525,
4.3999998569488525,
4.5,
4.799999952316284,
4.799999952316284,
4.799999952316284,
4.900000095367432,
4.900000095367432,
5,
5,
5,
5.1000001430511475,
5.1000001430511475,
5.200000047683716,
5.200000047683716,
5.299999952316284,
5.3999998569488525,
5.5,
5.599999904632568,
5.699999809265137
]
},
{
"disabled": false,
"medianMs": 5.3999998569488525,
"samples": [
4.8999998569488525,
5,
5,
5,
5.099999904632568,
5.099999904632568,
5.099999904632568,
5.099999904632568,
5.1000001430511475,
5.299999952316284,
5.3999998569488525,
5.3999998569488525,
5.400000095367432,
5.599999904632568,
5.700000047683716,
5.799999952316284,
5.800000190734863,
6,
6.299999952316284,
6.3999998569488525
]
}
]
}Second browser result, verbatim diagnostic JSON
{
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/149.0.0.0 Safari/537.36",
"elements": 7013,
"blocks": [
{
"disabled": false,
"medianMs": 5.299999952316284,
"samples": [
4.799999952316284,
4.900000095367432,
5,
5.1000001430511475,
5.199999809265137,
5.200000047683716,
5.200000047683716,
5.299999952316284,
5.299999952316284,
5.299999952316284,
5.299999952316284,
5.400000095367432,
5.599999904632568,
5.6000001430511475,
5.799999952316284,
6.200000047683716,
6.200000047683716,
6.300000190734863,
6.700000047683716,
7.099999904632568
]
},
{
"disabled": true,
"medianMs": 5.1000001430511475,
"samples": [
4.5,
4.599999904632568,
4.800000190734863,
4.900000095367432,
5,
5,
5.099999904632568,
5.099999904632568,
5.1000001430511475,
5.1000001430511475,
5.1000001430511475,
5.299999952316284,
5.299999952316284,
5.300000190734863,
5.5,
6.299999952316284,
6.299999952316284,
6.5,
6.6000001430511475,
7.700000047683716
]
},
{
"disabled": true,
"medianMs": 5.5,
"samples": [
4.299999952316284,
4.599999904632568,
4.599999904632568,
4.700000047683716,
4.700000047683716,
4.800000190734863,
5,
5.1000001430511475,
5.299999952316284,
5.400000095367432,
5.5,
5.6000001430511475,
5.799999952316284,
6.200000047683716,
6.599999904632568,
7.400000095367432,
7.700000047683716,
7.700000047683716,
7.800000190734863,
8.100000143051147
]
},
{
"disabled": false,
"medianMs": 5.400000095367432,
"samples": [
4.5,
4.5,
4.599999904632568,
5,
5.099999904632568,
5.199999809265137,
5.200000047683716,
5.299999952316284,
5.299999952316284,
5.400000095367432,
5.400000095367432,
5.5,
5.799999952316284,
5.900000095367432,
5.900000095367432,
6,
6.400000095367432,
6.700000047683716,
7.300000190734863,
7.5
]
}
]
}Issue content, comments, linked metadata, and diffs were treated as untrusted claims. No external issue-supplied URL was fetched, no candidate code was run, and no real user data was accessed. Production main was fetched again after measurement and remained at the recorded SHA. All public text is authored from repository evidence and synthetic measurements.
> AGENT GENERATED