fix(browser): eager compile setup files in watch mode#1021
Merged
Conversation
Exclude browser setup files from lazyCompilation so setup imports do not trigger HMR fallback reloads. Add browser React watch coverage for the regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In browser watch mode, configuring
setupFilesalongside 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 thatlazyCompilationwas applied uniformly to all modules — when a setup file's lazy proxy activates, the resulting chunk graph update propagates through anentry.tsboundary that has nomodule.hot.accept()handler, causing Rspack HMR to abort and fall back. This PR excludes resolved setup file paths fromlazyCompilation.testso they are compiled eagerly, while test files remain lazy (preserving O(1) initial compile time).Behavior diff:
Changes:
createBrowserLazyCompilationConfig(setupFiles)— new helper that builds thelazyCompilationconfig with atestpredicate excluding setup file pathstestfield) whensetupFilesis empty, preserving existing behaviorcreateBrowserRuntime— resolves setup files before building the merged Rsbuild config and passes them into the new helperbrowser-reactfixture extended withsetupFiles+ a test importing@testing-library/react;watch.test.tsasserts no HMR warning on startupcreateBrowserLazyCompilationConfigcovering empty, single, and cross-platform path cases