feat: support server custom message handling by module.hot.on#7003
feat: support server custom message handling by module.hot.on#7003chenjiahan merged 9 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Summary of ChangesHello @SyMind, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the development server's capabilities by enabling it to send custom messages to the client-side HMR system. This feature allows for more flexible and powerful interactions between the server and client during development, facilitating custom HMR behaviors. The changes also include careful management of HMR event listeners to ensure they are correctly disposed of when modules are reloaded, preventing potential issues. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a great feature for sending custom messages from the dev server to the client using module.hot.on. The implementation is well-thought-out, especially the mechanism for disposing of HMR listeners to prevent leaks. The accompanying e2e tests cover the new functionality well. I've provided a few suggestions to improve the robustness and performance of the implementation, including a fix for a potential race condition in one of the new tests.
There was a problem hiding this comment.
Pull request overview
This PR adds support for server-side custom message handling through the HMR system, enabling developers to send custom events from the server to the client via module.hot.on. The implementation extracts custom message handling logic into a dedicated helper function.
Changes:
- Added
ServerCustomMessagetype to support custom WebSocket messages - Implemented
setupCustomHMRListenersto intercept and managemodule.hot.onlisteners with proper cleanup on module disposal - Added
RspackRuntimeReplacePluginto replace build-time constants with runtime values - Created comprehensive E2E tests verifying custom message handling and listener disposal
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/server/socketServer.ts | Adds ServerCustomMessage type definition to the message union |
| packages/core/src/client/hmr.ts | Implements custom HMR listener setup with disposal logic and message handling |
| packages/core/rslib.config.ts | Adds plugin for runtime constant replacement and reorganizes imports |
| e2e/cases/javascript-api/server-custom-message/src/index.js | Test source file demonstrating custom event listener usage |
| e2e/cases/javascript-api/server-custom-message/index.test.ts | E2E tests validating custom message delivery and listener cleanup |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Deploying rsbuild-v2 with
|
| Latest commit: |
2efad7e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cfe20187.rsbuild-v2.pages.dev |
| Branch Preview URL: | https://module-hot-on.rsbuild-v2.pages.dev |
| const rsbuild = await createRsbuild({ | ||
| cwd: import.meta.dirname, | ||
| }); | ||
|
|
||
| const server = await rsbuild.createDevServer(); | ||
|
|
||
| await server.listen(); |
There was a problem hiding this comment.
Can we just use the dev helper?
There was a problem hiding this comment.
Feel free to update the helper
Deploying rsbuild with
|
| Latest commit: |
d431722
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://217fce2d.rsbuild-v2.pages.dev |
| Branch Preview URL: | https://module-hot-on.rsbuild-v2.pages.dev |
|
👍 |

Summary
This PR improves the client-side HMR custom message handling by extracting the
module.hot.oninterception logic into a dedicated helpersetupCustomHMRListeners.Related Links
Checklist