Repository navigation
fix(ui): srcdoc frame height with collapsed margins + fenceTheme host seam - #1677
Conversation
…eTheme seam
HtmlViewer's bridge reported document.body.scrollHeight, which omits a
child's top/bottom margin that collapses through a margin-less body, so
auto-sized frames were cut short. measureContentHeight places body's box in
document coordinates and adds the bottom margins that can collapse through
it. It never reads documentElement.scrollHeight or anything sized by the
frame, so html{height:100%} pages still grow and shrink. Resize message
shape unchanged, so no BRIDGE_PROTOCOL_VERSION bump.
configurePlannotatorUI({ fenceTheme }) lets a host pick the Shiki theme for
every fence-style surface (everything reading resolveFenceTheme /
useFenceTheme); undefined, empty or a throw falls through to the default.
Plannotator passes nothing.
The new height measure adds collapsed/body margins on top of content that
is sized by the frame (html,body{height:100%}, min-height:100vh, a 100vh
child), so every grow asked for another (Chromium: 600 -> 2600+ in under a
second). Add a feedback guard: the first measure after a grow the parent
applied holds the frame when the page still overflows by as much as before.
Later content changes still resize. Unit test drives the guard.
|
Review fix pushed: the new measure made viewport-sized pages ( |
Two small
@plannotator/uichanges requested by a host embedding the package. No release or version bump.1. HtmlViewer frame height (bug)
Root cause (confirmed in Chromium): the bridge reported
document.body.scrollHeight. When body has no top padding or border, a first child's top margin collapses through body. That moves body's box down without making it taller, so the frame was cut short by the margin, and the same happens at the bottom. Example:body{margin:0}with a 560px card that hasmargin-top:40pxreported 560 instead of 600. Ordinary pages also lost their collapsedh1/last-pmargins (1062 reported vs 1100 true).Fix:
measureContentHeightinbridge-script.tsplaces body's box in document coordinates (its top already includes a collapsed top margin). It then adds the bottom margins that can collapse through body's bottom edge, by walking the last in-flow child chain. The walk skips out-of-flow children (display:none, absolute/fixed, floats, so also a trailing script and the bridge's own overlay), and stops at flex/grid, padded or bordered blocks and scroll containers. The ResizeObserver now also observesdocumentElement, because a change to a collapsed margin moves body without resizing it.Why not
max(documentElement.scrollHeight, body.scrollHeight):documentElement.scrollHeightnever drops below the frame's own viewport, and anhtml{height:100%}root is the frame's height. Either way the frame could grow but never shrink (the initial 600px frame could not get smaller than 600). The new measure reads nothing that the frame sizes.Verified in headless Chromium (real
BRIDGE_SCRIPTin sandboxed srcdoc frames; each value checked against the html box height):html{height:100%}, content 200 → 1500 → 80The
html{height:100%}page now grows and shrinks, with no runaway. Pages whose body is itself viewport-sized (html,body{height:100%},min-height:100vh) behave exactly as before.Protocol version: not bumped. The
resizemessage shape is unchanged and only the value is more accurate, so a cached older asset keeps the old measurement and nothing is misread. The bridge asset files are gitignored and generated at prepack (bun run --cwd packages/ui smoke:packageregenerates them and passes).Regression test:
components/html-viewer/bridgeResize.test.tsruns the shipped function against a hand-built box model. It covers collapsed top and bottom margins, independence from the frame height, the rule that scroll and flex containers stop the chain, and scroll/overflow.2.
fenceThemeseamconfigurePlannotatorUI({ fenceTheme?: (colorTheme, mode) => string | undefined }), also exposed assetFenceThemeResolver/resetFenceThemeResolveronutils/syntaxTheme. A return ofundefined, an empty string or a throw falls through to the default resolution. An unknown theme name renders the fence as plain text, the same as an unknown language does.It lives in
resolveFenceTheme, so it applies consistently to every fence-style surface: Viewer fences,CodeBlock, the code-file hover preview, the plan diff view, and code review'sHighlightedCode. The code-review diff pane's dark/light pair (resolveSyntaxTheme) is deliberately not affected. Plannotator passes nothing, so its output is unchanged. Documented in README.md and HANDOFF.md (seam catalog row plus an "unreleased" section). Tests are inhooks/useFenceTheme.seam.test.tsx; its DOM half is added to the CIDOM_TESTSlist.Checks
bun run typecheck: cleanbun test: all pass (the one initial failure was the DOM-test allowlist, now fixed);DOM_TESTS=1 bun test packages/ui: 2096 passbun run --cwd packages/ui smoke:package: passesbun run --cwd apps/review build && bun run build:hook: okPLANNOTATOR_DATA_DIR, raw-HTML annotate of an ordinary page, a margin card and anhtml{height:100%}page. All rendered correctly. Note that Plannotator's own HTML surfaces (annotate and PR artifacts) usefullViewport, so they ignore the reported height. The auto-height path only matters for hosts, and it was verified with the harness above.