#6288 · Context-aware lightbox portal ownership
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
The image preview is rendered in a portal, outside its original DOM parent. Its portal incorrectly identifies itself as an anonymous plugin root, both for ordinary host content and for content owned by a named plugin. A component-level reproduction confirms both attribute failures on trusted main, twice in separate clean checkouts. The underlying import selects the standalone shared-UI hook instead of the host's context-aware hook. This permits matching of the anonymous-root CSS selector; a visible styling collision, desktop behavior, mobile behavior, and release-package behavior were not tested.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| A host lightbox has an anonymous plugin root. | Verified | Host regression receives root="", plugin=null; expected root=null, plugin=null. |
| A lightbox under a named plugin loses that plugin's identity. | Verified | Plugin regression receives root="", plugin=null; expected root="", plugin="test-plugin". |
| The environment seam does not replace this direct app import. | Verified | The resolver returns early for importers outside packages/shared-ui; the failing DOM result corroborates that path. |
| Other representative shared-UI overlays use host context correctly. | Verified, limited sample | The five existing portal-scope cases pass on both baseline runs, including host/plugin dialogs. |
| Plugin selectors can match the anonymous root. | Verified by source | pluginScopeRoots includes [data-bb-plugin-root]:not([data-bb-plugin]). No rendered CSS collision was demonstrated. |
| The same defect ships in version 0.47.1. | Unverified | Only the recorded trusted main commit was executed; no release artifact was fetched. |
3. Environment
- Repository: public get-bb/bb. Base: 3a2c49a267cd2a62a96ebff880068a7c37074251, still origin/main when the fix branch was prepared.
- Linux 4.19.0-gvisor x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.1; jsdom through the app's existing isolated test project.
- Separate temporary checkouts named first and second. Each received its own frozen install and only an investigator-authored regression on top of the trusted commit.
- No server, browser session, provider, application data directory, database, or listener was used. No screenshots: the demonstrated defect is DOM attribute ownership, not a verified visual break.
4. Minimal reproduction
- Clone the trusted repository and detach at the recorded base:
git clone https://github.com/get-bb/bb.git bb-6288 cd bb-6288 git checkout --detach 3a2c49a267cd2a62a96ebff880068a7c37074251 pnpm install --frozen-lockfile --prefer-offline
- Copy the complete reproduction test from the expandable block below into
apps/app/src/lib/portal-scope.test.tsx. The existing five cases are retained and a two-row lightbox regression is added. No production code changes are required. - Run the owning package through Turbo:
pnpm exec turbo run test --filter=@bb/app -- src/lib/portal-scope.test.tsx
Expected: seven passing cases, with host portals carrying no plugin ownership and plugin portals carrying the context's ID. Actual, verbatim failure summaries from each run:
AssertionError: expected { root: '', plugin: null } to deeply equal { root: null, plugin: null }
AssertionError: expected { root: '', plugin: null } to deeply equal { root: '', plugin: 'test-plugin' }
Tests 2 failed | 5 passed (7)
The test checks a real rendered lightbox portal, its overlay marker, and both ownership attributes. It does not mock the hook or inspect an import string. Existing coverage omitted the lightbox, so it could not detect the wrong hook selection. No production test seam was added.
Complete reproduction test
// @vitest-environment jsdom
import type { ReactNode } from "react";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it } from "vitest";
import { PluginContext } from "@/components/plugin/plugin-context";
import { ImageLightbox } from "@/components/ui/image-lightbox";
import { Dialog, DialogContent, DialogTitle } from "@bb/shared-ui/dialog";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@bb/shared-ui/tooltip";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@bb/shared-ui/select";
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@bb/shared-ui/context-menu";
function inPluginScope(children: ReactNode) {
return (
<PluginContext.Provider value="test-plugin">
{children}
</PluginContext.Provider>
);
}
function openDialog() {
return (
<Dialog open>
<DialogContent>
<DialogTitle>hi</DialogTitle>
</DialogContent>
</Dialog>
);
}
afterEach(cleanup);
describe("usePortalScopeProps", () => {
it.each([null, "test-plugin"])(
"preserves lightbox portal ownership for plugin %s",
(pluginId) => {
const { container } = render(
<PluginContext.Provider value={pluginId}>
<ImageLightbox
imageSrc="/scope-check.png"
imageAlt="Scope check"
title="Scope check"
onClose={() => {}}
/>
</PluginContext.Provider>,
);
const dialog = screen.getByRole("dialog", { name: "Scope check" });
expect(container.contains(dialog)).toBe(false);
expect(dialog.getAttribute("data-bb-portaled-overlay")).toBe("");
expect({
root: dialog.getAttribute("data-bb-plugin-root"),
plugin: dialog.getAttribute("data-bb-plugin"),
}).toEqual({ root: pluginId === null ? null : "", plugin: pluginId });
},
);
it("stamps portaled dialog content + overlay inside a plugin slot", () => {
const { baseElement } = render(inPluginScope(openDialog()));
const content = baseElement.querySelector('[role="dialog"]');
expect(content).not.toBeNull();
expect(content!.getAttribute("data-bb-portaled-overlay")).toBe("");
expect(content!.getAttribute("data-bb-plugin-root")).toBe("");
const scoped = baseElement.querySelectorAll("[data-bb-plugin-root]");
expect(scoped.length).toBe(2);
for (const root of scoped) {
expect(root.getAttribute("data-bb-plugin")).toBe("test-plugin");
}
expect(
baseElement.querySelectorAll("[data-bb-portaled-overlay]").length,
).toBe(2);
});
it("leaves host-tree dialogs unscoped so plugin CSS cannot match them", () => {
const { baseElement } = render(openDialog());
const content = baseElement.querySelector('[role="dialog"]');
expect(content).not.toBeNull();
expect(content!.hasAttribute("data-bb-plugin-root")).toBe(false);
expect(content!.getAttribute("data-bb-portaled-overlay")).toBe("");
expect(baseElement.querySelectorAll("[data-bb-plugin-root]").length).toBe(
0,
);
});
it("stamps tooltip content (inline-hook variant) inside a plugin slot", () => {
const { baseElement } = render(
inPluginScope(
<TooltipProvider>
<Tooltip open>
<TooltipTrigger>trigger</TooltipTrigger>
<TooltipContent>tip</TooltipContent>
</Tooltip>
</TooltipProvider>,
),
);
const tip = baseElement.querySelector(
'[data-bb-plugin-root][role="tooltip"], [role="tooltip"]',
);
expect(tip).not.toBeNull();
const scopedTip = baseElement.querySelector("[data-bb-plugin-root]");
expect(scopedTip).not.toBeNull();
expect(scopedTip!.getAttribute("data-bb-plugin")).toBe("test-plugin");
expect(scopedTip!.getAttribute("data-bb-portaled-overlay")).toBe("");
});
it("stamps select content so native drag regions cannot swallow options", () => {
const { baseElement } = render(
<Select open value="one">
<SelectTrigger aria-label="Example select">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="one">One</SelectItem>
</SelectContent>
</Select>,
);
expect(
baseElement
.querySelector('[role="listbox"]')
?.getAttribute("data-bb-portaled-overlay"),
).toBe("");
});
it("stamps context menu content after a real context-menu gesture", () => {
const { baseElement } = render(
<ContextMenu>
<ContextMenuTrigger>Context target</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Action</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>,
);
fireEvent.contextMenu(screen.getByText("Context target"));
const menu = baseElement.querySelector('[role="menu"]');
expect(menu?.getAttribute("data-bb-portaled-overlay")).toBe("");
expect(menu?.classList.contains("z-[70]")).toBe(true);
});
});5. Root cause
The app lightbox imports the standalone hook directly:
import { usePortalScopeProps } from "@bb/shared-ui/lib/portal-scope";
That hook uses a compile-time ID and always adds a plugin root:
const pluginId =
typeof __BB_PLUGIN_ID__ === "string" ? __BB_PLUGIN_ID__ : undefined;
return {
"data-bb-portaled-overlay": "",
"data-bb-plugin-root": "",
...(pluginId !== undefined ? { "data-bb-plugin": pluginId } : {}),
};
In this host test environment the compile-time plugin ID is absent, so the result is an anonymous root. React's PluginContext cannot affect this implementation. The app's environment seam substitutes the host implementation only for importers inside packages/shared-ui. The lightbox lives inside apps/app and is excluded.
The existing host implementation reads PluginContext and returns only the overlay marker when that context is null, or the overlay marker, plugin root and owning ID otherwise. That is the existing behavior already exercised by the dialog cases.
The utility scope root selector contains an anonymous-root alternative:
[data-bb-plugin="PLUGIN_ID"], [data-bb-plugin-root]:not([data-bb-plugin])
Consequently, the incorrect host root is eligible for utility rules from plugins other than an intended owner. This is a CSS ownership defect; no authentication, authorization, data exposure, or exploit was demonstrated.
6. Proposed fix and verification
Use @/lib/portal-scope in the app's lightbox. This reuses existing policy rather than broadening the resolver or changing plugin packaging. Preserve the two ownership cases in the canonical portal-scope suite.
The investigator applied that one-import repair locally. The focused suite passed: 3 files, 12 tests, including lightbox keyboard/dismissal interactions and the existing portal cases. Turbo lint/typecheck passed (246 lint warnings, zero errors). The final change is two files, 26 additions and one deletion: 27 changed text lines. No dependency, lockfile, generated output, public API, protocol, stored data, or permission behavior changes.
pnpm exec oxfmt apps/app/src/lib/portal-scope.test.tsx apps/app/src/components/ui/image-lightbox.tsx pnpm exec turbo run test --filter=@bb/app -- src/lib/portal-scope.test.tsx src/components/ui/image-lightbox.test.ts src/components/ui/image-lightbox.interaction.test.tsx pnpm exec turbo run lint typecheck --filter=@bb/app pnpm exec turbo run build --filter=@bb/app git diff --check git diff --numstat origin/main
Live image-preview journey, desktop Safari/WebKit and mobile journeys: not run. Component-level assertions establish the reported attribute defect; they are not a whole-product visual verification.
7. Linked PR review
PR #6290 was closed and unmerged at review. Its metadata and diff were read as untrusted data after the investigator authored and reproduced the regression. No branch or code from that PR was checked out or run. Static review: it changes the same hook import and adds ownership coverage; that production change addresses the verified root cause. No defect was found in the reviewed small diff. Its own tests were not executed. Both timeline metadata and an open-PR search returned no open PR for this issue before this fix was prepared.
8. Related issues
A repository search for portal-scope/lightbox issues found this issue and #3812 (native browser overlay stacking). The latter has a different reported symptom; it was not investigated and is not evidence for this defect. No duplicate open fix was found.
9. Verification — second clean run
The same investigator repeated the reproduction in a second clean temporary checkout, detached at 3a2c49a267cd2a62a96ebff880068a7c37074251, with a separate frozen install. Only the newly authored test file was copied; production sources remained unchanged. Running the same Turbo test command at 03:25:30 UTC produced the same two ownership assertion failures and five existing passes (exit 1). The first run began at 03:24:57 UTC and produced the same result (exit 1). Output excerpts below preserve both results; complete raw logs remain local. This is a repeated check by one investigator, not independent verification. No finding required correction. No ports or data directories were needed.
10. Appendix and limitations
Raw logs and the repair diff are retained locally, not committed to this public reports repository. The reproduction is fully included above. Relevant verbatim output excerpts:
First baseline run:
AssertionError: expected { root: '', plugin: null } to deeply equal { root: null, plugin: null }
AssertionError: expected { root: '', plugin: null } to deeply equal { root: '', plugin: 'test-plugin' }
Test Files 1 failed (1)
Tests 2 failed | 5 passed (7)
Start at 03:24:57
Second clean baseline run:
AssertionError: expected { root: '', plugin: null } to deeply equal { root: null, plugin: null }
AssertionError: expected { root: '', plugin: null } to deeply equal { root: '', plugin: 'test-plugin' }
Test Files 1 failed (1)
Tests 2 failed | 5 passed (7)
Start at 03:25:30
After-fix focused run:
Test Files 3 passed (3)
Tests 12 passed (12)
Lint and typecheck:
Found 246 warnings and 0 errors.
Tasks: 6 successful, 6 total
After-fix app build:
Tasks: 5 successful, 5 total
git diff --numstat origin/main:
1 1 apps/app/src/components/ui/image-lightbox.tsx
25 0 apps/app/src/lib/portal-scope.test.tsx
Preparation used origin/main from the trusted target repository, GitHub read-only metadata for issue properties and PR references, frozen installs and Turbo. An initial unfiltered build failed because a plugin's SDK host entry had not finished building. The SDK runtime subsequently built, pnpm exec turbo run build:types --filter=@get-bb/plugin-sdk passed, and the app-filtered production build passed. This preparatory build-order failure is not the reproduction result.
Trust handling: issue text, links and proposed tests were treated as untrusted claims. No issue-supplied URL, command, patch, script, branch or external test was fetched or executed. The reproduction was written from trusted repository evidence. No production instance or user data was accessed.