Files
AFFiNE/packages/frontend/hosts/web/AGENTS.md
T
DarkSky 445a1092e9 feat(desktop): keep Web Desktop workspaces in IndexedDB
Read and write each workspace through its IndexedDB v3 store.
Keep document edits and deletions in order across retries and reloads.
Seed empty workspaces under the startup lock and release it if a write
cannot start or the connection closes.

Wait for pending transactions and read the stored clocks before each
retry. Cancel queued retries when the connection closes. Compact a
document only when its snapshot and all source updates still match.
2026-12-02 15:10:57 +09:00

2.9 KiB

Working in packages/frontend/hosts/web/ (for agents)

This directory holds the zero-build Web Mobile host and the desktop/ Workbench entry for AFFiNE. It uses plain HTML and standard ES modules with JSDoc types. desktop/start.js keeps each Workbench workspace in the same IndexedDB v3 store as the Web Mobile host (src/idb-storage.js), passes the stored update frames to wasm_desktop_main, and calls flush_web_desktop when the page is hidden or unloaded.

Hard boundaries

  • Keep zero package.json files and zero yarn.lock files in packages/frontend/hosts/.

  • Keep zero third-party npm imports in src/*.js. Use relative ES module imports only.

  • Keep index.html Content Security Policy free of third-party script domains.

  • Keep permanent visual DOM in index.html limited to <canvas id="app-canvas"> and <textarea id="ime">.

  • Keep at most one aria-hidden="true" zero-size safe-area probe in index.html.

  • Keep #embed-layer empty at rest. Strip allow-same-origin from every user HTML iframe.

  • Load Cloudflare Turnstile only inside sign-in.html, and only after /api/auth/captcha returns a challenge.

  • Flush pending CRDT writes before any login or legacy fallback navigation. Abort navigation if the flush fails.

Verification

Run the deterministic Node test suite and zero-third-party-JS gate from packages/frontend/:

node --test hosts/web/tests/*.test.mjs
node hosts/web/scripts/verify-zero-third-party-js.mjs

Run the browser tests from the repository root with Yarn dependencies and Chromium installed:

node --test packages/frontend/hosts/web/tests/*.browser.mjs

Set BUILT_MOBILE_DIST to the directory that contains the built mobile index.html. After building the four blocksuite-preview wasm32-unknown-unknown workers (cargo rustc --profile wasm-worker-size --lib --crate-type cdylib) and the main playground Wasm bundle (wasm-bindgen --target web, --profile wasm-release-size --lib), stage the binaries plus static fonts and run the end-to-end worker and real-browser verification scripts:

node hosts/web/scripts/stage-preview-workers.mjs /tmp/preview-wasm dev-local
node hosts/web/scripts/stage-canary-dual-shell.mjs --out /tmp/canary-static-root --wasm-dir /tmp/preview-wasm --legacy-dir "$BUILT_MOBILE_DIST"
node hosts/web/scripts/verify-preview-workers-e2e.mjs
node hosts/web/scripts/verify-idb-real-browser.mjs
node hosts/web/scripts/verify-s3-web-real-browser.mjs
node hosts/web/scripts/verify-canary-dual-shell-browser.mjs /tmp/preview-wasm
node hosts/web/scripts/verify-canary-dual-shell-e2e.mjs --out-dir /tmp/canary-e2e

After building affine-desktop for wasm32-unknown-unknown and running wasm-bindgen --target web --out-name affine_desktop into <pkg>, verify that the Workbench keeps created and edited documents across a reload:

node hosts/web/scripts/verify-desktop-persistence.mjs --pkg <pkg> --out /tmp/desktop-persistence