Skip to content

armgit / fx0

Public Imported from GitHub
0

A lightweight design agent built with libfx. Describe a page and an agent writes it as one HTML file.

TypeScript

Merge pull request #30 from vercel-labs/esteban/fx0-screenshot-preview

Esteban Suáreze1045b3518fe
diff --cc lib/design-artifact.ts
index 789447a,ff366c4..f1cb5a1
--- a/lib/design-artifact.ts
+++ b/lib/design-artifact.ts
@@@ -124,11 -137,12 +138,15 @@@ frame.setAttribute('credentialless','')
let readySignals=0;
let consumedSignals=0;
let lastHeartbeat=Date.now();
+ // A capture can hold off restores while the design is busy photographing itself (lib/design-capture.ts).
+ let holdUntil=0;
+ // The capture runtime, bound to each child's own token by the restore that builds that child.
+ const captureRuntimeJs=${runtimeJs};
const safe=value=>JSON.stringify(value).replaceAll('<',String.fromCharCode(92)+'u003c');
-const painted=()=>parent.postMessage(preview?{type:'fx0-artifact-painted',protocol:1,sessionId:preview.sessionId,revision:current.revision,documentId,updateReady:hotReady}:{type:'fx0-artifact-painted'},location.origin);
+// A child's rAF can run before this wrapper finishes loading. Revealing that
+// still-loading wrapper exposes the app background (black in dark mode).
+const painted=()=>{if(hasLoaded)parent.postMessage(preview?{type:'fx0-artifact-painted',protocol:1,sessionId:preview.sessionId,revision:current.revision,documentId,updateReady:hotReady}:{type:'fx0-artifact-painted'},location.origin);};
+addEventListener('load',()=>{hasLoaded=true;if(hasPainted)painted();},{once:true});
const reply=(task,status,reason)=>parent.postMessage({type:'fx0-preview-result',protocol:1,sessionId:preview.sessionId,requestId:task.requestId,documentId:task.documentId,revision:task.payload.revision,status,...(reason?{reason}:{})},location.origin);
const finish=(task,status,reason)=>{if(pending!==task)return;pending=null;task.controller.abort();reply(task,status,reason);};
const restore=()=>{
diff --cc tests/preview-update.browser.mjs
index 2aff802,7ed93c9..e4130f0
--- a/tests/preview-update.browser.mjs
+++ b/tests/preview-update.browser.mjs
@@@ -116,11 -118,12 +118,12 @@@ async function buildPaneFixture(directo
import { createElement, useEffect, useState } from 'react'
import PreviewPane from './compiled/components/preview-pane.js'
export function Fixture() {
- const [revision, setRevision] = useState(101), [viewing, setViewing] = useState(null)
+ const [revision, setRevision] = useState(${initialRevision}), [viewing, setViewing] = useState(null)
const [sessionId, setSession] = useState(${JSON.stringify(SESSION)}), [draft, setDraft] = useState(null)
- const [accessAllowed, setAccessAllowed] = useState(true)
+ const [accessAllowed, setAccessAllowed] = useState(true), [capture, setCapture] = useState(null)
useEffect(() => {
- Object.assign(window, { setRevision, setViewing, setSession, setDraft, setAccessAllowed, fixtureReady: true })
+ window.captureResults = []
+ Object.assign(window, { setRevision, setViewing, setSession, setDraft, setAccessAllowed, setCapture, fixtureReady: true })
const revoke = () => { setAccessAllowed(false); setRevision(0) }
window.addEventListener('fx0:auth-required', revoke)
return () => window.removeEventListener('fx0:auth-required', revoke)