Skip to content

Commit 7e0d6d1

Browse files
authored
fix: detect Node via process.type to keep Electron main process working (#1033)
* fix: detect Node via process.type, not process.versions.electron The Electron guard added in #951 (!process.versions.electron) also disabled the Node code path in the Electron main and utility processes, which are real Node environments that need it. process.versions.electron is set in every Electron process, not just the renderer. Key off process.type instead: exclude only Electron's web contexts ('renderer', 'worker', 'service-worker'), keeping the Node path for the main ('browser') and utility processes, and for plain Node (no process.type). Fixes the renderer crash from #813 without regressing PGlite in the Electron main process. Refs #951, #813 * refactor: extract isElectronWebContext helper, trim comment Address review feedback on #1033: move the Electron/Node detection out of the IN_NODE expression into a small named helper and trim the explanatory comment from 9 lines to 3. Behavior is unchanged.
1 parent 401137e commit 7e0d6d1

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@electric-sql/pglite': patch
3+
---
4+
5+
Detect the Node environment via `process.type` instead of `process.versions.electron`. The previous Electron guard (#951) also treated the Electron main and utility processes as non-Node, which broke PGlite's filesystem code path there. `process.type` only excludes Electron's web contexts (renderer, web worker, service worker), so PGlite keeps using the Node.js path in the Electron main and utility processes. Follow-up to #951 / #813.

packages/pglite-utils/src/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
// Electron exposes a Node-like `process` in its renderer/worker/service-worker
2+
// contexts, which must use the browser fs path. Its main and utility processes
3+
// are real Node environments (#813).
4+
function isElectronWebContext(): boolean {
5+
const type = (process as { type?: string }).type
6+
return type === 'renderer' || type === 'worker' || type === 'service-worker'
7+
}
8+
19
export const IN_NODE =
210
typeof process === 'object' &&
311
typeof process.versions === 'object' &&
412
typeof process.versions.node === 'string' &&
5-
!process.versions.electron
13+
!isElectronWebContext()
614

715
export const WASM_PREFIX = '/pglite'
816

0 commit comments

Comments
 (0)