Skip to content

fix(lite): add lite:// protocol to serve local content#13644

Merged
slarse merged 1 commit intomasterfrom
GB-1402/fix-page-reload
May 6, 2026
Merged

fix(lite): add lite:// protocol to serve local content#13644
slarse merged 1 commit intomasterfrom
GB-1402/fix-page-reload

Conversation

@slarse
Copy link
Copy Markdown
Contributor

@slarse slarse commented May 5, 2026

When opening a project in the packaged app, React Router sets the path to /project/<id>/workspace. As we used to serve via the file:// protocol, this made the effective location.href file:///project/<id>/workspace. When reloading the page, Electron just requests whatever is set in the location. As that file does not exist, we fail the reload.

This commit fixes that by introducing a custom lite:// protocol where we simply serve the index file for any route-looking path, and let the router handle the rest.

This also plugs a security hole inherent in serving local files via the file:// protocol, see https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols

Copilot AI review requested due to automatic review settings May 5, 2026 20:33
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

Introduces a custom lite:// protocol in the Lite Electron app so the packaged UI can be served through a secure, router-friendly origin (fixing reloads on client-side routes and avoiding file://).

Changes:

  • Switch Vite build base to / so asset URLs work from a custom protocol origin.
  • Register a privileged lite://app scheme and route requests to the bundled UI (serving index.html for route-like paths).
  • Load the main window via lite://app/ instead of loadFile(...).

Reviewed changes

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

File Description
apps/lite/ui/vite.config.ts Adjusts Vite base path to support asset loading from the custom protocol origin.
apps/lite/electron/src/main.ts Adds lite:// protocol registration/handler and switches the window load target to lite://app/.

Comment thread apps/lite/electron/src/main.ts Outdated
Comment thread apps/lite/electron/src/main.ts
Comment thread apps/lite/electron/src/main.ts Outdated
@slarse slarse force-pushed the GB-1402/fix-page-reload branch from fa75739 to 6a98e04 Compare May 5, 2026 20:36
Copilot AI review requested due to automatic review settings May 5, 2026 20:43
@slarse slarse force-pushed the GB-1402/fix-page-reload branch from 6a98e04 to 67d9be7 Compare May 5, 2026 20:43
@slarse slarse requested review from OliverJAsh and samhh May 5, 2026 20:43
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

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

Comment thread apps/lite/electron/src/main.ts Outdated
Comment thread apps/lite/electron/src/main.ts Outdated
Comment thread apps/lite/electron/src/main.ts Outdated
}),
],
base: "./",
base: "/",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is necessary as, otherwise, when you reload e.g. on the route /project/<id>/workspace, assets are fetched relative to that (e.g. /project/<id>/workspace/assets/blabla.css).

I introduced this relative behavior in the first place as it was necessary when serving via file://, since the "ui root" does not correspond to the actual root of the app. But now with the lite:// protocol we want to have fetches be absolute, and then we direct them to the correct subdirectory as necessary.

Comment thread apps/lite/electron/src/main.ts
Comment thread apps/lite/electron/src/main.ts Outdated
When opening a project in the packaged app, React Router sets the
path to /project/<id>/workspace. As we used to serve via the `file://`
protocol, this made the effective `location.href`
`file://project/<id>/workspace`. When reloading the page, Electron just
requests whatever is set in the location. As that file does not exist, we fail
the reload.

This commit fixes that by introducing a custom `lite://` protocol where
we simply serve the index file for any route-looking path, and let the router
handle the rest.

This also plugs a security hole inherent in serving local files via the
`file://` protocol, see
https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols
Copilot AI review requested due to automatic review settings May 6, 2026 15:46
@slarse slarse force-pushed the GB-1402/fix-page-reload branch from 2cd5241 to 8074123 Compare May 6, 2026 15:46
@slarse slarse merged commit bd137e9 into master May 6, 2026
40 checks passed
@slarse slarse deleted the GB-1402/fix-page-reload branch May 6, 2026 15:58
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