Repository navigation
Extract a shared GuestFrame for RenderedFrame and DemoCard - #294
Conversation
There was a problem hiding this comment.
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.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
5423d30 to
bbb3430
Compare
c1bff14 to
229f9bd
Compare
bbb3430 to
df74945
Compare
229f9bd to
82bd1d2
Compare
wrenj
left a comment
There was a problem hiding this comment.
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.
82bd1d2 to
0547ddd
Compare
df74945 to
230d894
Compare
0547ddd to
f889f28
Compare
230d894 to
99b20eb
Compare
f889f28 to
042b5f9
Compare
wrenj
left a comment
There was a problem hiding this comment.
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.
042b5f9 to
a9c1e8e
Compare
99b20eb to
9648789
Compare
9648789 to
acc8eee
Compare
a9c1e8e to
a235ffa
Compare
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.
a235ffa to
c63ff8b
Compare
Summary
Stacked on
resizing/2-demo-wall.Phase 3 of simplifying preview iframe sizing — shared
GuestFramecomponent:guest-frame-selectors.ts,rendered-frame-selectors.ts,demo-card-selectors.ts), Playwright frame locators (preview-frame-locators.ts), andRENDERER_URLS(renderer-urls.ts) undershell/src/app/preview/testing/.<a2ui-composer-guest-frame>(GuestFrame):buildRendererUrl) andDomSanitizertrust,HostCommunicationregistration (DefaultTarget.REPLACEvsDefaultTarget.KEEP),RENDERER_READY/A2UI_CATALOG/(load)handshake gating,stableStringifypayload deduplication, andSURFACE_RESIZEsourceWindowvalidation into a single component used by bothRenderedFrameandDemoCard.HostCommunication(broadcasting toreadyWindowsonthemePreferencechanges and sending the initial theme once duringRENDERER_READY).RenderedFrameandDemoCardontoGuestFrame:RenderedFrameandDemoCardto layout/sizing hosts around<a2ui-composer-guest-frame>.guest-frame.spec.tsandguest-frame-sends.e2e.tsverifying outboundpostMessagecounts across all 3 bundled renderers.