fix: prevent HMR configs from overlapping across environments#6656
Merged
chenjiahan merged 2 commits intomainfrom Nov 27, 2025
Merged
fix: prevent HMR configs from overlapping across environments#6656chenjiahan merged 2 commits intomainfrom
chenjiahan merged 2 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request addresses an issue where different environments could share the same HMR module and use incorrect WebSocket tokens. The solution restructures HMR client injection by introducing a virtual module as the entry point, ensuring each environment gets its own isolated configuration.
Key Changes:
- Replaced static HMR client entry files with dynamically generated virtual modules containing environment-specific configuration
- Converted
hmr.tsfrom using global constants to aninit()function that accepts configuration parameters - Updated global type definitions to use
BUILD_HASHinstead of multiple environment-specific constants
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/server/assets-middleware/index.ts | Removed getClientPaths() function and replaced DefinePlugin + EntryPlugin approach with a single virtual module entry containing inline configuration |
| packages/core/src/env.d.ts | Removed multiple environment-specific global constants, added BUILD_HASH to replace WEBPACK_HASH |
| packages/core/src/client/hmr.ts | Refactored from module-level variables to an init() function that accepts configuration parameters for better isolation |
| packages/core/rslib.config.ts | Renamed WEBPACK_HASH define to BUILD_HASH for consistency |
| e2e/cases/hmr/client-multiple-environment/index.test.ts | Updated test assertions to match JSON.stringify spacing format |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Nov 29, 2025
Merged
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 the previous implementation, different environments could end up sharing the same
hmr.jsmodule and using the wrong WebSocket token. (see #6150 (comment))This PR restructures how HMR clients are injected, introducing a virtual module as the new entry point to fix the issue.
Related Links
resolve #6646
Checklist