Skip to content

feat(core): support opt-in Node lazy compilation - #8629

Closed
ScriptedAlchemy wants to merge 6 commits into
mainfrom
codex/node-lazy-compilation-opt-in
Closed

ScriptedAlchemy wants to merge 6 commits into
mainfrom
codex/node-lazy-compilation-opt-in

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Node targets currently ignore dev.lazyCompilation. Frameworks that retain a Node runtime need to compile an optional server module when its dynamic import is requested, then resume that request without re-evaluating the entry.

Related to React Router plugin #155. Framework integration is tracked in plugin #158.

Changes

  • Add dev.lazyCompilation.node to opt Node targets into lazy imports during development. Keep entries eager and require HMR; reject production and none modes.
  • Enable Node HMR for the dev action and derive the activation URL from the dev server. Support explicit HTTP(S) URLs with a <port> placeholder.
  • Document the runtime contract in English and Chinese: the framework retains the runtime, applies hot updates after successful compilation, and defines dependency acceptance boundaries.
  • Cover native CommonJS and ESM runtimes through HTTP requests, including deferred compilation, accepted dependency edits, single module evaluation, and isolation between test runtimes. Assertions tolerate duplicate filesystem rebuild notifications while keeping runtime results and accepted-update counts exact.

Upstream dependency

Temporarily pin @rspack/core to npm:@rspack-canary/core@2.2.9-canary-a9cfd15e-20261009001219. It includes the lazy/HMR dependency-identity fix needed to resume imports in a retained runtime, plus the rebuild-origin support from Rspack #15968.

Before stable release: replace the canary pin and its loader-path snapshots with a released Rspack version containing the required fix.

Validation

At 02cc90587c13864bfd20c0e6e4f0191f1820e300:

  • pnpm build and pnpm check passed.
  • All 449 unit tests and 1,123 end-to-end tests passed locally.
  • Ten consecutive focused Node runtime runs passed.
  • Windows and Ubuntu e2e, Windows and macOS unit tests, and lint passed in CI.

Open questions

The tests establish retained-runtime behavior for the covered CJS/ESM scenarios. They do not establish universal restart-free Node support or a net startup/first-request performance benefit. Edits outside an application's acceptance boundaries still require framework handling.

Whether to keep the separate node option or align the configuration directly with Rspack remains a maintainer decision. See the review follow-up for the cross-project evidence and remaining coverage limits.

Require an explicit Node opt-in, eager entries, and HMR. Derive activation URLs from the bound server and validate explicit HTTP(S) endpoints.

Exercise original lazy requests and source updates through retained native CommonJS and ESM runtimes. Apply pending hot revisions until runtime and compiler hashes match.
Document native output requirements, sequential hot updates, and dependency acceptance boundaries. Describe the framework responsibilities that remain after the opt-in.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Deploying rsbuild with  Cloudflare Pages  Cloudflare Pages

Latest commit: 465c960
Status: ✅  Deploy successful!
Preview URL: https://4eb5c41f.rsbuild-v2.pages.dev
Branch Preview URL: https://codex-node-lazy-compilation.rsbuild-v2.pages.dev

View logs

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether lazy compilation for Node targets currently works reliably in all supported scenarios. If we can confirm that it does, I'd prefer to keep the configuration aligned with Rspack and avoid introducing a separate node option.

@stormslowly cc

@stormslowly

Copy link
Copy Markdown
Contributor

Lazy compilation makes the SSR server startup quickly, but it may introduce some APP restarts (like a full page reload in the web target).

Maybe we need to evaluate whether the quick startup benefits cover the effects of restarts.

@ScriptedAlchemy

ScriptedAlchemy commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

I haven't seen server restarts or other tabs reloading during lazy imports in the cases I tested. I also ran the startup comparison: lazy compilation was slower in all 40 paired runs on the example workload, with identical packages. I didn't find a performance benefit, so I'm closing this PR.

Measurements and reproduction steps.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants