refactor(core): rename socket server send method#7476
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the core dev-server websocket implementation by renaming the internal SocketServer.sockWrite method to sendMessage (and its low-level sender to sendRawMessage), then updates internal call sites and modernizes non-legacy e2e coverage to use the environment-scoped HMR send API.
Changes:
- Rename internal
SocketServer.sockWrite→sendMessageandsend→sendRawMessage, plus update internal usages. - Switch relevant internal triggers (watch files, dev-server hot sender, assets middleware) to call
sendMessage. - Update non-legacy e2e tests to prefer
server.environments.web.hot.send(...)while keeping explicitsockWritecompatibility tests elsewhere.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/server/watchFiles.ts | Update reload-on-change to use socketServer.sendMessage. |
| packages/core/src/server/socketServer.ts | Rename internal socket broadcast API to sendMessage and raw sender to sendRawMessage. |
| packages/core/src/server/devServer.ts | Route environment hot send implementation through socketServer.sendMessage. |
| packages/core/src/server/assets-middleware/index.ts | Use sendMessage for HTML-triggered full reload. |
| e2e/cases/server/setup-middlewares/index.test.ts | Prefer server.environments.web.hot.send('full-reload') in server.setup test. |
| e2e/cases/javascript-api/server-custom-message/index.test.ts | Prefer server.environments.web.hot.send('custom', ...) for custom HMR messages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request renames the sockWrite method to sendMessage and the send method to sendRawMessage within the SocketServer class, updating all references across the core packages and E2E tests. Feedback was provided to optimize the sendMessage function by deferring JSON serialization until it is confirmed that active sockets are available to receive the message.
Summary
SocketServer.sockWritemethod tosendMessageto better match its behavior of sending structured server messages to matching HMR clientsenvironment.web.hot.send, while keeping the dedicatedsockWritecompatibility coverage in placeRelated Links
None