fix(worker): inline NEXT_DEPLOYMENT_ID into worker bundles - #3241
Open
AhmedElBanna80 wants to merge 1 commit into
Open
fix(worker): inline NEXT_DEPLOYMENT_ID into worker bundles#3241AhmedElBanna80 wants to merge 1 commit into
AhmedElBanna80 wants to merge 1 commit into
Conversation
`process.env.NEXT_DEPLOYMENT_ID` and `process.env.__VINEXT_DEPLOYMENT_ID` are set as top-level Vite `define`s, and the comment there explicitly intends worker code to read `process.env.NEXT_DEPLOYMENT_ID`. But worker builds run in their own plugin container that the top-level defines don't reach (the sibling `createWorkerImageImportsPlugin` exists for exactly this reason), so a worker that reads `process.env.NEXT_DEPLOYMENT_ID` sees an un-replaced member access → null. Add a worker-scoped define plugin that inlines both identifiers into worker scripts, mirroring the top-level define values for parity (`NEXT_DEPLOYMENT_ID` → the string or `false`; `__VINEXT_DEPLOYMENT_ID` → the string or `""`). It's a no-op where the identifiers are absent, and safe if the top-level define already reaches workers. Fixes the `NEXT_DEPLOYMENT_ID`-is-null half of the `app-dir/worker` e2e fixture. (The `?dpl=` skew query on the worker *script* URL is a separate asset-URL concern.) Test: tests/worker-deployment-id-define.test.ts exercises the transform directly — inlines the configured id, inlines `false` when unset, handles the internal ident, and is a no-op when the id is never read.
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.
Problem
process.env.NEXT_DEPLOYMENT_IDandprocess.env.__VINEXT_DEPLOYMENT_IDare set as top-level Vitedefines, and the comment there explicitly intends worker code to readprocess.env.NEXT_DEPLOYMENT_ID. But worker builds run in their own plugin container that the top-level defines don't reach — as the siblingcreateWorkerImageImportsPluginalready notes ("Worker builds use their own plugin container, so the top-level … plugin cannot perform this transform"). So a worker that readsprocess.env.NEXT_DEPLOYMENT_IDsees an un-replaced member access →null/undefined.Surfaced by the Next.js e2e fixture
test/e2e/app-dir/worker(NEXT_DEPLOYMENT_IDnull inside the worker).Fix
Add a worker-scoped define plugin (
createWorkerDeploymentIdDefinePlugin) registered inworker.pluginsalongside the existing worker-image plugin. It inlines both identifiers into worker scripts, mirroring the top-level define values for parity (NEXT_DEPLOYMENT_ID→ the string orfalse;__VINEXT_DEPLOYMENT_ID→ the string or""). It is a no-op where the identifiers are absent, and harmless if the top-level define already reaches workers (the filter simply won't match a value that's already replaced).packages/vinext/src/plugins/worker-image-imports.ts(the plugin, beside its sibling) + registration inpackages/vinext/src/index.ts.Test
tests/worker-deployment-id-define.test.tsexercises the transform directly: inlines a configured id, inlinesfalsewhen unset (Next.js parity), handles the internal identifier, and is a no-op when the id is never read. Mutation-proved (neutering the replacement reds the positive cases).Scope
This fixes the
NEXT_DEPLOYMENT_ID-is-null half of the fixture. The?dpl=skew query on the worker script URL is a separate asset-URL concern (renderBuiltUrl/assetPrefix) and is not addressed here.