fix: define process in eval sandbox to support CommonJS dev builds#3086
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix: define process in eval sandbox to support CommonJS dev builds#3086posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The webworker eval sandbox injected exports/require/module/circuit into the
evaluated function body but never defined `process`. Any imported CommonJS
development build (*.development.js) reads `process.env.NODE_ENV` at module
load, so evaluating such a module threw "process is not defined" and failed
the render.
Inject `var process = globalThis.process || { env: { NODE_ENV: "production" } }`
into the eval function body, and add a matching `globalThis.process` polyfill
in the worker entrypoint next to the existing `globalThis.global` polyfill.
Generated-By: PostHog Code
Task-Id: 3579c101-2794-4a43-80cc-604c74e24dcf
|
This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs. |
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.
Summary
Evaluating any circuit that imports a CommonJS development build (
*.development.js) failed withprocess is not definedin the browser web worker. The eval sandbox inlib/eval/eval-compiled-js.tsinjectsexports,require,module, andcircuitinto the evaluated function body but never definedprocess, so the moment an imported module readprocess.env.NODE_ENV(which every CJS dev build does) the render threw.The fix polyfills
processin two places:var process = globalThis.process || { env: { NODE_ENV: "production" } }into the eval function body.globalThis.processpolyfill inwebworker/entrypoint.ts, right next to the existingglobalThis.globalpolyfill.Added a repro test that removes
globalThis.processto simulate the worker environment and confirms the sandbox no longer throws.Why
Users reported hard render failures when importing packages that touch
processat module load (e.g.react-reconciler/cjs/react-reconciler-reflection.development.js). This is a correctness gap in the core circuit-evaluation flow affecting a whole class of npm packages, with no obvious workaround.Created with PostHog Code from an inbox report.