-
-
Notifications
You must be signed in to change notification settings - Fork 737
feat: use __rspack_dev_server_uri to communicate to right dev server #12281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the lazy compilation feature for web environments by adding support for __rspack_dev_server_uri. This allows the lazy compilation client to correctly communicate with the dev server when the application is running behind a proxy or on a different origin than localhost. The change ensures that relative URLs are properly resolved to the correct dev server location.
Key Changes
- Added logic to prepend
__rspack_dev_server_urito relative URLs in lazy compilation - Only applies when URL is not already absolute (doesn't start with "http")
- Depends on rspack-dev-server PR #53 for the server-side implementation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| !urlBase.startsWith("http") && | ||
| typeof __rspack_dev_server_uri !== "undefined" | ||
| ) { | ||
| urlBase = __rspack_dev_server_uri + urlBase; |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential URL concatenation issue: When concatenating __rspack_dev_server_uri with urlBase, there's no handling for trailing/leading slashes. This could result in malformed URLs like http://example.com//path (double slash) or http://example.compath (missing slash).
Consider normalizing the URL concatenation:
var separator = __rspack_dev_server_uri.endsWith("/") || urlBase.startsWith("/") ? "" : "/";
urlBase = __rspack_dev_server_uri + separator + urlBase;Or ensure proper slash handling:
urlBase = __rspack_dev_server_uri.replace(/\/$/, "") + "/" + urlBase.replace(/^\//, "");| urlBase = __rspack_dev_server_uri + urlBase; | |
| urlBase = __rspack_dev_server_uri.replace(/\/$/, "") + "/" + urlBase.replace(/^\//, ""); |
| if ( | ||
| !urlBase.startsWith("http") && | ||
| typeof __rspack_dev_server_uri !== "undefined" | ||
| ) { | ||
| urlBase = __rspack_dev_server_uri + urlBase; | ||
| } |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding a comment explaining the purpose of prepending __rspack_dev_server_uri to help future maintainers understand this logic. For example:
// When running behind a proxy or on a different origin, use the dev server URI
// provided by rspack-dev-server to construct the full URL for lazy compilation
if (
!urlBase.startsWith("http") &&
typeof __rspack_dev_server_uri !== "undefined"
) {
urlBase = __rspack_dev_server_uri + urlBase;
}| if ( | |
| !urlBase.startsWith("http") && | |
| typeof __rspack_dev_server_uri !== "undefined" | |
| ) { | |
| urlBase = __rspack_dev_server_uri + urlBase; | |
| } |
📦 Binary Size-limit
🙈 Size remains the same at 47.65MB |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
CodSpeed Performance ReportMerging #12281 will not alter performanceComparing Summary
|
chenjiahan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a reasonable design, because most higher-level tools (including Rsbuild and Modern.js) do not use @rspack/dev-server.
I agree that high-level tools should configure RSPack correctly. However, there is a key difference in this case. We need to know the final For Lazy Compilation, if the I believe there are two ways to achieve this: Config PhaseBefore the compiler starts running, configure the Runtime PhaseDuring runtime, the hostname and port for active lazy compilation are determined. Therefore, Lazy Compilation needs a way to obtain the dev server information. A "magic variable" is one potential solution. Without the variable For Rsbuild and Modern.js, they can either adapt to this magic variable or opt for the configuration phase solution. |
Summary
This update depends on Pull Request #53.
This change enhances the developer experience for users running the development server on a proxied site rather than on localhost.
For example, if the development server starts on a localhost auto port, and the user configures
lazyCompilation: true(using the default settings), the development assets are proxied to a site likehttps://a.com.Before
With lazy compilation enabled, requests would be sent to
https://a.com/lazy-compilation-using-compilation-proxy....These requests would fail, resulting in a blank page.After
Requests will now be sent to
http://127.0.0.1:8080/lazy-compilation-using-compilation-proxy...., allowing lazy compilation to function as expected.Related Links
Checklist