Skip to content

fix: prevent HMR configs from overlapping across environments#6656

Merged
chenjiahan merged 2 commits intomainfrom
hmr_client_1127
Nov 27, 2025
Merged

fix: prevent HMR configs from overlapping across environments#6656
chenjiahan merged 2 commits intomainfrom
hmr_client_1127

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

In the previous implementation, different environments could end up sharing the same hmr.js module 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

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

Copilot AI review requested due to automatic review settings November 27, 2025 13:38
@netlify
Copy link
Copy Markdown

netlify bot commented Nov 27, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 7e95bbc
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/6928568d5b832c000872f71f
😎 Deploy Preview https://deploy-preview-6656--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 71 (🟢 up 12 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
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 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.ts from using global constants to an init() function that accepts configuration parameters
  • Updated global type definitions to use BUILD_HASH instead 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.

@chenjiahan chenjiahan merged commit fc174b0 into main Nov 27, 2025
11 checks passed
@chenjiahan chenjiahan deleted the hmr_client_1127 branch November 27, 2025 13:57
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.

[Bug]: Rsbuild MF v2 plugin infinity reloads one bundle entry when use plugin in multi-enviroment

2 participants