Repository navigation
Commit demo card heights once after content settles and lock them - #293
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a robust content-settling mechanism for the preview bridge, ensuring that surface dimensions are reported only after content has stabilized (e.g., fonts and images loaded). It updates the A2uiSandboxConnection to wait for markdown rendering and adds comprehensive end-to-end tests to verify commit accuracy under various conditions. I have reviewed the implementation and provided a suggestion to optimize the DOM traversal in imagesComplete to improve performance during frequent sampling.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
5423d30 to
bbb3430
Compare
8f6eaff to
29d7060
Compare
bbb3430 to
df74945
Compare
wrenj
left a comment
There was a problem hiding this comment.
Reviewed PR #293. Left comments on sizing reducer edge cases (unmount cleanup while a window timer is running, remounted committed cards on render failure or legacy bridges, and multi-step width changes during an active fresh-commit window) and bridge settle/readiness edge cases (last = current while fonts/images are still loading, lazy-loaded images under the 32px measure frame, and contentReady when measure() is null).
230d894 to
99b20eb
Compare
b3f0c14 to
4213265
Compare
wrenj
left a comment
There was a problem hiding this comment.
Took another look at PR #293 (99b20eb2). Left follow-up comments on onAvailableWidthChanged preserving kind: 'error' on remounted cards, older-bridge pre-RENDER_SUCCESS height recording in onResizeCommitted, the last !== null && current !== last short-circuit in waitForContentToSettle, and Angular TextComponent render-pass timing in onInitialRender.
4213265 to
084fd9b
Compare
99b20eb to
9648789
Compare
Add an e2e sweep over every demo on the demo wall for the Angular, Lit and React renderers. Each card is brought on screen, and its frame height, in guest pixels, must match the guest's content height, capped at MAX_CONTENT_HEIGHT_PX, within 2px. Content is measured like SurfaceResizeObserver does, after document.fonts.ready. The same test sweeps two more pages that hold the frame at 600px and at 100px before it commits, by overriding --demo-card-measure-h. Each of their commits must match the default run's for the same demo laid out at the same width, so the measurement can't follow the frame's own height even for content that fills its viewport. Cards that the wall resizes after their commit, in any of their frames, are reported, not asserted: the current card only follows growth, so it keeps a taller height when a wider layout makes the demo shorter. Each run attaches the report trace per card, the demos whose content changed after webfonts loaded, and the demos whose content differs from their first contentReady report. This is the baseline for making demo cards commit their height once.
The first content a renderer commits is often not its final size: nested components render on later ticks, images decode and webfonts swap in. On the demo wall the first contentReady report differed from the final height in 33 of 46 Angular and 35 of 46 React demos. After onInitialRender resolves, PreviewBridge now also waits until no webfont is loading (checked on every sample, since the browser replaces document.fonts.ready when a new font starts loading), every image has finished loading (including images in open shadow roots), and the measured dimensions stay unchanged for CONTENT_QUIET_MS (150ms). The whole wait, onInitialRender included, is capped at CONTENT_SETTLE_MAX_MS (2s) from the render, so readiness reaches the host within that of RENDER_SUCCESS. The generation and renderer guards cancel the wait, and an onInitialRender that rejects before the cap behaves as before. The Angular bridge's onInitialRender also waits for the lazily loaded markdown renderer. Until it loads, markdown Text renders empty with stable dimensions, so under CPU load the quiet period could pass before the text appeared. The constants and the settle logic live in content-settle.ts, and the constants are exported for hosts. SurfaceResizeObserver exposes the measurement it reports, so the wait compares the same dimensions. Only DemoCard reads contentReady.
A demo card now commits its height once and keeps it. Content that changes afterwards scrolls inside the card, so the wall no longer reflows under the reader. The rules live in a pure reducer, demo-card-sizing.ts; DemoCard only feeds it events and renders it. - The card commits the first contentReady report above MEASURE_HEIGHT_PX that arrives while it is visible. An IntersectionObserver on the frame, with no root margin, gates this, because Chrome does not render a cross-origin frame that is out of view. A ready report from a hidden card waits until the card is visible, then the latest report is committed after a short window. - A remounted frame keeps the committed height; a renderer switch starts over. - RENDER_ERROR before the commit puts the card in the error state. - Older bridges wait up to 1s for the first report after RENDER_SUCCESS, then commit once no new report has arrived for 300ms; the ready timeout bounds the wait. A current bridge that never marks its content ready commits the latest report after a window longer than the bridge's settle cap, which counts from the same render. - Widening converges before the commit. When the card's frame width changes after the commit, one fresh commit is offered from a report laid out at the new width. It closes when the width returns to the committed one, when it is taken, or 1s after the card is visible. - MEASURE_HEIGHT_PX and MAX_CONTENT_HEIGHT_PX are bound on the host as --demo-card-measure-h and --demo-card-max-h. Every window duration is in one exported table, SIZING_WINDOW_MS, next to READY_TIMEOUT_MS. The measurement window, the growth phase and their timers are gone. A DemoCardHarness replaces the spec's direct DOM queries. E2E: the commit-accuracy sweep asserts every card, checks that the pre-commit frame height doesn't change any commit, and runs once more under 4x CPU throttling for Angular and React. New journeys check that growth after the commit keeps the card and the wall in place and scrolls inside the card, that a card scrolled away and back keeps its height, that cards commit fresh heights after a renderer change, and that the wall settles with no card committing more than twice. The demo e2e tests share demo-wall-helpers.ts.
- Reset DemoCard visibility on iframe unmount to stop open timers - Arm ready timeout and enter error state on unrevealed remounts - Guard older-bridge remount resize reports before RENDER_SUCCESS - Discard in-flight re-measurements across multi-step width changes - Require full quiet window after font and eager image completion - Defer contentReady until measurable and skip failed stream renders - Resolve superseded Angular initial render promises and markdown
9648789 to
acc8eee
Compare
Summary
Stacked on
resizing/1-frame-sizing.Phase 2 of simplifying preview iframe sizing — Demo Wall settle & single-commit height locking:
contentReady: true(a2ui-bridge):waitForContentToSettle(bridge/src/content-settle.ts), which waits afteronInitialRenderuntil webfonts (document.fonts.status !== 'loading'), images (HTMLImageElement.complete, including open shadow roots), and measured document dimensions have been quiet for150ms(CONTENT_QUIET_MS), bounded by a2000mscap (CONTENT_SETTLE_MAX_MS) from render start.A2uiSandboxConnection.onInitialRender(bridge/src/angular/angular-bridge.ts) to await@a2ui/angular's lazyMarkdownRenderer.render('')beforeafterNextRenderso markdown-containing surfaces do not report pre-markdown heights.shell/src/app/demos/demo-card-sizing.ts):DemoCardheight tracking and the post-reveal repack timer with a pure state machine (DemoCardSizing) that commits a card's height once (capped atMAX_CONTENT_HEIGHT_PX = 560px) when settled content is ready and locks it.committedFrameWidth), and supports older bridges (contentReady === undefined) via aRENDER_SUCCESSquiet-window fallback.demo-card-commit-accuracy.e2e.ts(46 demos × 3 renderers + 4× CPU-throttled markdown demos),demo-card-locked-height.e2e.ts,demo-wall-quiescence.e2e.ts, anddemo-card-sizing.spec.ts.