fix: detect Node via process.type to keep Electron main process working#1033
Open
claygeo wants to merge 1 commit into
Open
fix: detect Node via process.type to keep Electron main process working#1033claygeo wants to merge 1 commit into
claygeo wants to merge 1 commit 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
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).