Skip to content

fix production loading issue#10

Merged
newbe36524 merged 1 commit intomainfrom
feature/d
Feb 9, 2026
Merged

fix production loading issue#10
newbe36524 merged 1 commit intomainfrom
feature/d

Conversation

@newbe36524
Copy link
Contributor

@newbe36524 newbe36524 commented Feb 9, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Resolved white screen issue affecting application startup in production environments.
    • Fixed resource loading to work correctly with packaged application bundles.
  • Chores

    • Updated build configuration to ensure all application resources are properly included in packaged builds.

@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

📝 Walkthrough

Walkthrough

This PR fixes an Electron white screen issue by introducing path resolution helper functions (getDistRootPath() and getAppRootPath()) to correctly resolve resources in production asar packaging, updates the build configuration to include resources in packaging, and removes Linux deb/tar.gz targets.

Changes

Cohort / File(s) Summary
Build Configuration
electron-builder.yml
Added resources/**/* to files section for packaging; commented out Linux deb and tar.gz targets, retaining AppImage format only.
Path Resolution Implementation
src/main/main.ts
Introduced getDistRootPath() and getAppRootPath() helpers to resolve paths consistently in dev and production asar environments. Refactored createWindow() and IPC handlers to use these helpers for renderer, preload, and icon paths. Added debugging logs and file existence checks for production path resolution.
Documentation and Specifications
openspec/changes/archive/2026-02-09-fix-electron-white-screen-issue/.../{proposal.md, specs/electron-app/spec.md, tasks.md}
Added comprehensive documentation including fix proposal, asar/production path resolution specification, cross-platform installation flows, and detailed task checklists for diagnosis and validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A white screen haunted our desktop app,
But clever helpers closed the gap!
With paths resolved through asar's might,
The window renders clean and bright! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix production loading issue' is related to the PR's main objective but is vague and generic, lacking specificity about what aspect of production loading is being addressed. Revise the title to be more specific, such as 'Fix Electron white screen issue in production' or 'Fix production path resolution for Electron renderer' to clearly indicate the exact problem being solved.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/d

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

@newbe36524 newbe36524 merged commit 4968677 into main Feb 9, 2026
1 of 2 checks passed
@newbe36524 newbe36524 deleted the feature/d branch February 9, 2026 02:02
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: 2

🤖 Fix all issues with AI agents
In
`@openspec/changes/archive/2026-02-09-fix-electron-white-screen-issue/fix-electron-white-screen-issue/specs/electron-app/spec.md`:
- Line 34: The scenario text in spec.md currently says "AppImage 或 deb 包" but
the deb target is disabled in electron-builder.yml; update the scenario in
openspec/changes/archive/2026-02-09-fix-electron-white-screen-issue/fix-electron-white-screen-issue/specs/electron-app/spec.md
to reflect only the active packaging target (e.g., change to "AppImage 包"), or
alternatively re-enable the deb target in electron-builder.yml by restoring the
deb target entry so the spec and build config match; ensure you reference the
exact phrase "AppImage 或 deb 包" when making the change.

In `@src/main/main.ts`:
- Around line 108-117: fs.access(htmlPath) is called fire-and-forget so
mainWindow.loadFile(htmlPath) proceeds regardless; either make the intent
explicit by adding a comment that the check is purely informational (leave
fs.access as-is) or gate the load by awaiting the file check and only calling
mainWindow.loadFile on success (which requires making createWindow() async and
handling the catch to log and abort/handle the failure). Update or add a comment
if you choose the informational route, or convert the fs.access promise into an
await with try/catch and call mainWindow.loadFile(htmlPath) inside the success
branch if you choose the gated route; also keep
mainWindow.webContents.openDevTools() behavior unchanged or move it after the
successful load if you want it conditional.
🧹 Nitpick comments (1)
electron-builder.yml (1)

46-47: Minor: Inconsistent comment formatting and consider removing unused targets.

The commented-out targets have inconsistent spacing (# - deb vs #- tar.gz). If these targets are intentionally disabled, consider either:

  1. Removing them entirely if they won't be needed
  2. Using consistent formatting if keeping them for reference
🔧 Suggested fix for consistent formatting
   - AppImage
-    # - deb
-    `#-` tar.gz
+    # - deb
+    # - tar.gz

#### Scenario: 用户在 Linux 平台安装应用

**Given** 用户使用 Linux 发行版(Ubuntu、Fedora 等)
**When** 用户下载并运行 AppImage 或 deb 包
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor inconsistency: Scenario mentions "deb 包" but deb target is disabled.

The scenario mentions "AppImage 或 deb 包" but the electron-builder.yml has commented out the deb target. Consider updating the scenario to reflect the current packaging targets (AppImage only) or re-enable deb in the build config.

🤖 Prompt for AI Agents
In
`@openspec/changes/archive/2026-02-09-fix-electron-white-screen-issue/fix-electron-white-screen-issue/specs/electron-app/spec.md`
at line 34, The scenario text in spec.md currently says "AppImage 或 deb 包" but
the deb target is disabled in electron-builder.yml; update the scenario in
openspec/changes/archive/2026-02-09-fix-electron-white-screen-issue/fix-electron-white-screen-issue/specs/electron-app/spec.md
to reflect only the active packaging target (e.g., change to "AppImage 包"), or
alternatively re-enable the deb target in electron-builder.yml by restoring the
deb target entry so the spec and build config match; ensure you reference the
exact phrase "AppImage 或 deb 包" when making the change.

Comment on lines +108 to 117
// Verify file exists for debugging
fs.access(htmlPath)
.then(() => console.log('[Hagicode] HTML file verified to exist'))
.catch((err) => console.error('[Hagicode] HTML file not found:', err));

// Enable DevTools for production to diagnose white screen issue
// TODO: Remove this after white screen issue is resolved
mainWindow.webContents.openDevTools();

mainWindow.loadFile(htmlPath);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

The file existence check runs concurrently with loadFile() and doesn't gate the load.

The fs.access() call is fire-and-forget—its result doesn't affect whether loadFile() proceeds. If the intent is to verify the file exists before loading, the check should be awaited and the load should be conditional. As written, the verification only logs the result after the fact.

If this is intentional (just for debugging), consider adding a comment to clarify. Otherwise, consider restructuring to await the check.

🔧 Option 1: Make the check informational only (add clarifying comment)
     // Verify file exists for debugging
+    // Note: This check is for logging only and doesn't block loadFile()
     fs.access(htmlPath)
       .then(() => console.log('[Hagicode] HTML file verified to exist'))
       .catch((err) => console.error('[Hagicode] HTML file not found:', err));
🔧 Option 2: Gate the load on successful verification
-    // Verify file exists for debugging
-    fs.access(htmlPath)
-      .then(() => console.log('[Hagicode] HTML file verified to exist'))
-      .catch((err) => console.error('[Hagicode] HTML file not found:', err));
-
-    // Enable DevTools for production to diagnose white screen issue
-    // TODO: Remove this after white screen issue is resolved
-    mainWindow.webContents.openDevTools();
-
-    mainWindow.loadFile(htmlPath);
+    // Verify file exists before loading
+    try {
+      await fs.access(htmlPath);
+      console.log('[Hagicode] HTML file verified to exist');
+    } catch (err) {
+      console.error('[Hagicode] HTML file not found:', err);
+    }
+
+    // Enable DevTools for production to diagnose white screen issue
+    // TODO: Remove this after white screen issue is resolved
+    mainWindow.webContents.openDevTools();
+
+    mainWindow.loadFile(htmlPath);

Note: This would require making createWindow() async.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Verify file exists for debugging
fs.access(htmlPath)
.then(() => console.log('[Hagicode] HTML file verified to exist'))
.catch((err) => console.error('[Hagicode] HTML file not found:', err));
// Enable DevTools for production to diagnose white screen issue
// TODO: Remove this after white screen issue is resolved
mainWindow.webContents.openDevTools();
mainWindow.loadFile(htmlPath);
// Verify file exists for debugging
// Note: This check is for logging only and doesn't block loadFile()
fs.access(htmlPath)
.then(() => console.log('[Hagicode] HTML file verified to exist'))
.catch((err) => console.error('[Hagicode] HTML file not found:', err));
// Enable DevTools for production to diagnose white screen issue
// TODO: Remove this after white screen issue is resolved
mainWindow.webContents.openDevTools();
mainWindow.loadFile(htmlPath);
🤖 Prompt for AI Agents
In `@src/main/main.ts` around lines 108 - 117, fs.access(htmlPath) is called
fire-and-forget so mainWindow.loadFile(htmlPath) proceeds regardless; either
make the intent explicit by adding a comment that the check is purely
informational (leave fs.access as-is) or gate the load by awaiting the file
check and only calling mainWindow.loadFile on success (which requires making
createWindow() async and handling the catch to log and abort/handle the
failure). Update or add a comment if you choose the informational route, or
convert the fs.access promise into an await with try/catch and call
mainWindow.loadFile(htmlPath) inside the success branch if you choose the gated
route; also keep mainWindow.webContents.openDevTools() behavior unchanged or
move it after the successful load if you want it conditional.

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