Repository navigation
feat(@angular/build): add manualRebuild option to the dev-server - #34742
DingWeizhe wants to merge 4 commits into
Conversation
When `manualRebuild` is enabled, the development server keeps tracking file changes but no longer rebuilds automatically on every change. Instead, all pending changes are accumulated and rebuilt incrementally (reusing the in-memory build state) only when a rebuild is explicitly requested, either by sending a `POST` request to the `/__ng_rebuild` endpoint or by pressing `b` in the terminal. The endpoint responds once the rebuild has completed with a JSON object containing the outcome (`success`, `failure`, `no-changes` or `cancelled`). Cross-origin browser requests to the endpoint are rejected. This is useful when many files are edited in a batch (for example by AI coding agents) to avoid repeated intermediate rebuilds without having to restart the development server and lose the incremental build state. Closes angular/angular#72079 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `devserver_start` MCP tool now accepts a `manualRebuild` option which starts `ng serve` with `--manual-rebuild`. A new `devserver_rebuild` tool triggers an incremental rebuild of such a dev server once a batch of edits is complete, waits for it to finish, and returns the build status and logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces a manual rebuild mode for the Angular development server, allowing file changes to be tracked but only rebuilt when explicitly requested via a POST request to /__ng_rebuild or by pressing 'b' in the terminal. This feature is supported by a new ManualRebuildController, a Vite middleware, and an MCP tool devserver_rebuild. The review feedback highlights several key improvements: ensuring pending manual rebuild requests are properly resolved as cancelled if the build loop is aborted, falling back to the :authority pseudo-header in the rebuild middleware to support HTTP/2 clients, and ensuring isBuilding() returns false if the devserver process has terminated.
|
|
||
| // Reject cross-origin requests made by browsers to prevent arbitrary web pages from | ||
| // triggering rebuilds. Non-browser clients (e.g., curl or tooling) do not send an origin. | ||
| if (!isSameOrigin(req.headers.origin, req.headers.host)) { |
There was a problem hiding this comment.
In HTTP/2, the host header may be absent, and the :authority pseudo-header is used instead. To ensure compatibility with HTTP/2 clients, we should fall back to the :authority header when checking the origin.
const host = req.headers.host ?? (req.headers[':authority'] as string | undefined);
if (!isSameOrigin(req.headers.origin, host)) {|
Hi @DingWeizhe, thank you for putting together this PR and exploring an HTTP and MCP alternative to the file trigger approach in #33330. Even without a sentinel file on disk, we do not plan to introduce a manual or paused rebuild mode to
For automated or agent workflows making bursts of edits, we recommend one of the following:
Because of this, we will be closing this PR and the associated issue. Thank you again for your time and contribution! |
PR Checklist
PR Type
What is the current behavior?
ng serveeither rebuilds on every file change (watch: true) or never rebuilds again after the initial build (watch: false). When many files are edited in a batch, for example by AI coding agents, the dev server rebuilds over and over while the edits are still in progress. The only other option is--watch=falsefollowed by a restart, which throws away the in-memory incremental build state and means a full cold build every time.Issue Number: #34743 (filed against
angular/angular, but the implementation lives in this repo)What is the new behavior?
@angular/build: newmanualRebuilddev-server optionremoved, remove→add becomesmodified, and so on). Rebuilds no longer start on their own.POST /__ng_rebuildis sent to the dev server. The response is sent after the rebuild finishes and the results have been pushed to clients:curl -X POST http://localhost:4200/__ng_rebuild # {"status":"success"} (or "failure" | "no-changes" | "cancelled")bis pressed in the terminal (a new Vite CLI shortcut).successresponse always covers every edit made before the request.Originheader are rejected (403). Methods other than POST get a 405.watchis disabled, the option does nothing and a warning is logged.Implementation notes:
utils/manual-rebuild.tsaddsManualRebuildControllerandwaitForManualRebuilds(), which gates the watcher's change stream.runEsBuildBuildActiontakes an optional controller (as the internal application optionmanualRebuild) and resolves requests once a rebuild's results have been emitted.tools/vite/middlewares/rebuild-middleware.ts.@angular/cli: MCP integrationdevserver_startacceptsmanualRebuild: true, which startsng serve --manual-rebuild.devserver_rebuildtool: an agent calls it once it has finished a batch of edits. It triggers the rebuild through the endpoint above, waits for it, and returns{ status, logs }.Does this PR introduce a breaking change?
The option defaults to
false. Default behavior is unchanged.Other information
manual-rebuild_spec.ts(unit): change merging, request gating, the settle window, and cancellation.dev-server/tests/options/manual-rebuild_spec.ts(integration): a change is not rebuilt until it is requested, and is served after the request. Also coversno-changes, 405 and 403.devserver_spec.ts: the MCP start args and the rebuild tool.manualRebuild,/__ng_rebuild) are open to bikeshedding.pnpm-lock.yamlonmaincurrently fails to parse (duplicate mapping key: minimatch@11.0.8), so I ran the tests locally with the previous commit's lockfile. This PR does not touch the lockfile.🤖 Generated with Claude Code