Desktop: never a blank window (frozen-prototype fix, error screens, logs, state migration, boot check)

The signed release showed only its background colour and never started the sidecar. Tauri's freezePrototype
freezes Object.prototype before the bundle runs; d3-color and d3-format (under the visx charts) assign
`constructor` / `toString` on plain objects while loading, which throws on a frozen prototype, so the bundle
stopped before React drew anything. The saved state was not the cause.

- build/freeze-safe.ts: Vite plugin that rewrites those assignments in dependencies into a helper that defines
  the property when the frozen prototype would refuse it
- error boundaries for the window, each screen and each app tab (Copy details, Reload, Reset saved state with a
  backup); public/boot.js shows the same panel when the bundle fails or the window stays empty
- logs/host.log (start, saved state, sidecar start/stop, panics) and logs/webview.log (log_webview), rotated,
  home as ~, keys, tokens and e-mail addresses replaced
- state.json `version` 2 with an explicit 1 -> 2 migration (original kept as state.json.v1.bak), per-entry
  tolerant parsing, partial settings keep their fields, unreadable files kept aside
- folders that are gone: "Folder not found" with Locate... (project_locate) / Remove; portfolio reads skip them
- tools/desktop-boot-check.ts: the built window with the release CSP and the frozen prototype, a mocked host from
  the state fixtures (empty, D1 with folders gone, D3) and the real sidecar, through every screen; in bun run ci,
  the Forgejo CI workflow and the macOS release
This commit is contained in:
CRTkafa 2026-10-11 01:36:34 +00:00
parent 209b8d0559
commit 08eb314196
45 changed files with 2080 additions and 69 deletions

View file

@ -272,6 +272,36 @@ Download sources (one click on the Dependencies screen or in the first-run guide
- **`storebound-desktop --self-test`**: starts the bundled sidecar, checks the `session.hello` handshake, prints one
JSON line and exits, before Tauri starts (no window). The release runs it on the exact artifacts.
## Never a blank window (D6)
- **Frozen prototype.** `freezePrototype: true` makes Tauri run `Object.freeze(Object.prototype)` before any page
script. Dependencies that assign `x.constructor = ...` or `x.toString = ...` on a plain object (d3-color, d3-format
under the visx charts) then throw while the bundle loads ("Cannot assign to read only property"; WebKit:
"Attempted to assign to readonly property"), and the window shows only its background colour, before React and
before the sidecar starts. `apps/desktop/build/freeze-safe.ts` (a Vite plugin) rewrites those assignments in
dependencies into a helper that defines the property when the frozen prototype would refuse it.
- **Saved state versions.** `state.json` carries `version` (2). Files without it are format 1 (D1 to D3: projects and
accounts, later studios, overrides and settings) and are migrated once (`store::migrate`), the original kept as
`state.json.v1.bak`. An unreadable file is kept as `state.json.unreadable-<time>` and the app starts empty; entries
that do not parse are dropped one by one (named in host.log), settings missing a field keep the rest.
- **Folders that are gone** (moved, renamed, deleted, old worktrees): `projects_list` marks them `missing`; the app
shows "Folder not found" with Locate… (`project_locate`: keeps the id, accounts, links and saved reads) and Remove
from list. Portfolio reads skip them.
- **Error screens.** A React error boundary around the whole window and one per screen and app tab show the error,
Copy details, Reload and Reset saved state (keeps a backup: `state_reset` moves `state.json` to
`state.json.reset-<time>.bak` after a native confirmation; keys stay in the keychain). `public/boot.js` runs before
the bundle and shows the same panel in plain DOM when the bundle fails or the window stays empty.
- **Logs** in `<app data>/logs`: `host.log` (start, saved state and migration, sidecar start / stop with its last
stderr lines, panics) and `webview.log` (window.onerror, unhandled rejections, boundaries, through `log_webview`,
at most 60 entries a minute). Rotated at 512 KB (one `.1.log` kept); home folder shown as `~`, keys, tokens,
passwords and e-mail addresses replaced.
- **Boot check** (`bun tools/desktop-boot-check.ts`, in `bun run ci` and the macOS release): the built `dist/` in
headless Chromium with the release CSP and the frozen prototype, a mocked host answering from the saved state
fixtures (`apps/desktop/tests/fixtures/state`: empty, D1 with folders gone, D3 full; the host answers are written by
the Rust migration itself, `src-tauri/tests/state.rs`) and the real sidecar for reads. It opens every screen and
app and fails on any uncaught or console error, an error panel or an empty `#root`; a last case removes the bundle
and expects the boot.js panel.
## Develop
```sh