Skip to content

Commit

Permalink
docs: deprecate server.hot (#16741)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre authored May 23, 2024
1 parent 76fbbba commit e7d38ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
```js
handleHotUpdate({ server, modules, timestamp }) {
// Also use `server.ws.send` to support Vite <5.1 if needed
server.hot.send({ type: 'full-reload' })
server.ws.send({ type: 'full-reload' })
// Invalidate modules manually
const invalidatedModules = new Set()
for (const mod of modules) {
Expand All @@ -448,8 +447,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
```js
handleHotUpdate({ server }) {
// Also use `server.ws.send` to support Vite <5.1 if needed
server.hot.send({
server.ws.send({
type: 'custom',
event: 'special-update',
data: {}
Expand Down Expand Up @@ -556,7 +554,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi
### Server to Client
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:
On the plugin side, we could use `server.ws.send` to broadcast events to the client:
```js
// vite.config.js
Expand All @@ -565,9 +563,8 @@ export default defineConfig({
{
// ...
configureServer(server) {
// Example: wait for a client to connect before sending a message
server.hot.on('connection', () => {
server.hot.send('my:greetings', { msg: 'hello' })
server.ws.on('connection', () => {
server.ws.send('my:greetings', { msg: 'hello' })
})
},
},
Expand Down Expand Up @@ -603,7 +600,7 @@ if (import.meta.hot) {
}
```
Then use `server.hot.on` (since Vite 5.1) or `server.ws.on` and listen to the events on the server side:
Then use `server.ws.on` and listen to the events on the server side:
```js
// vite.config.js
Expand All @@ -612,7 +609,7 @@ export default defineConfig({
{
// ...
configureServer(server) {
server.hot.on('my:from-client', (data, client) => {
server.ws.on('my:from-client', (data, client) => {
console.log('Message from client:', data.msg) // Hey!
// reply only to the client (if needed)
client.send('my:ack', { msg: 'Hi! I got your message!' })
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface Plugin<A = any> extends RollupPlugin<A> {
* the descriptors.
*
* - The hook can also return an empty array and then perform custom updates
* by sending a custom hmr payload via server.hot.send().
* by sending a custom hmr payload via server.ws.send().
*
* - If the hook doesn't return a value, the hmr update will be performed as
* normal.
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ export interface ViteDevServer {
watcher: FSWatcher
/**
* web socket server with `send(payload)` method
* @deprecated use `hot` instead
*/
ws: WebSocketServer
/**
* HMR broadcaster that can be used to send custom HMR messages to the client
*
* Always sends a message to at least a WebSocket client. Any third party can
* add a channel to the broadcaster to process messages
* @deprecated will be replaced with the environment api in v6.
*/
hot: HMRBroadcaster
/**
Expand Down

0 comments on commit e7d38ab

Please sign in to comment.