/** * A quick preview: a proposal's page, running the proposal's CLIENT code * built in the Studio, without a build being uploaded or served. * * A full build of a proposal bundles the app for the server and the browser, * uploads it, and has the platform render every page before it is served -- * minutes. Most of what the assistant changes is components and styles, * which the browser half alone shows. So the tab bundles the app in its * builder worker, and a service worker on the proposal's address hands the * page that bundle instead of the served one: * * 1. The tab sends the files (`/_app/app.js`, its chunks, the stylesheet and * assets) to the page in the preview, over the canvas protocol. * 2. The page -- the bridge, which is the only thing at that origin the tab * can talk to -- registers {@link QUICK_PREVIEW_SERVICE_WORKER_SOURCE} * and stores the files in it (Cache Storage, so a worker the browser * stopped still has them). * 3. The tab opens the page with `?val_quick=`. The worker serves that * document's `/_app/` requests from the files, and everything else from * the network: the HTML is the last build's, rendered by its server, and * the new code takes it over in the browser. * 4. It takes it over by RENDERING it, not by hydrating it. Hydration keeps * the markup the server sent wherever only an attribute differs -- React * mends text, never a `className` -- so a change to classes and props, * which is most of what the assistant changes, hydrated into the old * page and showed nothing. The worker adds a script to the end of that * document's `` ({@link QUICK_PREVIEW_RENDER_SCRIPT}) that takes the * server's markup out before the app's scripts run, so hydration finds * nothing to keep and React renders the page with the new code. * * What it cannot show, and the tab says so: anything on the server. Server * functions, API routes and loaders that run there are the last build's, as * is the page's first render and its `head`. A new dependency is not there * either. A build is still what decides, before Publish. * * Only a document opened with the parameter is served from the files, so a * visitor to the proposal's address -- even in the same browser -- is never * given them. */ /** The parameter a quick preview's page is opened with. */ export declare const QUICK_PREVIEW_PARAM = "val_quick"; /** Where Val's API serves the worker: under `/api/val`. */ export declare const QUICK_PREVIEW_SERVICE_WORKER_PATH = "/quick-preview-sw.js"; /** * What a quick preview's document runs before the app's scripts: the * server's markup out of ``, every script left where it is -- the * router's dehydrated state and the app's entry are among them. Hydration * then finds the body empty and React renders the page, with the new code's * attributes and classes, where it would have kept the old ones. */ export declare const QUICK_PREVIEW_RENDER_SCRIPT: string; /** What the page sends the worker to store a preview's files. */ export declare const QUICK_PREVIEW_STORE_MESSAGE = "val-quick-preview-store"; /** * A preview's files, by their path under `/_app/`: `app.js`, `c-.js`, * `app.css`, `a/.png`. A binary file is base64. */ export type QuickPreviewFiles = Record; /** * The files of a quick preview: paths under `/_app/` with no way out of it, * each a string body and a type. */ export declare function isQuickPreviewFiles(value: unknown): value is QuickPreviewFiles; /** * The worker, as the source it is served as: plain, and small, because it is * served as a file of its own (`demoServiceWorker.ts` is the same). */ export declare const QUICK_PREVIEW_SERVICE_WORKER_SOURCE: string; /** * Store a preview's files in the worker, registering it first: what the * bridge does when the tab sends `quickPreview`. `swUrl` is the worker's * address on this origin (`/api/val` + {@link QUICK_PREVIEW_SERVICE_WORKER_PATH}). */ export declare function storeQuickPreview(id: string, files: QuickPreviewFiles, options: { swUrl: string; container?: ServiceWorkerContainer; }): Promise; /** The address of a page as a quick preview `id`. */ export declare function withQuickPreviewParam(url: string, id: string): string;