Client shell internals ​

The client is a Vue 3 application that owns presentation and orchestration. It never executes Frappe directly and does not proxy backend requests itself.

Composition root ​

packages/client/src/main.js mounts App.vue. The root component composes four modules in src/composables/: use-playground-lifecycle.js, use-frame-navigation.js, use-app-manager.js, and use-instance-manager.js. They own:

  • five-stage boot progress and errors;
  • iframe source and displayed address;
  • instance catalog and active instance;
  • optional-app catalog, installed IDs, and pending operations.

Presentation remains in src/components/. Runtime lifecycle code lives in src/playground/ so it can be contract-tested without rendering Vue.

Controller lifecycle ​

PlaygroundController is an event emitter with progress, ready, error, waking_up, and woke_up events. start() is idempotent while running and proceeds in this order:

  1. resolve or create the requested session;
  2. register and validate the build-versioned Service Worker;
  3. create a dedicated module worker with scope/freshness query parameters;
  4. transfer a new channel to the two workers; and
  5. open recovery listeners.

The controller records installed app IDs only after runtime:ready. A second ready message means a recovered channel and emits woke_up instead of repeating initial readiness.

dispose() is the ownership boundary. It aborts pending startup and boot-flag requests, retires the owned Service Worker channel, clears timers, rejects pending app operations, terminates the dedicated worker, closes the BroadcastChannel, removes lifecycle listeners, and clears event subscribers. Switching instances always disposes the old controller first.

Service Worker coordination and upgrades ​

Worker URLs include a source-derived build query parameter. ServiceWorkerCoordinator (src/playground/sw-coordinator.js) encapsulates Service Worker registration, version checking, update checking, and controller change lifecycle management.

The coordinator validates whether the active registration or page controller matches the expected worker URL. If an older script controls the page, it bounds the wait for a controller change with an upgrade timeout (default 30 seconds) rather than sending current protocol messages to an obsolete worker.

The first controller transition during initial install or legacy upgrade is expected. A later transition triggers one guarded top-level reload via setupControllerChangeReload so the Vue shell and origin worker move releases together. On every return to a visible tab, the coordinator calls checkForServiceWorkerUpdate() and transfers a fresh channel; update errors are logged but do not block the active runtime.

App operation correlation ​

Install and uninstall calls validate the app ID, require a ready runtime, generate a UUID when Web Crypto provides one (with a time/random fallback), and store promise handlers by request ID. Result messages settle only their matching promise. Disposal rejects outstanding calls; a ten-minute timer bounds operations whose worker never responds.

The UI also prevents simultaneous install/uninstall clicks. The server worker provides the stronger serialization guarantee.

Iframe and address synchronization ​

The iframe is mounted only after the selected runtime is ready. Switching instances removes the old iframe and creates a fresh one, avoiding empty-URL navigation during teardown. The iframe is same-origin but internally scoped. iframe-navigation.js normalizes entered/boot paths, strips legacy query scopes, and adds the selected path scope. use-frame-navigation.js polls the iframe location every 500 ms because Frappe can change routes without notifying the shell.

On each successful inspection, the shell:

  • removes scope and _frappe_playground_bounce from the displayed address;
  • attempts one-time login-field prefilling;
  • adds a Safari password-field font fix; and
  • mirrors Frappe’s dark-mode marker onto the parent document.

The shell accepts frappe-playground-nested-shell messages only from its same-origin iframe and removes the listener on unmount. It rebuilds a scoped target and adds a timestamp bounce parameter, forcing Vue to update the iframe even when the nominal URL appears unchanged.

Boot flags and failure cleanup ​

Boot flags run only after the backend is ready and before the iframe is shown. This allows app installation and authenticated setup API calls to use the worker without racing the initial Frappe page.

A failed initialization disposes its worker and retains the instance catalog and saved state for retry. Each initialization uses its own controller identity, so cancelled or superseded boots cannot update the current UI. The app dialog loads its catalog lazily and can retry failed loads. Boot-flag installation uses the ready worker’s validated catalog without waiting for a second catalog request.

Package boundary ​

The client imports constructors and validators from packages/protocol. It must not import Service Worker/server worker implementation. The inline recovery watchdog in packages/client/index.html is intentionally independent of the Vue bundle so it can recover when an obsolete Service Worker breaks normal module loading.

The lifecycle exposes idle, starting, ready, stopping, and failed states. Its runtime error listener remains subscribed after boot, so a late worker failure removes the iframe and stops address synchronization. Instance management owns creation, selection, rename, reset, deletion, and initial URL selection. Blocked IndexedDB deletions remain pending with a visible explanation until the browser confirms completion; failed deletions retain the catalog entry and expose a retryable shell error for the active instance.