Skip to content

Conversation

@stormslowly
Copy link
Contributor

@stormslowly stormslowly commented Nov 25, 2025

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 like https://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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 25, 2025 09:27
@netlify
Copy link

netlify bot commented Nov 25, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit e4661da
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/692579d2faee2600086db2ac

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Nov 25, 2025
Copilot finished reviewing on behalf of stormslowly November 25, 2025 09:29
Copy link
Contributor

Copilot AI left a 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_uri to 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;
Copy link

Copilot AI Nov 25, 2025

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(/^\//, "");
Suggested change
urlBase = __rspack_dev_server_uri + urlBase;
urlBase = __rspack_dev_server_uri.replace(/\/$/, "") + "/" + urlBase.replace(/^\//, "");

Copilot uses AI. Check for mistakes.
Comment on lines 8 to 13
if (
!urlBase.startsWith("http") &&
typeof __rspack_dev_server_uri !== "undefined"
) {
urlBase = __rspack_dev_server_uri + urlBase;
}
Copy link

Copilot AI Nov 25, 2025

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;
}
Suggested change
if (
!urlBase.startsWith("http") &&
typeof __rspack_dev_server_uri !== "undefined"
) {
urlBase = __rspack_dev_server_uri + urlBase;
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

📦 Binary Size-limit

Comparing e4661da to chore: release v1.6.5 (#12278) by jinrui

🙈 Size remains the same at 47.65MB

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 25, 2025

CodSpeed Performance Report

Merging #12281 will not alter performance

Comparing feat/use_dev_sever_uri (e4661da) with main (01fbb08)

Summary

✅ 17 untouched

Copy link
Member

@chenjiahan chenjiahan left a 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.

@stormslowly stormslowly marked this pull request as draft November 26, 2025 00:46
@stormslowly
Copy link
Contributor Author

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 hostname and port of the development server. The hostname and port are determined by the dev server; for example, if the port is configured to auto.

For Lazy Compilation, if the serverUrl is not configured properly, the application will go blank. To ensure Lazy Compilation works as expected, it is crucial to direct active requests to the correct server.

I believe there are two ways to achieve this:

Config Phase

Before the compiler starts running, configure the serverUrl with the correct hostname and port. Since the appropriate hostname and port come from the dev server, determining the right configuration at that moment may not be straightforward.

Runtime Phase

During 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 __rspack_dev_server_uri, Lazy Compilation will default to using the browser's URL hostname and port. If the variable exists, it will utilize the configured value.

For Rsbuild and Modern.js, they can either adapt to this magic variable or opt for the configuration phase solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants