Skip to content

Extract a shared GuestFrame for RenderedFrame and DemoCard - #294

Merged
jgindin merged 4 commits into
mainfrom
resizing/3-guest-frame
Oct 26, 2026
Merged

jgindin merged 4 commits into
mainfrom
resizing/3-guest-frame

Conversation

@jgindin

@jgindin jgindin commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Stack: #291 → #293 → #294

Summary

Stacked on resizing/2-demo-wall.

Phase 3 of simplifying preview iframe sizing — shared GuestFrame component:

  1. Centralize preview frame selectors, Playwright locators, and renderer URL constants:
    • Extracts shared selector constants (guest-frame-selectors.ts, rendered-frame-selectors.ts, demo-card-selectors.ts), Playwright frame locators (preview-frame-locators.ts), and RENDERER_URLS (renderer-urls.ts) under shell/src/app/preview/testing/.
  2. Extract <a2ui-composer-guest-frame> (GuestFrame):
    • Consolidates iframe creation, URL construction (buildRendererUrl) and DomSanitizer trust, HostCommunication registration (DefaultTarget.REPLACE vs DefaultTarget.KEEP), RENDERER_READY / A2UI_CATALOG / (load) handshake gating, stableStringify payload deduplication, and SURFACE_RESIZE sourceWindow validation into a single component used by both RenderedFrame and DemoCard.
    • Consolidates theme delivery in HostCommunication (broadcasting to readyWindows on themePreference changes and sending the initial theme once during RENDERER_READY).
  3. Refactor RenderedFrame and DemoCard onto GuestFrame:
    • Reduces RenderedFrame and DemoCard to layout/sizing hosts around <a2ui-composer-guest-frame>.
    • Adds guest-frame.spec.ts and guest-frame-sends.e2e.ts verifying outbound postMessage counts across all 3 bundled renderers.

@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 new GuestFrame component to encapsulate sandboxed iframe management, registration, payload dispatching, and inbound message filtering. Both RenderedFrame and DemoCard are refactored to use this component, eliminating duplicate logic. Additionally, the theme broadcast mechanism is centralized within HostCommunication via an Angular effect. A comprehensive suite of E2E tests (guest-frame-sends.e2e.ts) is added to verify these changes, and existing tests are updated to use centralized preview frame locators and selectors. I have no feedback to provide on the changes.

@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 c63ff8b):
👉 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/3-guest-frame branch from c1bff14 to 229f9bd 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 force-pushed the resizing/3-guest-frame branch from 229f9bd to 82bd1d2 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 #294. Left comments on in-place iframe reload state in GuestFrame.onLoad(), DemoCard timeout/mount behavior when resolvedUrl() is null or unsafe, RenderedFrame defaultTarget / (documentReplaced) wiring, and lastSentPayload reset when payload() clears to null/empty.

Comment thread shell/src/app/demos/demo-card.ts Resolved
@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from 82bd1d2 to 0547ddd Compare October 22, 2026 22:35
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from df74945 to 230d894 Compare October 22, 2026 22:35
@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from 0547ddd to f889f28 Compare October 23, 2026 15:03
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from 230d894 to 99b20eb Compare October 23, 2026 15:03
@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from f889f28 to 042b5f9 Compare October 23, 2026 15:59
@jgindin
jgindin requested a review from wrenj October 23, 2026 16:06

@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 #294 (042b5f93). Left comments on GuestFrame.onLoad() reload ordering with StrictMode / mixed-order loads, RenderedFrame.onRendererReady() when GuestFrame deduplicates RENDER_A2UI, double registerIframe on initial GuestFrame mount, and HostCommunication untargeted message routing with DefaultTarget.KEEP.

@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from 042b5f9 to a9c1e8e 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
@jgindin
jgindin force-pushed the resizing/2-demo-wall branch from 9648789 to acc8eee Compare October 26, 2026 15:38
@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from a9c1e8e to a235ffa Compare October 26, 2026 15:38
Base automatically changed from resizing/2-demo-wall to main October 26, 2026 16:06
The GuestFrame extraction moves the preview iframes and their classes.
Read every selector that reaches into RenderedFrame or DemoCard from
one place, so that change touches only the selector modules.

- rendered-frame-selectors.ts and demo-card-selectors.ts hold the
  internal selectors. They are free of Angular, so the component
  harnesses and the Playwright tests can both import them.
- src/app/preview/testing/preview-frame-locators.ts holds the
  Playwright frame locators. The frame host locators move here from
  e2e/helpers.ts, joined by previewIframe, previewFrame,
  firstPreviewFrame, renderedFrameContainer, sideCanvasFrame,
  inlineSurfaceIframe and inlineSurfaceFrame (both with an optional
  index), and the demoCard* locators. It is free of Angular too, so
  the e2e tests and the visual tests under src import it directly.
- RENDERER_URLS moves from e2e/helpers.ts to
  src/app/preview/testing/renderer-urls.ts, so that no visual test
  imports from e2e.
- Code that runs in the page imports the selector modules and gets
  the selectors as arguments.
- chat-message.scss turns off the frame background by setting
  --rendered-frame-background on the frame host. It no longer
  overrides .rendered-frame-container through ::ng-deep.
  rendered-frame.scss reads the property in both themes and falls
  back to the current surface colours.

No behavior change. Every rewritten locator matches the same elements
as before: each card holds one iframe, and on the workspace pages every
top-level iframe is a RenderedFrame iframe.
GuestFrame owns the sandboxed renderer iframe that RenderedFrame and
DemoCard each built: the URL (buildRendererUrl, sanitized, with
projected fallback content while there is none), registration with
HostCommunication (defaultTarget, REPLACE unless the host passes
KEEP), the payload send and the inbound messages. RawFrame has no
iframe and is not part of it. RenderedFrame now hosts a GuestFrame
and keeps only its sizing, the chat lock overlay and the session
reset; DemoCard moves onto it in the next commit.

Payload sends go through one idempotent syncPayload(), called on
RENDERER_READY and on every payload change. It sends only once the
current document has announced itself, so nothing is handed to
sendRenderA2UI early, where it would be queued and delivered again
by the READY flush. It skips a payload whose stableStringify form
equals the last one sent to the current document: a second identical
RENDER_A2UI replays createSurface and drops what the user typed, and
A2aChatView rebuilds identical payload arrays when the first catalog
resolves, which wiped inline form input on Lit and React. A load
event or a renderer URL change never sends.

The iframe's initial about:blank load is ignored. The first renderer
load belongs to the document that may already have announced
RENDERER_READY, so READY, load, READY and load, READY, READY each
send once. A later load with no URL change is a guest reload, a new
document that has been sent nothing. If the old document announced
itself before its load and a READY came after that load, the reload
is taken to have announced itself already: the frame stays ready, so
the next payload change or a repeat READY reaches it. Otherwise the
frame waits for the new document's READY. Without a per-document id
in RENDERER_READY both rules guess; GuestFrame.onLoad documents the
orders they get wrong.

Inbound filtering is strict: an envelope without a source window, or
from any window but the frame's own, is dropped, including the
replay that arrives before the iframe exists. Accepted messages come
out as typed outputs, one emission per message and in order:
surfaceResize (validated by CrossFrameValidator), rendererReady,
renderSuccess and renderError. documentReplaced reports a renderer
URL change. The iframe's accessible name is the frameTitle input.

A2UI_CATALOG no longer re-sends the payload. With the re-send gone,
a GET_CATALOG posted to an inline frame showing a surface got its
A2UI_CATALOG reply, and the surface and a value typed into it stayed,
with no further RENDER_A2UI, on the Angular, Lit and React renderers.
The bridge's catalog handler does not touch rendered surfaces.

Theme changes have one owner: HostCommunication, a root service that
already sends the current theme on every handshake. An effect there
broadcasts each preference change once, through a now private
sendTheme that posts to every ready frame, KEEP frames included, and
queues nothing, not even with no frame registered: frames not yet up
get the theme in their URL and on their own handshake. The per-frame
theme effect in RenderedFrame, which sent a toggle once per mounted
frame, is removed; demo cards keep getting the broadcast.
A demo card now hosts its renderer in a GuestFrame, mounted under the
same mount gate and registered with DefaultTarget.KEEP so the /demos
coordinator stays the default target. The card's own URL building
and sanitizing, its registration effect, its messageStream$
subscription and SURFACE_RESIZE validation, and its send guard
(payloadSentForCurrentLoad, onFrameLoad and the re-arm on a URL
change) are removed; GuestFrame's send state machine replaces them.
A load event between two RENDERER_READY announcements of one
document no longer sends the demo a second time; a renderer change
still re-arms the send for the new document.

The sizing reducer is fed from GuestFrame's typed outputs, one event
per guest message: surfaceResize, rendererReady, renderSuccess and
renderError, and documentReplaced resets it for another renderer, so
the card no longer watches StartupResolution itself. Envelopes
without a source window are now dropped, as envelopes from other
windows already were. The visibility gate observes the GuestFrame
host, which its iframe fills exactly, and an older bridge's missing
viewport width falls back to that host's width. The
--demo-preview-scale transform and the measuring height apply to the
GuestFrame host. Placeholder, error chrome, reveal and the
commit-once rules are unchanged.

Demo cards keep receiving theme changes through HostCommunication's
broadcast, introduced in the previous commit; the card sends none.

The demo card's selectors and harness build on GuestFrame's:
DEMO_CARD_SELECTORS.iframe comes from GUEST_FRAME_SELECTORS, and
DemoCardHarness delegates to GuestFrameHarness.

E2E (guest-frame-sends), counted from inside each guest document:
on the Angular, Lit and React renderers, each inline surface, side
canvas and demo card document gets exactly one RENDER_A2UI, also with
webfonts held so load follows READY, and the default-target frames
get none they were not meant to; a value typed into an inline surface
survives the first catalog resolution; a guest reload with no URL
change gets the payload again; and each theme toggle reaches every
frame exactly once, on /demos, in the workspace, on /a2a and on
/gallery. Frames are told apart by a table of preview hosts that
preview-frame-locators.ts now exports.
Ensure GuestFrame re-sends payloads on pre-load reloads and after
clearing payloads, gate DemoCard mounting on an active iframe, and
bind GuestFrame lifecycle outputs and required defaultTarget in
RenderedFrame.
@jgindin
jgindin force-pushed the resizing/3-guest-frame branch from a235ffa to c63ff8b Compare October 26, 2026 16:19
@jgindin
jgindin merged commit 229e7c2 into main Oct 26, 2026
15 checks passed
@jgindin
jgindin deleted the resizing/3-guest-frame branch October 26, 2026 16:45
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