Skip to content

fix(electron): restore packaged desktop app loading#1095

Merged
tomcasaburi merged 2 commits intomasterfrom
codex/fix/macos-release-loading
Mar 17, 2026
Merged

fix(electron): restore packaged desktop app loading#1095
tomcasaburi merged 2 commits intomasterfrom
codex/fix/macos-release-loading

Conversation

@tomcasaburi
Copy link
Member

@tomcasaburi tomcasaburi commented Mar 17, 2026

Restore packaged desktop loading by rebuilding Electron-native modules before every package/make flow and by using the Vite base URL for preloaded theme assets in file:// builds.

Closes #1094


Note

Medium Risk
Touches Electron packaging/CI and adds a new native-module verification step that runs Electron during builds; failures could block releases but scope is limited to build/runtime asset paths.

Overview
Fixes packaged Electron builds that could ship with an incompatible better-sqlite3 binary by adding electron:prepare-package (rebuild via electron-rebuild + verification) and running it in CI packaging jobs and all electron:package/electron:build* scripts.

Updates theme asset preloading to resolve URLs via import.meta.env.BASE_URL (new resolveAssetUrl) instead of hardcoded root paths, and extends tests accordingly. Adds a playbook note documenting the better-sqlite3 packaging failure mode and mitigation.

Written by Cursor Bugbot for commit cf326a2. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Packaging now rebuilds and verifies native Electron modules before creating installers to prevent broken native binaries at runtime.
  • Documentation

    • Added guidance describing an Electron packaging issue and recommended pre-package mitigation steps.
  • Chores

    • Build and packaging pipeline updated to run native-module preparation across all Electron build targets.
    • Asset URL resolution updated to respect the app base URL.

Rebuild and verify Electron native modules before packaging and use the Vite base URL for packaged asset preloads.
@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
5chan Ready Ready Preview, Comment Mar 17, 2026 8:44am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 84f37569-ae98-4348-b907-2370c057accd

📥 Commits

Reviewing files that changed from the base of the PR and between aa91b3a and cf326a2.

📒 Files selected for processing (2)
  • src/lib/utils/__tests__/misc-utils.test.ts
  • src/lib/utils/preload-utils.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/utils/preload-utils.ts
  • src/lib/utils/tests/misc-utils.test.ts

📝 Walkthrough

Walkthrough

Adds a pre-package native module rebuild-and-verify step to CI and build scripts, introduces a verification script for Electron native modules, documents a better-sqlite3 ABI packaging issue, and updates asset URL resolution for preload logic and its tests.

Changes

Cohort / File(s) Summary
CI Workflow
.github/workflows/ci.yml
Inserted a "Rebuild and verify Electron native modules" step that runs yarn electron:prepare-package before packaging in multiple CI jobs.
Build scripts / package.json
package.json
Added scripts: electron:rebuild-native, electron:verify-native, electron:prepare-package; updated all electron packaging/build targets to run electron:prepare-package before packaging/make.
Native verification script
scripts/verify-electron-native-modules.js
New script that runs Electron with ELECTRON_RUN_AS_NODE=1 to require listed native modules (e.g., better-sqlite3) and emits native-ok / native-fail output; exits nonzero on failures.
Docs
docs/agent-playbooks/known-surprises.md
Added subsection documenting the better-sqlite3 ABI mismatch observed in packaged Electron apps, with mitigation recommending a pre-package rebuild/verify step.
Preload asset resolution & tests
src/lib/utils/preload-utils.ts, src/lib/utils/__tests__/misc-utils.test.ts
Added resolveAssetUrl export and switched preload asset paths to use import.meta.env.BASE_URL-prefixed URLs; updated tests to assert resolution with a non-root base URL.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Job / Developer
    participant Scripts as npm/yarn scripts
    participant Electron as Electron (ELECTRON_RUN_AS_NODE)
    participant Native as Native Modules (e.g., better-sqlite3)
    participant Packager as electron-forge

    CI->>Scripts: yarn build && yarn build:preload
    Scripts->>Scripts: yarn electron:prepare-package
    Scripts->>Electron: spawn Electron + inline verifier (ELECTRON_RUN_AS_NODE=1)
    Electron->>Native: require('better-sqlite3') (and others)
    alt require succeeds
        Electron-->>Scripts: prints "native-ok"
        Scripts->>Packager: electron-forge package / make
    else require fails
        Electron-->>Scripts: prints "native-fail" + stack
        Scripts-->>CI: exit non-zero (fail CI / halt packaging)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through builds both near and far,
