diff --git a/packages/react/README.md b/packages/react/README.md index e9339a95..64be05bc 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -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`. | diff --git a/packages/react/src/loading-shape.tsx b/packages/react/src/loading-shape.tsx index e8ba3e0b..1714730b 100644 --- a/packages/react/src/loading-shape.tsx +++ b/packages/react/src/loading-shape.tsx @@ -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 => { @@ -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); diff --git a/packages/react/src/styles/components.css b/packages/react/src/styles/components.css index 0c52e9ff..b2f4fa18 100644 --- a/packages/react/src/styles/components.css +++ b/packages/react/src/styles/components.css @@ -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; } diff --git a/packages/react/test/mirror-and-shape-ids.test.mjs b/packages/react/test/mirror-and-shape-ids.test.mjs new file mode 100644 index 00000000..337097ef --- /dev/null +++ b/packages/react/test/mirror-and-shape-ids.test.mjs @@ -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) => `
  • `).join(""); + const { page } = await fixturePage(browser, `document.body.style.margin = "0"; createRoot(document.getElementById("root")).render( +
    + + +
    );`, { 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

    {name}

    ; } + function App() { + const [ready, setReady] = React.useState(false); + window.__load = () => setReady(true); + return }>{() => }; + } + createRoot(document.getElementById("root")).render();`, { 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(); + }); +});