Skip to content

Conversation

@stormslowly
Copy link
Contributor

@stormslowly stormslowly commented Jan 8, 2026

Summary

The original method of passing module IDs to the active state via URL query strings may encounter limitations related to browser/server constraints or URL length. Therefore, we are refactoring this process to pass those IDs through the POST body instead.

To handle potential bursts of requests when activating modules, we will implement a request queue during the activation process. The steps are as follows:

  1. During the activation request for lazy modules, all active requests will be buffered in a compiling set.
  2. After the Hot Module Replacement (HMR) for the previous request is completed, we will proceed to make the next active request, including all buffered module IDs. Then, we will return to step 1 to manage further requests.

Related Links

Closes Issue #12649.

Checklist

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

@netlify
Copy link

netlify bot commented Jan 8, 2026

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit c0078ad
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/69675f34b029ba00086b7785

@github-actions github-actions bot added release: refactor team The issue/pr is created by the member of Rspack. labels Jan 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-5k 2.7 MB 0
rome 984.3 KB 0
react-1k 825.4 KB 0
ui-components 2.1 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

📦 Binary Size-limit

Comparing c0078ad to chore(deps): update patch crates (#12716) by renovate[bot]

🙈 Size remains the same at 47.90MB

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 8, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing refactor/lazy_active_module_id_goes_to_post_body (c0078ad) with main (36866ea)

Summary

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

📝 Ecosystem CI detail: Open

suite result
rsdoctor ✅ success
modernjs ✅ success
rspress ✅ success
rsbuild ✅ success
nuxt ✅ success
plugin ✅ success
rstest ❌ failure
lynx-stack ❌ failure
devserver ❌ failure
rslib ❌ failure
examples ✅ success

1. 如果其他中间件一个解析好了body,并挂载在req.body 上的花就直直接使用 req.body
2. packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts body 解析的时候不能简单的使用 string 的拼接,需要考虑多字节符号的截断的问题。
packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts 当req.body 非空时,直接假body中时一组 module ids,如果没有 body 自行拼接完,之后也 parse json string,返回 module ids 数组
@stormslowly stormslowly force-pushed the refactor/lazy_active_module_id_goes_to_post_body branch from 7362078 to 5d8eeb5 Compare January 13, 2026 07:33
@stormslowly stormslowly marked this pull request as ready for review January 14, 2026 03:59
@stormslowly stormslowly requested a review from hardfist as a code owner January 14, 2026 03:59
Copilot AI review requested due to automatic review settings January 14, 2026 03:59
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.

PR title: refactor -> refactor(lazy-compilation)

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
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 pull request refactors the lazy compilation mechanism to transmit active module IDs via POST request body instead of URL query parameters, addressing URL length limitations in browsers and servers. The change replaces EventSource-based communication with XMLHttpRequest using simple CORS requests (Content-Type: text/plain) to avoid preflight checks in cross-origin scenarios.

Changes:

  • Migrated from EventSource to XMLHttpRequest with POST requests for activating lazy-compiled modules
  • Implemented request queuing to batch module activations and avoid overwhelming the server
  • Added backward compatibility by maintaining GET request support in the middleware
  • Added comprehensive tests for cross-origin scenarios and handling many modules with long filenames

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/rspack/hot/lazy-compilation-web.js Complete rewrite from EventSource to XMLHttpRequest with request queuing logic
packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts Added POST body parsing with backward-compatible GET support
tests/e2e/cases/lazy-compilation/cross-origin/* New test suite verifying cross-origin POST requests work correctly
tests/e2e/cases/lazy-compilation/active-lots-modules/* New test for URL length limitation scenario with many long-named modules
tests/e2e/cases/lazy-compilation/custom-prefix/index.test.ts Updated test to not check request method (now supports both GET and POST)
packages/rspack-test-tools/src/runner/web/index.ts Added POST request proxying for lazy compilation in test environment
packages/rspack/etc/core.api.md Marked lazyCompilationMiddleware as undocumented
Comments suppressed due to low confidence (1)

packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts:231

  • The middleware always sets Server-Sent Events (SSE) headers even for POST requests. For POST requests, the response should end immediately (which it does on line 247), but setting SSE headers like 'content-type: text/event-stream' is misleading and inappropriate for a simple POST response. These headers should only be set for GET requests that maintain a persistent connection.
    req.socket.setNoDelay(true);

    res.setHeader('content-type', 'text/event-stream');
    res.writeHead(200);
    res.write('\n');

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…thub.com:web-infra-dev/rspack into refactor/lazy_active_module_id_goes_to_post_body
@stormslowly stormslowly changed the title refactor: use post transfer ids of active modules refactor(lazy-compilation): use post transfer ids of active modules Jan 14, 2026
@stormslowly stormslowly force-pushed the refactor/lazy_active_module_id_goes_to_post_body branch from 1d54eb6 to bf0fc1f Compare January 14, 2026 07:08
@stormslowly stormslowly changed the title refactor(lazy-compilation): use post transfer ids of active modules refactor(lazy-compilation): use POST request to transfer ids of active modules Jan 14, 2026
@chenjiahan chenjiahan merged commit ad662bc into main Jan 15, 2026
54 checks passed
@chenjiahan chenjiahan deleted the refactor/lazy_active_module_id_goes_to_post_body branch January 15, 2026 05:42
LingyuCoder pushed a commit that referenced this pull request Jan 16, 2026
…e modules (#12678)

* refactor: use post transfer module ids

* test: skip lazy active method

* test: add lazy post request help

* test: add large module id container

* test: add case introduction

* refactor: remove about controller

* test: we are using post method now

* refactor: rename

* fix body parser (vibe-kanban 09797829)

1. 如果其他中间件一个解析好了body,并挂载在req.body 上的花就直直接使用 req.body
2. packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts body 解析的时候不能简单的使用 string 的拼接,需要考虑多字节符号的截断的问题。

* refactor read module ids from body (vibe-kanban a7874ac1)

packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts 当req.body 非空时,直接假body中时一组 module ids,如果没有 body 自行拼接完,之后也 parse json string,返回 module ids 数组

* refactor: downgrading to lower web api

* test: ✅ add lazy compilation active cors cases

* chore: update test case doc

* fix: we all need cors header no matter is simple request or not

* refactor:delete cors header setting

* refactor: set cors header should set by user

* Update packages/rspack/hot/lazy-compilation-web.js

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>

* test: fix case name

* chore: api-extract update

* fix: memory leak of requst listeners

* refactor: remove event source handle logic

* fix: jsdom XMLHTTPRequets need strict cors header

* refactor: node lazy compilation client use post too

---------

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
chenjiahan added a commit that referenced this pull request Jan 16, 2026
…e modules (#12678)

* refactor: use post transfer module ids

* test: skip lazy active method

* test: add lazy post request help

* test: add large module id container

* test: add case introduction

* refactor: remove about controller

* test: we are using post method now

* refactor: rename

* fix body parser (vibe-kanban 09797829)

1. 如果其他中间件一个解析好了body,并挂载在req.body 上的花就直直接使用 req.body
2. packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts body 解析的时候不能简单的使用 string 的拼接,需要考虑多字节符号的截断的问题。

* refactor read module ids from body (vibe-kanban a7874ac1)

packages/rspack/src/builtin-plugin/lazy-compilation/middleware.ts 当req.body 非空时,直接假body中时一组 module ids,如果没有 body 自行拼接完,之后也 parse json string,返回 module ids 数组

* refactor: downgrading to lower web api

* test: ✅ add lazy compilation active cors cases

* chore: update test case doc

* fix: we all need cors header no matter is simple request or not

* refactor:delete cors header setting

* refactor: set cors header should set by user

* Update packages/rspack/hot/lazy-compilation-web.js

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>

* test: fix case name

* chore: api-extract update

* fix: memory leak of requst listeners

* refactor: remove event source handle logic

* fix: jsdom XMLHTTPRequets need strict cors header

* refactor: node lazy compilation client use post too

---------

Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LazyCompilation causes ENAMETOOLONG

3 participants