Live preview
How live preview works
The editor loads the real site route in a frame, with ?genga-preview=<id>. The route renders
the draft on the server. After that, the editor sends each change with postMessage, and
the page renders again without a reload.
sequenceDiagram
autonumber
participant E as Editor (admin)
participant F as Preview frame (your route)
participant S as Server (loadForRoute)
E->>F: Load /studio?genga-preview=id
F->>S: GET with the session cookie
S-->>F: SSR of the draft, Cache-Control no-store
F->>E: genga:ready
loop At each keystroke, at most once per animation frame
E->>F: genga:draft (populated draft)
F->>F: usePreviewData renders your components again
end
F->>E: genga:select (click on a block)
E->>F: genga:focus (highlight the selected block)
- Same origin (library mode): the frame reads the draft with the session cookie.
- Another origin (headless mode): the preview URL carries an HMAC token, valid 10 minutes
for one document.
connectPreviewfromgenga/preview(about 6 KB, no dependency) works in any framework.
Both sides post only to the exact origin of the other side, and check event.origin and
event.source. Read preview bridge.