Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ const landed = useStaged({ people: Boolean(people), stream: Boolean(stream) });

| Export | What it does |
|---|---|
| `LoadingShape` | `loading`, `shape` or `prefill(variant)`, `children` (a function is called only once loaded), `refreshing`, `label` (said once for the page, default "Loading"), `showAfter` (300), `minShown` (400), `keep` (`KEEP`). `aria-busy` while loading; the shape is `aria-hidden` and `inert`. |
| `LoadingShape` | `loading`, `shape` or `prefill(variant)`, `children` (a function is called only once loaded), `refreshing`, `label` (said once for the page, default "Loading"), `showAfter` (300), `minShown` (400), `keep` (`KEEP`). `aria-busy` while loading; the shape is `aria-hidden` and `inert`, and the ids of what it draws move to `data-shape-id` so `getElementById` never finds the shape's copy. A text query in a test can skip it with `.basalt-bones`. |
| `Bones` | The painting alone (`shown`, `keep`, `twin`), for a place a region can't wrap. |
| `useStaged(ready, gap = 120, together = 250)` | Releases parts in phases. |
| `useRefreshing(on, after = 1000)`, `Refreshing` | "Updating" for a refresh that takes more than a second: braille and its word, or the ring alone with `compact`. |
Expand Down
12 changes: 11 additions & 1 deletion packages/react/src/loading-shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ function BonesFrame({ shown = true, keep = KEEP, twin, onBones, children, classN
const node = root.current;
if (!node) return undefined;
let frame = 0;
// The shape draws the app's own parts (twice with a prefill: the drawing and its twin), so it would hold the app's ids: duplicate ids are invalid, and
// the app's `getElementById` during loading found the inert copy. Each id inside the shape moves to `data-shape-id`, now and whenever one is set again.
const unId = (): void => {
for (const el of node.querySelectorAll("[id]")) {
el.setAttribute("data-shape-id", el.id);
el.removeAttribute("id");
}
};
unId();
// Whether the shape holds a part that stays put while the page scrolls (sticky or fixed): only then does a scroll outside the shape move its bones.
let moving = false;
const measure = (): void => {
Expand All @@ -149,7 +158,8 @@ function BonesFrame({ shown = true, keep = KEEP, twin, onBones, children, classN
// A part that settles its own layout after it is drawn moves what is inside without changing the region's size, and a prefill whose known part
// grows changes its words: measure again when the drawing changes, but not for the marks the measure sets.
const changed = new MutationObserver((records) => {
if (records.some((record) => record.attributeName !== "inert" && !record.attributeName?.startsWith("data-bone") && !(record.target as Element).closest?.(".basalt-bones-layer"))) again();
if (records.some((record) => record.type === "childList" || record.attributeName === "id")) unId();
if (records.some((record) => record.attributeName !== "inert" && record.attributeName !== "id" && record.attributeName !== "data-shape-id" && !record.attributeName?.startsWith("data-bone") && !(record.target as Element).closest?.(".basalt-bones-layer"))) again();
});
changed.observe(node, { subtree: true, childList: true, attributes: true, characterData: true });
window.addEventListener("resize", again);
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/styles/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -3882,8 +3882,10 @@
Select inserts; the `uncheckedValue` input), not the Slider's range input (a real focus target, and already inside its transformed thumb, so
not a layer), and not the checklist rows' inputs: in the open popup absolute inputs move the AA of its corners, which is a pixel. It is an inline
style, so the override takes !important. If a Base UI release stops passing `inputRef` to this input, nothing matches and nothing is exposed (the input is
as hidden as Base UI makes it); a test fails when the rule matches nothing. */
[data-basalt-mirror] { position: absolute !important; inset: auto !important; }
as hidden as Base UI makes it); a test fails when the rule matches nothing. It sits at the top start of its containing block, as Base UI's fixed
input sat at the viewport's, never at its place in the flow: an absolute box at its static place escapes a scroller that is not itself positioned,
so a list of checkboxes under a sticky or positioned ancestor stretched the page by the list's whole scrolled height (found by the first app). */
[data-basalt-mirror] { position: absolute !important; inset: 0 auto auto 0 !important; }
/* In the checklist's rows the inputs sit at the rows' own top start, so they add nothing to the rows' scrollable height (DECISIONS 167, Q9j). */
.basalt-filter-rows > [data-basalt-mirror] { top: 0 !important; left: 0 !important; }

Expand Down
56 changes: 56 additions & 0 deletions packages/react/test/mirror-and-shape-ids.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Two faults the first app's browser suite found (2026-11-22). Synthetic data only.
// 1. A checkbox's hidden form input (the mirror) was absolute at its place in the flow, so in a scrolling list that is not itself positioned, under a
// sticky or positioned ancestor, it escaped the list's clipping and stretched the page by the list's scrolled height. It now sits at the top start
// of its containing block.
// 2. A LoadingShape draws the app's parts (twice with a prefill), so it held the app's ids twice: the app's getElementById found the inert copy. Ids
// inside the shape move to data-shape-id.
import assert from "node:assert/strict";
import { after, before, describe, test } from "node:test";

import { fixturePage, launch, settle } from "./support.mjs";

let browser;
before(async () => { browser = await launch(); });
after(async () => { await browser?.close(); });

describe("A checkbox's hidden input in a scrolling list", () => {
for (const theme of ["dark", "light"]) {
test(`does not stretch the page past the list's clipping (${theme})`, async () => {
const rows = Array.from({ length: 40 }, (_, i) => `<li key={${i}} style={{ height: 44, display: "flex", alignItems: "center" }}><B.Checkbox aria-label="Reviewer ${i + 1}" /></li>`).join("");
const { page } = await fixturePage(browser, `document.body.style.margin = "0"; createRoot(document.getElementById("root")).render(
<div style={{ position: "sticky", top: 0, height: "100vh", display: "flex", flexDirection: "column" }}>
<ul style={{ flex: 1, minHeight: 0, overflow: "auto", margin: 0, padding: 0, listStyle: "none" }}>${rows}</ul>
<footer style={{ height: 56 }}>Synthetic foot</footer>
</div>);`, { theme, viewport: { width: 800, height: 600 } });
await settle(page);
const m = await page.evaluate(() => ({ scroll: document.documentElement.scrollHeight, view: innerHeight, foot: document.querySelector("footer").getBoundingClientRect().bottom, mirrors: document.querySelectorAll("input[data-basalt-mirror]").length }));
assert.equal(m.mirrors, 40, "every mirror is marked");
assert.ok(m.scroll <= m.view, `the page is not stretched (${m.scroll} against ${m.view})`);
assert.ok(m.foot <= m.view, `the foot stays on screen (${m.foot})`);
await page.close();
});
}
});

describe("Ids inside a LoadingShape", () => {
test("the drawing and its twin hold no id; each moves to data-shape-id, and the loaded content keeps its own", async () => {
const { page } = await fixturePage(browser, `function Card({ name }) { return <section id="approval-1"><h3 id="approval-1-title">{name}</h3></section>; }
function App() {
const [ready, setReady] = React.useState(false);
window.__load = () => setReady(true);
return <B.LoadingShape loading={!ready} showAfter={0} prefill={() => <Card name="Synthetic approval" />}>{() => <Card name="Synthetic approval" />}</B.LoadingShape>;
}
createRoot(document.getElementById("root")).render(<App />);`, { theme: "dark", viewport: { width: 800, height: 600 } });
await settle(page);
await page.waitForTimeout(100);
const loading = await page.evaluate(() => ({ ids: document.querySelectorAll("#approval-1, #approval-1-title").length, moved: document.querySelectorAll('[data-shape-id="approval-1"]').length }));
assert.equal(loading.ids, 0, "no id inside the shape while it loads");
assert.equal(loading.moved, 2, "the drawing and its twin each keep the id as data-shape-id");
await page.evaluate(() => window.__load());
await page.waitForTimeout(600);
const loaded = await page.evaluate(() => ({ ids: document.querySelectorAll("#approval-1").length, inShape: !!document.getElementById("approval-1")?.closest(".basalt-bones") }));
assert.equal(loaded.ids, 1, "the loaded card has its id, once");
assert.equal(loaded.inShape, false);
await page.close();
});
});
Loading