Skip to content

Bundle preloads so imports work, and live-reload the renderer in dev - #15

Merged
ipfizz merged 2 commits into
mainfrom
fix/preload-imports-and-dev-watch
Jun 29, 2026
Merged

Bundle preloads so imports work, and live-reload the renderer in dev#15
ipfizz merged 2 commits into
mainfrom
fix/preload-imports-and-dev-watch

Conversation

@ipfizz

@ipfizz ipfizz commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Two fixes from macOS-user field feedback, both confirmed genuine in the code and fixed.

import in a preload silently broke window.api (fix)

A preload is injected as a classic script (a WKUserScript and its WebKitGTK / WinCairo equivalents have no module mode), so a top-level import threw a SyntaxError that aborted the whole preload — silently taking window.api with it.

The preload is now bundled into a self-contained IIFE before injection, inlining its imports:

  • Shared common/preload-bundle.ts → runtime main/api/preload.ts (bundles via Bun in dev; raises a clear error instead of failing silently) + bundlePreloadAssets wired into build-macos / build-windows / build-linux so a packaged app matches dev.
  • Plain preloads still pass through verbatim (no subprocess).
  • Proven end-to-end on the WinCairo engine: an import-using preload exposes window.api.

bunmaska dev restarted the whole app (reopening the window) on every save (feat)

The watcher now classifies each change — a TypeScript source (compiled into the main process) restarts; any other watched file is a renderer asset (page / CSS / preload) and live-reloads the window in place over the child's stdin. No more window churn for HTML/CSS edits.

  • main/dev-reload.ts (app-side stdin reload listener) + a reload path in the supervisor.
  • Proven end-to-end on the engine: a reload on stdin re-navigates the page with no restart.

Testing

  • New unit tests (preload bundling, dev change-classification, reload dispatch) + two engine-gated Windows integration probes.
  • validate:windows187 pass, 0 fail; type-check + lint clean.
  • The logic is platform-agnostic (the macOS/Linux backends just receive the already-bundled preload string) — CI confirms macOS + Linux here.

Docs

Corrected the now-inaccurate "preload is injected verbatim, keep it plain JS" across the scaffold, examples, and website: preloads are bundled, so imports work — just keep them browser code (no Node APIs).

@ipfizz
ipfizz merged commit 0622050 into main Jun 29, 2026
3 checks passed
@ipfizz
ipfizz deleted the fix/preload-imports-and-dev-watch branch June 29, 2026 01:06
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.

1 participant