FredKSchott / esm-hmr

a Hot Module Replacement (HMR) API for your ESM-based dev server.
MIT License
413 stars 11 forks source link

Specification of the WebSocket `esm-hmr` protocol #29

Open TomokiMiyauci opened 2 months ago

TomokiMiyauci commented 2 months ago

Apart from the HMR API, the WebSocket esm-hmr protocol should also be clearly specified.

As an example, GraphQL over WebSocket protocol specification is helpful.

According to this, and based on the current implementation, it is as follows:

Message Types

hotAccept

Direction: Client -> Server

interface HotAcceptMessage {
  type: "hotAccept";
  id: string;
}

reload

Direction: Server -> Client

interface ReloadMessage {
  type: "reload";
}

update

Direction: Server -> Client

interface UpdateMessage {
  type: "update";
  url: string;
}

You may want to unify the id and url fields.