Rebuilt the natives to match Electron's star,
Prefixed assets with BASE_URL so neat,
Packages now stride on nimble feet. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main objective: restoring packaged Electron app loading by fixing native module and asset resolution issues.
Linked Issues check ✅ Passed The PR fully addresses the two core coding objectives from issue #1094: rebuilding native modules for Electron ABI and fixing asset preloading with Vite base URL.
Out of Scope Changes check ✅ Passed All changes align with restoring packaged app loading; no unrelated modifications were introduced outside the native module rebuild/verification and asset URL resolution scopes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix/macos-release-loading
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

215-216: Consider a packaged-artifact smoke test here.

This step verifies the host node_modules before packaging, but issue #1094 only showed up after packaging. Launching one packaged desktop artifact and waiting for the local RPC port would catch ASAR/unpack and file:// regressions that this pre-package check can't see.

Also applies to: 280-281, 345-346, 411-413

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yml around lines 215 - 216, Add a packaged-artifact
smoke test after the packaging step instead of only pre-package checks: after
the existing "Rebuild and verify Electron native modules" step that runs `yarn
electron:prepare-package`, add steps to produce a packaged desktop artifact,
launch that packaged binary, and wait/poll the local RPC port to confirm the app
starts correctly (catching ASAR/unpack and file:// regressions). Ensure the step
gracefully kills the process after verifying the RPC port and fails the job on
timeout; apply the same packaged-app smoke-test pattern to the other similar CI
spots that run `yarn electron:prepare-package` (the duplicate steps holding the
same name/command).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/utils/__tests__/misc-utils.test.ts`:
- Around line 119-123: Update the test to simulate a non-root BASE_URL (e.g.,
set import.meta.env.BASE_URL = 'file:///app/') so the test exercises the
packaged-electron path; then adjust the expected array to the concrete
file:///app/... URLs (the expectation comparing loadedSources) to verify the
code uses `${import.meta.env.BASE_URL}${path}` rather than `/${path}`; locate
the assertion on loadedSources in misc-utils.test.ts and change the test setup
and expected values accordingly.

---

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 215-216: Add a packaged-artifact smoke test after the packaging
step instead of only pre-package checks: after the existing "Rebuild and verify
Electron native modules" step that runs `yarn electron:prepare-package`, add
steps to produce a packaged desktop artifact, launch that packaged binary, and
wait/poll the local RPC port to confirm the app starts correctly (catching
ASAR/unpack and file:// regressions). Ensure the step gracefully kills the
process after verifying the RPC port and fails the job on timeout; apply the
same packaged-app smoke-test pattern to the other similar CI spots that run
`yarn electron:prepare-package` (the duplicate steps holding the same
name/command).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 46c46784-c847-4c99-857b-143aa644438a

📥 Commits

Reviewing files that changed from the base of the PR and between 83aa221 and aa91b3a.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • docs/agent-playbooks/known-surprises.md
  • package.json
  • scripts/verify-electron-native-modules.js
  • src/lib/utils/__tests__/misc-utils.test.ts
  • src/lib/utils/preload-utils.ts

@tomcasaburi
Copy link
Member Author

Addressed the valid review finding in cf326a2e by extracting resolveAssetUrl() and adding a non-root BASE_URL unit test for the packaged file:// path.

I am deferring the broader packaged-artifact CI smoke test suggestion for a follow-up because it expands the PR scope and would materially lengthen the packaging matrix further; the current PR remains focused on restoring packaged app loading and verifying the Electron-native module ABI.

@tomcasaburi tomcasaburi merged commit c9bd625 into master Mar 17, 2026
10 of 11 checks passed
@tomcasaburi tomcasaburi deleted the codex/fix/macos-release-loading branch March 17, 2026 09:04
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.

Packaged Electron app fails to load boards and comments on macOS arm64

1 participant