You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given that the same plugin instance is used for different environments, the plugin state needs to be keyed with `this.environment`. This is the same pattern the ecosystem has already been using to keep state about modules using the `ssr` boolean as key to avoid mixing client and ssr modules state. A `Map<Environment, State>` can be used to keep the state for each environment separately. Note that for backward compatibility, `buildStart` and `buildEnd` are only called for the client environment without the `perEnvironmentStartEndDuringDev:true` flag. Same for `watchChange` and the `perEnvironmentWatchChangeDuringDev:true` flag.
`environment.hot`allows plugins to communicate with the code on the application side for a given environment. This is the equivalent of [the Client-server Communication feature](/guide/api-plugin#client-server-communication), but supports environments other than the client environment.
Be aware that there might be multiple application instances running in the same environment. For example, if you multiple tabs open in the browser, each tab is a separate application instance and have a separate connection to the server.
When a new connection is established, a `vite:client:connect`event is emitted on the environment's `hot` instance. When the connection is closed, a `vite:client:disconnect`event is emitted.
Each event handler receives the `NormalizedHotChannelClient`as the second argument. The client is an object with a `send`method that can be used to send messages to that specific application instance. The client reference is always the same for the same connection, so you can keep it to track the connection.
Copy file name to clipboardExpand all lines: guide/api-environment-runtimes.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -381,13 +381,9 @@ await createServer({
381
381
382
382
:::
383
383
384
-
<<<<<<< HEAD
385
-
使用 HTTP 请求在运行程序和服务器之间进行通信的另一个示例:
386
-
=======
387
-
Make sure to implement the `vite:client:connect` / `vite:client:disconnect` events in the `on` / `off` methods when those methods exist. `vite:client:connect` event should be emitted when the connection is established, and `vite:client:disconnect` event should be emitted when the connection is closed. The `HotChannelClient` object passed to the event handler must have the same reference for the same connection.
0 commit comments