You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: serve lazy compilation from the dev server's own server - #5807
With experiments.lazyCompilation, webpack's backend starts its own server on a random port. It ignores the dev server's host, port and https, and a client that reconnects after a restart reaches a port that is gone.
webpack/webpack#23435 adds a backendOptions hook to LazyCompilationPlugin. This PR taps it, where the compiler's webpack has it, and hands the backend this server and the url it is reached at:
LazyCompilationPlugin.getCompilerHooks(compiler).backendOptions.tap(pluginName,(options)=>options.listen||options.server
? options// the configuration's own backend server stays
: { ...options,server: this.server,urlBase: "http://localhost:8080"});
The urlBase is handed over because in plugin mode the server listens only after the first build, which waits for the backend. Nothing changes with a webpack without the hook or with ipc.
Measured with webpack/webpack#23435 linked, lazyCompilation: { entries: false } and port: 18765:
Yes, in test/e2e/lazy-compilation.test.js. The installed webpack predates the hook, so a stand-in hook checks that the dev server passes its server and url, and keeps a listen the configuration names. It fails without the change.
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
The docs could say that lazy compilation runs on the dev server's own host and port when webpack supports it, and that experiments.lazyCompilation.backend.listen or server opts out.
Use of AI
Claude Code wrote the change and its test, ran the test, the repository's lint and an end-to-end check against webpack/webpack#23435, at the requester's direction.
Lazy compilation can connect through the development server using its configured host, port, and HTTP or HTTPS protocol when supported by webpack. Unset or wildcard hosts use localhost.
Existing connection settings remain unchanged when custom listener or server options are provided, backend options are functions, no server is available, or the server uses a dynamically assigned port.
This behavior applies to eligible compilers using the development server; IPC configurations remain unchanged.
Tap webpack's `LazyCompilationPlugin` `backendOptions` hook, where the
compiler's webpack has it, and hand the backend this server and the url
it is reached at, so lazy compilation shares its host, port and https.
A `listen` or `server` the configuration names is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FhutTE6yv5FArV4ThNJrq
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Server.initialize() now sets up lazy-compilation backend options after creating the HTTP server. The setup skips IPC, disabled child compilers, and compilers without webpack’s lazy-compilation plugin. For supported compilers, it preserves options that already specify listen or server; otherwise, it supplies the dev server and a URL based on its TLS state, host, and port. End-to-end tests check default options, supplied listener options, and the behavior when the configured port is 0. A changeset documents the update.
Merge Risk: Moderate · previous review ebb20
Lazy compilation now runs on the dev server's own host, port and protocol. Setups that bind to 0.0.0.0 and are opened from another machine may fail to load lazy chunks because the lazy URL points at localhost. The lazy endpoint also bypasses the dev server's allowedHosts and allowedOrigins checks. Resolve or explicitly accept these before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "feat: serve lazy compilation from the dev server's own server" matches the main change. The changeset adds setupLazyCompilation() in lib/Server.js, which taps webpack's LazyCompilationPlugi…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "feat: serve lazy compilation from the dev server's own server" matches the main change. The changeset adds setupLazyCompilation() in lib/Server.js, which taps webpack's LazyCompilationPlugin backendOptions hook and passes the dev server's server and URL base. The objectives describe the same goal: lazy-compilation traffic uses the dev server's server instead of a separate random-port server. The title is specific and uses a conventional commit prefix.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 5ec28b13-39ae-487c-bb5e-c7404e76058a
Commits
Reviewing files that changed from the base of the PR and between 796262e and 5b926df.
Files selected for processing: 3
.changeset/lazy-compilation-shared-server.md
lib/Server.js
test/e2e/lazy-compilation.test.js
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
With `port: 0` the url is only known once listening, which plugin mode
does after the first build, so the backend keeps its own server. An
explicit `listen: 0` now counts as the configuration's own setting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FhutTE6yv5FArV4ThNJrq
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (2)
Major · Do not advertise localhost to remote browsers. · Server.js:2891-2893
lib/Server.js:2891-2893 Major · Functional Correctness · Heavy lift
Do not advertise localhost to remote browsers.
With host: "0.0.0.0", a browser on another machine can load the app using the dev machine's LAN address. The generated lazy client instead connects to localhost, which points to the browser's own machine. The lazy import cannot activate on the dev server. Resolve the shared endpoint against the page origin for browser clients when the bind address is not a client-facing hostname. Keep a reachable absolute URL for non-browser clients and preserve explicit backend overrides. (raw.githubusercontent.com)
Major · Lazy compilation stays bound to the first HTTP server after a restart. · Server.js:2885
lib/Server.js:2885 Major · Stability & Availability · Heavy lift
Lazy compilation stays bound to the first HTTP server after a restart.
The lazy-compilation backend starts once per compiler. The backendOptions hook runs only on that first build, and the plugin keeps the backend afterward. When stop() and start() reuse the same compiler, the next build keeps the backend attached to the closed server. The new listener does not route lazy requests to that backend, so lazy imports can fail after the restart.
Before this change, the lazy listener stayed open across a restart. This change removes that behavior for shared-server setups.
Make lazy requests reach a live listener after stop() and start() on the same compiler. Choose one approach: rebind the backend to the listener that start() creates, or keep the shared server open across restarts. The supplied plugin source exposes no reset for the cached backend, so this change needs a webpack-side hook or a different restart policy. Add a test that restarts a dev server with lazy compilation enabled and requests a lazy module afterward.
Minor comments: 1
lib/Server.js: 1
2885-2885: Minor · Security & Privacy · Poor tradeoff
Apply the dev server's Host and Origin rules to the shared lazy endpoint.
When server: this.server is passed to webpack's lazy-compilation backend, the backend's dispatcher answers requests for its URL prefix before the Express app runs. The host-header-check and cross-origin-header-check middleware in lib/Server.js do not run for those requests. A request with a disallowed Host or Origin header can therefore open the lazy event stream and activate a known lazy module, which triggers a rebuild.
Require the lazy endpoint to pass the same Host and Origin rules before it opens the event stream or activates a module. Requests that pass these rules must still activate lazy modules.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 955da598-19c1-44b3-bc08-f2865a8a2be2
Commits
Reviewing files that changed from the base of the PR and between 5b926df and 5a3de7a.
Files selected for processing: 2
lib/Server.js
test/e2e/lazy-compilation.test.js
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Nitpick comments: 1
test/e2e/lazy-compilation.test.js: 1
119-120: Trivial · Maintainability & Code Quality · Heavy lift
Add a request-level test with webpack’s real hook.
Keep the stand-in to test option handling on older webpack versions. When webpack exposes the real hook, also exercise a lazy import through the shared listener. Check that a permitted client receives the event stream and that a request denied by the dev server’s policy does not. The stand-in cannot detect a dispatcher that skips that policy. (raw.githubusercontent.com)
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: ac35c85b-1d2d-4b9c-a7d9-b7bceb394856
Commits
Reviewing files that changed from the base of the PR and between 5a1e6ec and bdde17a.
Files selected for processing: 2
lib/Server.js
test/e2e/lazy-compilation.test.js
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor comments: 1
lib/Server.js: 1
2886-2886: Minor · Functional Correctness · Poor tradeoff
The lazy-compilation route depends on backend creation order, so a restart can misroute an existing client.
On a shared server, webpack numbers each backend prefix from a process-level counter when the backend is created. A fresh dev-server process can create the compiler backends in a different order. A client opened before the restart then reconnects to the prefix that another compiler now holds. That backend filters the requested module key against its own keys and activates nothing, so the original compiler's lazy module is not activated. Reloading the page recovers it.
The route must stay bound to one compiler across process restarts. The prefix assignment is in webpack's lazyCompilationBackend.js, not in lib/Server.js. The dev server's transport tap cannot change the prefix, so this change does not belong in the tap at line 2886.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 20a4f675-ffa2-413c-ba95-0863987bd0b6
Commits
Reviewing files that changed from the base of the PR and between bdde17a and ebb20b2.
Files selected for processing: 2
lib/Server.js
test/e2e/lazy-compilation.test.js
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The `transport` hook is tapped once per compiler and reads the server the
compiler is served from now, so `stop()` and `start()` again, or a new
server for the same compiler, hand the backend the current one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FhutTE6yv5FArV4ThNJrq
The `transport` hook carries an options object with a custom backend
under `backend`, so this server's `server` and `urlBase` reach it too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FhutTE6yv5FArV4ThNJrq
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
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
With
experiments.lazyCompilation, webpack's backend starts its own server on a random port. It ignores the dev server's host, port and https, and a client that reconnects after a restart reaches a port that is gone.webpack/webpack#23435 adds a
backendOptionshook toLazyCompilationPlugin. This PR taps it, where the compiler's webpack has it, and hands the backend this server and the url it is reached at:The
urlBaseis handed over because in plugin mode the server listens only after the first build, which waits for the backend. Nothing changes with a webpack without the hook or withipc.Measured with webpack/webpack#23435 linked,
lazyCompilation: { entries: false }andport: 18765:http://localhost:<random port>/lazy-compilation-using-http://127.0.0.1:18765/lazy-compilation-using-(answered withtext/event-stream; other requests still served)Depends on webpack/webpack#23435.
What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes, in
test/e2e/lazy-compilation.test.js. The installed webpack predates the hook, so a stand-in hook checks that the dev server passes its server and url, and keeps alistenthe configuration names. It fails without the change.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
The docs could say that lazy compilation runs on the dev server's own host and port when webpack supports it, and that
experiments.lazyCompilation.backend.listenorserveropts out.Use of AI
Claude Code wrote the change and its test, ran the test, the repository's lint and an end-to-end check against webpack/webpack#23435, at the requester's direction.
Generated by Claude Code
Summary by CodeRabbit
localhost.