Skip to content

Commit demo card heights once after content settles and lock them - #293

Merged
jgindin merged 4 commits into
mainfrom
resizing/2-demo-wall
Oct 26, 2026
Merged

jgindin merged 4 commits into
mainfrom
resizing/2-demo-wall

Conversation

@jgindin

@jgindin jgindin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Stack: #291 → #293 → #294

Summary

Stacked on resizing/1-frame-sizing.

Phase 2 of simplifying preview iframe sizing — Demo Wall settle & single-commit height locking:

  1. Wait for rendered demo content to settle before signaling contentReady: true (a2ui-bridge):
    • Adds waitForContentToSettle (bridge/src/content-settle.ts), which waits after onInitialRender until webfonts (document.fonts.status !== 'loading'), images (HTMLImageElement.complete, including open shadow roots), and measured document dimensions have been quiet for 150ms (CONTENT_QUIET_MS), bounded by a 2000ms cap (CONTENT_SETTLE_MAX_MS) from render start.
    • Updates A2uiSandboxConnection.onInitialRender (bridge/src/angular/angular-bridge.ts) to await @a2ui/angular's lazy MarkdownRenderer.render('') before afterNextRender so markdown-containing surfaces do not report pre-markdown heights.
  2. Commit Demo Wall card heights once and lock them (shell/src/app/demos/demo-card-sizing.ts):
    • Replaces continuous DemoCard height tracking and the post-reveal repack timer with a pure state machine (DemoCardSizing) that commits a card's height once (capped at MAX_CONTENT_HEIGHT_PX = 560px) when settled content is ready and locks it.
    • Subsequent content growth scrolls inside the card instead of shifting the masonry wall.
    • Allows one bounded fresh commit only when the card's frame width actually changes (committedFrameWidth), and supports older bridges (contentReady === undefined) via a RENDER_SUCCESS quiet-window fallback.
  3. E2E & Unit Verification:
    • Adds 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, and demo-card-sizing.spec.ts.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bridge/src/content-settle.ts Resolved
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

⚡ A2UI Composer PR Preview

Your automated preview is successfully live (commit acc8eee):
👉 Launch PR Preview

Note: This environment will be wiped automatically when the PR is merged or closed.

@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from 5423d30 to bbb3430 Compare October 22, 2026 16:32
@jgindin
jgindin force-pushed the resizing/1-frame-sizing branch from 8f6eaff to 29d7060 Compare October 22, 2026 16:32
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from bbb3430 to df74945 Compare October 22, 2026 16:54
@jgindin
jgindin requested review from mikzat and wrenj October 22, 2026 17:12

@wrenj wrenj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread shell/src/app/demos/demo-card.ts Resolved
Comment thread shell/src/app/demos/demo-card-sizing.ts Resolved
Comment thread shell/src/app/demos/demo-card-sizing.ts Resolved
Comment thread bridge/src/content-settle.ts Resolved
Comment thread bridge/src/content-settle.ts Resolved
Comment thread bridge/src/preview-bridge.ts Resolved
Comment thread bridge/src/angular/angular-bridge.ts Resolved
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch 2 times, most recently from 230d894 to 99b20eb Compare October 23, 2026 15:03
@jgindin
jgindin force-pushed the resizing/1-frame-sizing branch from b3f0c14 to 4213265 Compare October 23, 2026 15:03
@jgindin
jgindin requested a review from wrenj October 23, 2026 15:34

@wrenj wrenj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shell/src/app/demos/demo-card-sizing.ts Resolved
Comment thread shell/src/app/demos/demo-card-sizing.ts Resolved
Comment thread bridge/src/content-settle.ts Resolved
Comment thread bridge/src/angular/angular-bridge.ts Resolved
@jgindin
jgindin force-pushed the resizing/1-frame-sizing branch from 4213265 to 084fd9b Compare October 23, 2026 20:51
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from 99b20eb to 9648789 Compare October 23, 2026 20:51
@jgindin
jgindin requested a review from wrenj October 26, 2026 14:37
Base automatically changed from resizing/1-frame-sizing to main October 26, 2026 15:20
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
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from 9648789 to acc8eee Compare October 26, 2026 15:38
@jgindin
jgindin merged commit 39c0ad5 into main Oct 26, 2026
15 checks passed
@jgindin
jgindin deleted the resizing/2-demo-wall branch October 26, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants