Skip to content

Commit e7d38ab

Browse files
authored
docs: deprecate server.hot (#16741)
1 parent 76fbbba commit e7d38ab

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

docs/guide/api-plugin.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
428428

429429
```js
430430
handleHotUpdate({ server, modules, timestamp }) {
431-
// Also use `server.ws.send` to support Vite <5.1 if needed
432-
server.hot.send({ type: 'full-reload' })
431+
server.ws.send({ type: 'full-reload' })
433432
// Invalidate modules manually
434433
const invalidatedModules = new Set()
435434
for (const mod of modules) {
@@ -448,8 +447,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
448447

449448
```js
450449
handleHotUpdate({ server }) {
451-
// Also use `server.ws.send` to support Vite <5.1 if needed
452-
server.hot.send({
450+
server.ws.send({
453451
type: 'custom',
454452
event: 'special-update',
455453
data: {}
@@ -556,7 +554,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi
556554

557555
### Server to Client
558556

559-
On the plugin side, we could use `server.hot.send` (since Vite 5.1) or `server.ws.send` to broadcast events to all the clients:
557+
On the plugin side, we could use `server.ws.send` to broadcast events to the client:
560558

561559
```js
562560
// vite.config.js
@@ -565,9 +563,8 @@ export default defineConfig({
565563
{
566564
// ...
567565
configureServer(server) {
568-
// Example: wait for a client to connect before sending a message
569-
server.hot.on('connection', () => {
570-
server.hot.send('my:greetings', { msg: 'hello' })
566+
server.ws.on('connection', () => {
567+
server.ws.send('my:greetings', { msg: 'hello' })
571568
})
572569
},
573570
},
@@ -603,7 +600,7 @@ if (import.meta.hot) {
603600
}
604601
```
605602

606-
Then use `server.hot.on` (since Vite 5.1) or `server.ws.on` and listen to the events on the server side:
603+
Then use `server.ws.on` and listen to the events on the server side:
607604

608605
```js
609606
// vite.config.js
@@ -612,7 +609,7 @@ export default defineConfig({
612609
{
613610
// ...
614611
configureServer(server) {
615-
server.hot.on('my:from-client', (data, client) => {
612+
server.ws.on('my:from-client', (data, client) => {
616613
console.log('Message from client:', data.msg) // Hey!
617614
// reply only to the client (if needed)
618615
client.send('my:ack', { msg: 'Hi! I got your message!' })

packages/vite/src/node/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
130130
* the descriptors.
131131
*
132132
* - The hook can also return an empty array and then perform custom updates
133-
* by sending a custom hmr payload via server.hot.send().
133+
* by sending a custom hmr payload via server.ws.send().
134134
*
135135
* - If the hook doesn't return a value, the hmr update will be performed as
136136
* normal.

packages/vite/src/node/server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ export interface ViteDevServer {
242242
watcher: FSWatcher
243243
/**
244244
* web socket server with `send(payload)` method
245-
* @deprecated use `hot` instead
246245
*/
247246
ws: WebSocketServer
248247
/**
249248
* HMR broadcaster that can be used to send custom HMR messages to the client
250249
*
251250
* Always sends a message to at least a WebSocket client. Any third party can
252251
* add a channel to the broadcaster to process messages
252+
* @deprecated will be replaced with the environment api in v6.
253253
*/
254254
hot: HMRBroadcaster
255255
/**

0 commit comments

Comments
 (0)