web: place() reads the capsule's height once
Review 8 on #181. place() runs on every visual viewport resize and scroll, and read the capsule's height twice each time (offsetHeight, then getBoundingClientRect) after writing its position, forcing a layout per event. The height, which the stylesheet fixes, is now read the first time the capsule shows and kept; the only read left per event is the layout viewport's height, before any write, and the position is written only when it changes. No test: what changed is how often the browser lays out, not what it draws. TestTheFormatSheetAndTheQuickBar, TestWhenTheKeyboardIsUp and TestATapInTheDocumentClosesTheSheet still hold the capsule's place.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+11
−6
internal/docs/brand/phone.js+11 −6
diff --git a/internal/docs/brand/phone.js b/internal/docs/brand/phone.js| index f404c10..654a845 100644 |
| --- a/internal/docs/brand/phone.js |
| +++ b/internal/docs/brand/phone.js |
| @@ -285,7 +285,7 @@ |
| if (a && editor && editor.contains(a)) a.blur(); |
| }); |
| } |
| - var lastHeight = -1; |
| + var lastHeight = -1, capsuleHeight = 0; |
| // The layout viewport's tallest height at this width: a keyboard that |
| // shrinks the layout viewport itself (interactive-widget= |
| // resizes-content, Firefox for Android) leaves the visual viewport as |
| @@ -324,14 +324,19 @@ |
| // scrolled with the keyboard up, so a distance from the bottom lands |
| // the capsule behind its accessory bar. |
| if (mode === "keyboard") { |
| - var top = vv.offsetTop + vv.height - (quick.offsetHeight || 48) - 8; |
| - quick.style.insetBlockStart = Math.round(top) + "px"; |
| - quick.style.insetBlockEnd = "auto"; |
| - } else { |
| + // Read once, the first time it shows: the stylesheet fixes its |
| + // height, and a read per event would force a layout on every |
| + // visual viewport scroll. |
| + if (!capsuleHeight) capsuleHeight = quick.offsetHeight || 48; |
| + var top = vv.offsetTop + vv.height - capsuleHeight - 8; |
| + var at = Math.round(top) + "px"; |
| + if (quick.style.insetBlockStart !== at) quick.style.insetBlockStart = at; |
| + if (quick.style.insetBlockEnd !== "auto") quick.style.insetBlockEnd = "auto"; |
| + } else if (quick.style.insetBlockStart) { |
| quick.style.insetBlockStart = ""; |
| quick.style.insetBlockEnd = ""; |
| } |
| - var h = mode === "keyboard" ? quick.getBoundingClientRect().height : 0; |
| + var h = mode === "keyboard" ? capsuleHeight : 0; |
| if (h !== lastHeight) { |
| lastHeight = h; |
| document.dispatchEvent(new CustomEvent("docs:quickbar", { detail: { height: h } })); |