Layout geometry
Where each region sits is arithmetic on a few inputs, computed once, and nothing measures the DOM to decide it.
The problem
An assistant panel can sit beside the page, squeezing it, or float over it when there isn’t room. The obvious way to decide is to measure: check how wide the page is, and float if it’s too narrow.
That builds a feedback loop. The panel docks, the page shrinks, something reflows, the measurement changes, and the panel floats. Then the page grows back and it docks again. Each region measuring for itself also means two regions can briefly disagree about the same layout.
What I concluded
Layout is a pure function of three inputs: the viewport width, whether you prefer the nav pinned, and the panel width you last chose.
function chromeLayout(viewport, pinPreferred, stored) {
const pinned = pinPreferred && viewport >= NAV_PIN_MIN;
const nav = pinned ? NAV_PINNED : NAV_RAIL;
const beside = Math.max(viewport, APP_MIN) - nav - GUTTER;
const dockedMax = beside - PAGE_FLOOR - FRAME;
const docked = dockedMax >= stored;
const max = docked ? dockedMax : beside - PAGE_KEEP;
const width = Math.min(Math.max(stored, PANEL_MIN),
Math.max(max, PANEL_MIN));
return { nav, pinned, docked, width };
}
Two numbers are the whole policy. The page never gets narrower than its floor beside a docked panel, and a floating panel always leaves some page showing. Docking compares against the width you chose, not the width you got, so the flip happens at one exact point.
The shell calls the function once per change, and every region sizes itself from that one result. In a real app I’d write it onto the shell’s root as custom properties plus a data-docked attribute, so the nav, page and panel size themselves in CSS and nothing reads layout back.
Rules
- Inputs, not measurements. Viewport, preference and stored width go in. No
getBoundingClientRectdecides the layout. - One call, one answer. The shell computes it. Regions read it and never recompute.
- Policy is a couple of named numbers. A page floor and a minimum page showing. Everything else follows.
- Compare against intent. Dock based on the width the person asked for, so the result doesn’t depend on itself.
- Test it without a browser. It’s a function of numbers, so unit tests cover every breakpoint.
What you get
No flicker at the boundary, because nothing feeds back. Every region agrees on the layout because there’s only one copy of it, and the rules for docking fit in a dozen lines you can read.
The demo runs the same function and shows its working: drag the window or the panel width and watch the math decide. It sets widths inline rather than through custom properties. Related: Nav rail, Resizable panel, Assistant panel.