Repository navigation
fix(vite): define ngServerMode per environment - #685
Merged
Brooooooklyn merged 2 commits intoNov 9, 2026
Merged
Brooooooklyn merged 2 commits into
Brooooooklyn merged 2 commits into
Conversation
The build optimizer set `ngServerMode` once, from the top-level `build.ssr`, in the `define` and `oxc.define` every environment shares. With the Environment API (`vite build --app`, `builder.buildApp`), one config builds the client and the server, `build.ssr` is not set at the top level, and the server environment got `ngServerMode = false`. Angular bundled into it then kept a process-wide platform injector and ran `afterRender` hooks on the server, so concurrent requests failed with NG0404. Define `ngServerMode` in `configEnvironment` instead: `true` for server environments (which includes `vite build --ssr`), and `false` for a production client environment, like the Angular CLI. The SSR manifest plugin had the same per-run detection and never injected the manifests in these builds; it now checks the environment's `consumer`.
…eated - `this.environment` is only set by Vite. Under plain rolldown / tsdown (library builds) `buildStart` threw "Cannot read properties of undefined (reading 'config')"; before, the plugin did nothing there. - Every server environment now injects the manifests, so one that bundles another's output (Nitro builds the `ssr` service, then bundles it) injected them twice, with a second copy of the app. Skip code that already calls `ɵsetAngularAppManifest`. - The development-mode `ngServerMode` test stubs `NODE_ENV`, which the plugin also reads, so it passes under `NODE_ENV=production`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Fixes #684
Summary: the build optimizer set
ngServerModeonce, from the top-levelbuild.ssr, in thedefine/oxc.defineevery environment shares. In Environment API builds (vite build --app,builder.buildApp), the server environment gotfalse, so Angular bundled into it kept a process-wide platform injector and concurrent SSR requests failed withNG0404. This PR defines it per environment, like the Angular CLI.Changes
angular-build-optimizer-plugin.ts:ngServerModemoves from theconfighook toconfigEnvironment. Server environments gettrue(this includesvite build --ssr), a production client getsfalse, and a non-production client still gets nothing. It is no longer in the sharedoxc.define.angular-ssr-manifest-plugin.ts: same per-run detection; it now checks the environment'sconsumer, so the manifests are also injected in Environment API builds. It does nothing outside Vite (plain rolldown / tsdown give nothis.environment), and skips code that already sets the manifest, since a server environment can bundle another one's output (Nitro).Tests
build-optimizer.test.ts: resolves real Vite build configs: client + server environments from one config,build.ssr, development mode, and the shared defines. Three of the four fail without this change; thebuild.ssrone guards the existing behaviour.ssr-manifest.test.ts: the manifests are injected in a server environment and not in a client one.ssr-manifest.test.ts: no second injection, and no error without an environment.ngServerMode: truein the server bundle, and a TanStack Start app built with this change answers 12 concurrent requests with 12 × 200 (only some succeeded before, the rest failed withNG0404).Reproduction: https://github.com/benjavicente/oxc-angular-repro-ng-server-mode