ADR-0151 — A portalled surface is told what it cannot be related to
Status: Accepted · Date: 2026-08-31 · Track: 002 close-out (LEDGER drain, row 27 / item 16) · Supersedes: nothing · Builds on: ADR-0025, ADR-0023
Context
Two of Studio's boxes are deliberately removed from the tree they are written
in. .lk-toasts is createPortal(…, document.body) under React and
document.body.appendChild in the vanilla build, because a position: fixed
box is contained by any ancestor carrying a transform, filter or
backdrop-filter — a class of clipping a grep cannot find (ADR-0025). Rendering
beside <body> means there is no such ancestor to look for.
That is the right call and it costs something: the box can no longer be addressed in terms of anything it was near. One rule had been written as if it could —
@media (max-width: 719px) {
.lk-shell ~ .lk-toasts,
.lk-shell .lk-toasts { bottom: calc(var(--float-inset) + 52px + …); }
}
— the nudge that keeps a toast from covering the mobile tab pill. Neither half holds up:
- The descendant half can never match anywhere. The container is a child
of
<body>in both renderings, so it is inside no shell in any tree this system builds. - The sibling half matched only the static layouts, where
<div class="lk-shell">happens to be a body child and the toast host is appended after it. Under React the shell renders inside the app root and the toast container beside it, so the two are not siblings and the nudge had never once fired on the path the product ships on.
A :has() rewrite is not available: the leftmost compound would have to be
body, and build-css.mjs's containment check refuses any selector in the
standalone layers that reaches outside the .lk- namespace — which is the
property that makes one layer safe to import alone (ADR-0023).
Decision
Chrome that a portalled surface must account for publishes a class on
<body>, and the rule is written against that class.
@media (max-width: 719px) {
.lk-has-tabbar .lk-toasts { bottom: calc(var(--float-inset) + 52px + …); }
}
- The publisher is the thing itself, not its container.
TabBarsets the flag while it is mounted; the shell does not. The bar is what is on screen to clear, and a shell with no tab bar has nothing down there — the old key was wrong about which fact it needed as well as unable to read it. useBodyFlag(name)is counted, not set-and-cleared. Unmount order does not follow mount order: React mounts, unmounts and mounts a subtree again under StrictMode, and a naive cleanup takes the flag out from under a live caller. The count lives at module scope, keyed by class name, because the flag is a fact about the document rather than about a component instance.- The class stays inside the
.lk-namespace, so the rule survives in the standalone component layer with nothing widened. - A page with no component to publish it writes the class itself. The three
static layouts that draw a bar carry
lk-has-tabbaron<body>besidestudio-base. The equality is held by a test rather than by discipline: a layout that draws a.lk-tabbarhas the class, and one that does not, does not. - The flag says mounted; the media query says visible. Chrome in this system is display-gated by the stylesheet and rendered unconditionally (chrome.jsx's own note), so publishing on mount rather than on a width keeps the three platforms agreeing without a media-query listener in the middle.
Consequences
- The nudge fires for the first time on the React path. Nothing moves for
Cardsite, which mounts its own shell and no
.lk-tabbar— its toasts sat at--float-insetbefore this and sit there after, which is what the old rule had been doing there all along, silently and for the wrong reason. - There is now one named way for a portalled box to learn about chrome it is
not related to. The next one — a bottom sheet, a docked player, a second
fixed bar — takes
useBodyFlagrather than inventing a second mechanism or reaching for an ancestor selector that cannot exist. - A body flag is global state, and the cost is honest: two independent Studio trees on one page share the count. That is the correct answer for a fact about the document (either a bar is on screen or it is not), and it is why the count is keyed by class name rather than held per provider.
check:layer-completenessgained a 92nd dispositioned gap the moment the dead selector went, and the gap was always there:lk-shellis the 63rd shell class and the only one with no row, because.lk-shell ~ .lk-toastssat in the component layer and made the class look defined. A rule that could not fire was standing in for a rule that does not exist.- What this does not do is make the toast measure anything. The 52px is the pill's own metric, written where the pill's metrics are written; a bar that changes height changes both.
Source: docs/decisions/0151-a-portalled-surface-is-told-what-it-cannot-be-related-to.md