rspack icon indicating copy to clipboard operation
rspack copied to clipboard

[Bug]: devServer.headers are not added to experiments.lazyCompilation middlewar

Open adrianwawryczuk opened this issue 7 months ago • 2 comments

System Info

System: OS: macOS 15.3.2 CPU: (12) arm64 Apple M2 Pro Memory: 391.30 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.12.1 - ~/.asdf/installs/nodejs/20.12.1/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.5.0 - ~/.asdf/installs/nodejs/20.12.1/bin/npm pnpm: 10.0.0 - ~/Library/pnpm/pnpm Browsers: Safari: 18.3.1 npmPackages: @rspack/cli: 1.3.5 => 1.3.5 @rspack/core: 1.3.5 => 1.3.5 @rspack/plugin-react-refresh: 1.2.1 => 1.2.1

Details

Hey, after upgrading Rspack to >1.3 and getting an error related to the Lazy Compilation

The issue I see is that the headers configured in devServer are not respected by the new LazyCompilationMiddleware. So when the lazy compilation server is configured to a different address than the app, it results in Cors errors.

Reproduce link

I'm not sure it's possible in this template

Reproduce Steps

  • Configure server side rendered app and set cross origin config
  • Set the lazyCompilation { serverUrl: http://localhost:3050 }
  • Set the dev server: devServer: { port: 3050, static: './public/assets', headers: { 'Access-Control-Allow-Origin': '*' }

adrianwawryczuk avatar Apr 15 '25 21:04 adrianwawryczuk

Emmm, are you using @rspack/cli and @rspack/dev-server as your dev server ?

JSerFeng avatar Apr 16 '25 09:04 JSerFeng

Hello @adrianwawryczuk, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

github-actions[bot] avatar Apr 16 '25 09:04 github-actions[bot]

Since the issue was labeled with need reproduction, but no response in 14 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions.

github-actions[bot] avatar May 01 '25 00:05 github-actions[bot]

@JSerFeng I have this same issue. For my situation, I have the webpage actually served by www.mydomain.com, but the rspack dev server is running on local.mydomain.com:3000. I hook into rspack by serving HTML with a <script src="http://local.mydomain.com:3000/entrypoint.js" /> (figuratively).

I have specified experiments.lazyCompilation.serverUrl to be http://local.mydomain.com:3000/.

As a consequence, the /lazy-compilation-using- requests are being sent to the right place (the devServer), but the browser wants Access-Control headers on them since there's a domain mismatch. I tried to solve this by specifying devServer.headers, but it seems like that does not apply to lazyCompilationMiddleware.

Maybe that's better information to try and repro? Otherwise I can have a crack at preparing a minimal set.

giles-v avatar Jul 16 '25 14:07 giles-v

Since the issue was labeled with need reproduction, but no response in 14 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions.

github-actions[bot] avatar Aug 02 '25 00:08 github-actions[bot]