fix: detect Node via process.type to keep Electron main process working#1033
Open
claygeo wants to merge 2 commits into
Open
fix: detect Node via process.type to keep Electron main process working#1033claygeo wants to merge 2 commits into
claygeo wants to merge 2 commits into
Conversation
The Electron guard added in electric-sql#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 electric-sql#813 without regressing PGlite in the Electron main process. Refs electric-sql#951, electric-sql#813
tdrz
requested changes
Jun 28, 2026
Comment on lines
+14
to
+16
| !['renderer', 'worker', 'service-worker'].includes( | ||
| (process as { type?: string }).type ?? '', | ||
| ) |
Collaborator
There was a problem hiding this comment.
This is getting hairy and hard to comprehend. Please extract this logic to a separate function, move the comments there and please trim them down. Code is the best doc, no need for a 9 line comment if the logic is clear.
Contributor
Author
There was a problem hiding this comment.
Done in 33b5b09. Extracted the detection into an isElectronWebContext() helper, moved the comment onto it, and trimmed it from 9 lines down to 3. Behavior is identical: IN_NODE is still the process.versions.node check plus !isElectronWebContext(), which keeps the Node fs path on in the Electron main and utility processes. Thanks for the steer.
Address review feedback on electric-sql#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #951 (thanks for merging that one!) and #813.
#951 fixed the Electron renderer crash by adding
!process.versions.electrontoIN_NODE. While verifying it I noticed that guard also flipsIN_NODEtofalsein the Electron main and utility processes, becauseprocess.versions.electronis set in every Electron process, not just the renderer. Those are real Node environments, so PGlite then takes the browser path and loses the Node.jsfscode path it needs. Running PGlite in the main process for filesystem-backed storage (keeping DB access out of the renderer) is a common pattern, so this is a regression.This keys the check off
process.typeinstead, which cleanly separates Electron's web contexts from its Node ones:process.type!process.versions.electron(#951)process.typeexclusion (this PR)undefinedworker_threadsundefinedbrowserutilityrendererworkerservice-workerprocess)So it still fixes the original renderer crash from #813, and additionally keeps the Node path working in the Electron main and utility processes.
process.typeis Electron specific and not in@types/node, hence the small structural cast.Checks run locally:
typecheck,lint, andbuildpass for@electric-sql/pglite-utils. Changeset included (patch to@electric-sql/pglite).