Skip to content

fix(browser): eager compile setup files in watch mode#1021

Merged
fi3ework merged 1 commit intomainfrom
fix/browser-eager-setup-files
Mar 6, 2026
Merged

fix(browser): eager compile setup files in watch mode#1021
fi3ework merged 1 commit intomainfrom
fix/browser-eager-setup-files

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Mar 6, 2026

Summary

In browser watch mode, configuring setupFiles alongside test files that import heavy libraries (e.g. @testing-library/react) triggers an HMR fallback reload with a noisy console warning. The root cause is that lazyCompilation was applied uniformly to all modules — when a setup file's lazy proxy activates, the resulting chunk graph update propagates through an entry.ts boundary that has no module.hot.accept() handler, causing Rspack HMR to abort and fall back. This PR excludes resolved setup file paths from lazyCompilation.test so they are compiled eagerly, while test files remain lazy (preserving O(1) initial compile time).

Behavior diff:

watch mode + setupFiles:   HMR fallback warning on startup  →  clean start, no warning
test files (no setupFiles): lazy compilation unchanged       →  unchanged

Changes:

  • createBrowserLazyCompilationConfig(setupFiles) — new helper that builds the lazyCompilation config with a test predicate excluding setup file paths
    • no-op (no test field) when setupFiles is empty, preserving existing behavior
  • createBrowserRuntime — resolves setup files before building the merged Rsbuild config and passes them into the new helper
  • e2e regression: browser-react fixture extended with setupFiles + a test importing @testing-library/react; watch.test.ts asserts no HMR warning on startup
  • unit tests for createBrowserLazyCompilationConfig covering empty, single, and cross-platform path cases

Exclude browser setup files from lazyCompilation so setup imports do not trigger HMR fallback reloads. Add browser React watch coverage for the regression.
@fi3ework fi3ework enabled auto-merge (squash) March 6, 2026 09:29
@fi3ework fi3ework merged commit 706c8ab into main Mar 6, 2026
18 of 20 checks passed
@fi3ework fi3ework deleted the fix/browser-eager-setup-files branch March 6, 2026 09:54
@9aoy 9aoy mentioned this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant