Skip to content

fix(desktop-electron): fix resource loading under file:// protocol#17125

Merged
Brendonovich merged 1 commit intoanomalyco:devfrom
Hona:fix/desktop-electron-resource-loading
Mar 12, 2026
Merged

fix(desktop-electron): fix resource loading under file:// protocol#17125
Brendonovich merged 1 commit intoanomalyco:devfrom
Hona:fix/desktop-electron-resource-loading

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Mar 12, 2026

Summary

  • Fix publicDir resolution in electron.vite.config.ts -- was ../app/public (resolved relative to renderer root: "src/renderer/" to src/app/public, doesn't exist). Changed to ../../../app/public which correctly resolves to packages/app/public. This has been broken since the initial electron commit (5cf235fa6), meaning public assets like oc-theme-preload.js, favicons, and the web manifest were never served in dev or included in production builds.
  • Convert all HTML paths to relative (./) in index.html and loading.html -- absolute / paths resolve to filesystem root under file:// protocol (e.g. file:///C:/oc-theme-preload.js on Windows).
  • Remove <link rel="manifest"> from Electron HTML -- web manifests are a PWA concept, not applicable in Electron.
  • Skip font preload links under file:// -- crossorigin="anonymous" on <link rel="preload"> creates a credential mode mismatch with @font-face url() fetches under file://, causing fonts to load twice.
  • Add regression tests that read the actual config values and HTML files to catch these issues.

Visible impact

Users on non-default themes get a flash of wrong colors on every launch because oc-theme-preload.js (which injects cached theme CSS before the app renders) was never bundled. Default theme users are unaffected (the script early-returns for oc-2).

Copilot AI review requested due to automatic review settings March 12, 2026 03:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Electron renderer asset loading when the app is served via the file:// protocol (dev + production), ensuring public assets and entrypoints resolve correctly and adding regression tests to prevent future breakage.

Changes:

  • Fix publicDir resolution in electron.vite.config.ts so Electron bundles/serves assets from packages/app/public.
  • Convert renderer HTML asset references from absolute (/…) to relative (./…) to work under file://, and remove the web manifest link.
  • Add regression tests to validate HTML paths and publicDir resolution.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/ui/src/components/font.tsx Skips font preloads under file:// to avoid double-loading due to credential-mode mismatch.
packages/desktop-electron/tsconfig.json Excludes *.test.ts from the package’s TypeScript project build/typecheck.
packages/desktop-electron/src/renderer/loading.html Switches asset/script references to relative paths; removes manifest link.
packages/desktop-electron/src/renderer/index.html Switches asset/script references to relative paths; removes manifest link.
packages/desktop-electron/src/renderer/html.test.ts Adds tests to enforce relative paths in renderer HTML and validate publicDir resolution.
packages/desktop-electron/electron.vite.config.ts Corrects publicDir relative to root for renderer builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import { fileURLToPath } from "node:url"

const dir = dirname(fileURLToPath(import.meta.url))
const root = resolve(dir, "../..")
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

root is resolved as ../.. from src/renderer, which points to packages/desktop-electron/src. That makes join(root, "electron.vite.config.ts") look for src/electron.vite.config.ts (doesn't exist) and also causes resolve(root, rendererRoot, pub) to duplicate src in the path. Adjust the base directory so it points at packages/desktop-electron (e.g., walk up one more level or resolve from import.meta.url to the package root) before reading the config and resolving publicDir.

Suggested change
const root = resolve(dir, "../..")
const root = resolve(dir, "../../..")

Copilot uses AI. Check for mistakes.
Comment thread packages/ui/src/components/font.tsx Outdated
publicDir was resolved relative to renderer root (src/renderer/) not the
config file, so no public assets were ever served or bundled. Also convert
all HTML paths to relative, remove inapplicable web manifest link, and
skip font preloads under file:// to avoid crossorigin credential mismatch.
@Hona Hona force-pushed the fix/desktop-electron-resource-loading branch from 4332484 to 34a55eb Compare March 12, 2026 03:52
@Brendonovich Brendonovich merged commit 54e7baa into anomalyco:dev Mar 12, 2026
9 checks passed
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.

3 participants