Skip to content

feat(open): warm a recent project's preview before its card is clicked - #1768

Merged
gregpriday merged 8 commits into
developfrom
feature/issue-1767-warm-recent-project-preview
Nov 28, 2026
Merged

gregpriday merged 8 commits into
developfrom
feature/issue-1767-warm-recent-project-preview

Conversation

@gregpriday

Copy link
Copy Markdown
Member

Resolves #1767

Pointing at a recent project on Welcome now starts its preview, so the click takes over a server that is already starting or ready instead of forking one after the open has read the project.

What changed

  • Intent, in the renderer (src/renderer/src/lib/recent-preview-intent.ts, wired in Welcome.tsx). A pointer at rest on a card (100 ms within 4 px), or keyboard focus that stays on one, sends that project over a new projects:warm IPC. Moving down the list sends nothing, a card that comes to rest replaces the one before, and nothing pointed at or focused for 2 s (or the window losing focus, or the card being filtered out) sends null. Missing cards, touch and pressed-button moves never count. Nothing is sent while an open runs.
  • The warm start, in the main process (Controller.warm and friends in src/main/controller.ts). One at a time, only while Welcome is showing with nothing else under way. It starts only for a project the open would preview without asking: listed in Recent projects, folder there and servable, the same trust check as today, website tools installed (never an install), no component previews left over, nothing to recover, readable documents and an available theme, not from a newer version (ProjectSession.previewBeforeOpen). It waits until every warm server it replaced has exited, then takes a fresh-only lock lease (ProjectSession.lease: only when no lock file exists at all, and no folders are made). Under the lock it checks trust again and notes what the server reads at start (the config hash and the .env* files), then forks the same DevServer the open would fork, in place.
  • Takeover or discard. At the open's start, a forked warm server for the same card is reserved (warmForOpen, src/main/runtime/warm-preview.ts). The lease session is passed to ProjectSession.open as OpenOptions.lease, so the open uses that session and its lock, and the lock stays this app's throughout. prepareRuntime adopts the server as the opening's early server, and today's rule decides as before (earlyTakeable: the publication was seen and landed no file, the project is writable, the server is starting or ready). A warm server whose configuration or environment files changed since it started is also discarded, as is one that failed before the takeover. Anything else stops it and opens as today: a different card, the Open dialog, a moved or deleted folder, a trust prompt, a read-only open.
  • Cleanup. A warm server stops, and its lock goes only after its process has exited, when it is replaced, left, opened elsewhere, unlocked by another app (checked every second, not at the 30 s heartbeat), when the window closes, the renderer goes or reloads, a project is created or a live session joined, or after 30 s unopened. Quitting waits for it (before-quit no longer takes its fast path while one runs or is being handed to an open).
  • Benchmark. npm run perf:run -- --scenario open --lead <ms> rests on the card that long before clicking. open.canvasReady is still timed from the click. The preview's phases are searched from the pointing (open.pointed) and can be negative. open.lead and open.warmTaken say what happened. Results with different leads are never compared, and percent change on a negative baseline now reads a later time as an increase.
  • E2E capture. tests/e2e/design/project-open.mjs now also opens the project after resting 800 ms on its card. It checks that exactly one preview process started during the rest and that the open took that same process over, and writes a second filmstrip.

Known limits

  • The warm server is the real preview server, run in the project folder, so whatever a preview start does happens on hover: SvelteKit and Vite rewrite their caches (.svelte-kit, node_modules/.vite), and trusted project code (a config plugin, a server hook on the home route's first render) runs. A project's documents, generated files, lock and local state are left as they were. A private copy was considered and rejected: copying the tools cannot fit a 300 ms lead, and the issue's takeover rule only has meaning for a server reading the project's own files.
  • A folder renamed while its card is warm carries the lease's lock.json with it, as renaming an open project's folder does. A later open in this app takes it over, and another instance sees it as stale once it stops changing.

Benchmark

npm run perf:run -- --scenario open --iterations 3 --lead <ms>, both fixtures, median open.canvasReady from the click. The serving server was the warm one in every leaded iteration (open.warmTaken 1).

Fixture No lead 300 ms lead 800 ms lead
small 1481 ms 1170 ms (−21%) 643 ms (−57%)
large 2212 ms 1825 ms (−18%) 1307 ms (−41%)

No lead against develop (built from origin/develop and measured with this harness via --app): small 1472 → 1481 ms (+0.6%, noise band ±147 ms), large 2216 → 2212 ms (−0.1%, ±222 ms). A no-lead open is no slower than today. These runs used the build at a7146a009; the two later commits add a lock check before a warm fork and lock-wait bookkeeping, neither on the no-lead path.

Testing

  • New unit tests:
    • tests/unit/recent-preview-intent.test.ts: 21 cases. Sweeps, drift, replacement, grace, keyboard, pointer and focus together, window blur, filtered cards, opening and disposal.
    • tests/unit/warm-preview.test.ts: 36 cases on the real controller and session with a fake preview process. Takeover, discard on a changed publication or .env, one at a time across three cards with a slow exit, untouched files, a different project, a moved folder, an early click, unlock (before the fork and while running), a lock still being written, quit, window close, handover counted for quit, and 16 never-warmed conditions.
    • open-outline-browser.test.ts: the Welcome wiring in Chromium, including window blur.
    • perf-scenarios.test.ts / perf-results.test.ts: lead metrics, protocol, and percent change on a negative baseline.
  • Nine of the review fixes were mutation-checked: each new test fails with its fix removed.
  • Impact ring: 75 of 746 test files (10%) selected, plus 5 policy tests, at a7146a009: 80 files, 2052 tests, all green. After the later fixes, the 41 controller tests in that set, session / read-only-open / project-switch, and warm-preview were all green.
  • Type check green. The repository has no linter or formatter.
  • DESIGN_CAPTURE=1 node tests/e2e/design/project-open.mjs on the built app (a7146a009) passed. Resting 800 ms on the card started one preview process, the open took that same process over, and the page was ready 616 ms after the click, against 1387 ms clicked straight away (both inside the capture's screenshot loop). The capture's sheet step needs Python's Pillow.
  • Left open (Low): a drag started inside the 100 ms dwell can still warm the card; returning to Welcome without moving the pointer needs one move before the card counts again; open.lead includes Playwright's hover and click dispatch.

- Welcome reads a pointer at rest on a card, or keyboard focus that stays on one
- The main process starts that project's preview under a fresh-only lock lease
- The open takes the lease as its own session and the server as its early one
… benchmark

- Unit tests for the intent rules, the warm start's conditions, takeover and discard
- perf:run --lead rests on the card before the click; open.lead and open.warmTaken
- Check trust again under the lock, right before the fork, and note what the server read
- Wait for every replaced warm server to exit; let an open wait for a lock being taken
- Count a warm server an open has taken until its preview takes it, so quitting waits
- Notice an unlock from another app within a second; never take a dead or stale server
- Decline projects whose open starts no preview (unreadable documents, missing theme)
- Hand intent back to the card focus or the pointer stays on; leave on window blur
… only for a lock being taken in the folder opened
…, and read no document through a link before a warm start
@gregpriday
gregpriday merged commit 5d79ac9 into develop Nov 28, 2026
1 check passed
@gregpriday
gregpriday deleted the feature/issue-1767-warm-recent-project-preview branch November 28, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warm a recent project's preview before its card is clicked

1 participant