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
{{ message }}
Repository navigation
Commit 0b50966
Browse filesBrowse the repository at this point in the historyBrowse files
feat(hot): speak webpack-dev-server's protocol with hot.protocol
`hot.protocol: { type: "webpack-dev-server", hot, liveReload }` puts
that server's runtime in the page instead of this package's, and speaks
its `{ type, data }` protocol over either transport — what that server
did, ported as it was:
- the runtime goes where a browser runs the compilation, with the query
that server wrote, in its order; `webpack/hot/dev-server` (or
`only-dev-server`) wherever `hot` is on; `__webpack_dev_server_client__`
everywhere; `HotModuleReplacementPlugin`, with that server's warning
when the configuration already has one; and the `EventTarget` emitter
for a universal ES module build. `entry` and `hotEntry` name other
modules for the first two, which is how that server's own
`client/index.js` and a subclass's overrides keep working.
- a client is told `hot`, `liveReload`, `progress`, `reconnect` and
`overlay` when it connects, then the last build's result; each build
sends `invalid`, then `hash` and `ok`, `still-ok`, `warnings` (with
`preventReloading` beside errors) or `errors`, serialized with that
server's stats options and `warningsFilter`.
In this mode the middleware logs under that server's name. The `ws`
server behind `"ws"` is handed out as `hot.implementation`, which that
server exposes as `webSocketServer.implementation`. The Server-Sent
Events client skips the heartbeat, which that runtime would parse, and
connects from the `ws:` url it builds.
TODO in the next major release remove `hot.protocol`, once
webpack-dev-server runs on this package's own runtime.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UjuMAuk9o6UazjHzcAQCTA
`hot.protocol: { type: "webpack-dev-server" }` speaks webpack-dev-server 6's `{ type, data }` protocol and puts that server's own runtime in the page, unchanged, instead of this package's: what webpack-dev-server runs on until its next major release, so nothing its users rely on changes, React Refresh's overlay reading `webpack-dev-server/client/socket` included. The runtime ships as `webpack-dev-middleware/client/webpack-dev-server/*`, the `ws` server behind `hot.transport: "ws"` is handed out as `instance.context.hot.implementation`, and the Server-Sent Events client skips the heartbeat and connects from the `ws:` url that runtime builds.
Copy file name to clipboardExpand all lines: README.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -660,6 +660,49 @@ Add the client entry and `HotModuleReplacementPlugin` to the compilation. Set it
660
660
661
661
Turn it off when you have a client of your own that the middleware will not recognize as one (anything other than `webpack-dev-middleware/client`), or when you do not want the hot runtime in your bundle at all and are using the endpoint through [`subscribe`](#custom-events) instead.
662
662
663
+
#### `hot.protocol`
664
+
665
+
Type: `Object`
666
+
Default: `undefined`
667
+
668
+
> [!NOTE]
669
+
>
670
+
> This is for webpack-dev-server, which runs on it until its next major release, when it is removed. Anything else wants this package's own runtime, which is what you get without it.
671
+
672
+
Speak webpack-dev-server 6's protocol — its `{ type, data }` messages — and put that server's runtime in the page instead of this package's own. Whatever its users rely on comes with it unchanged: `webpack-dev-server/client/socket` and the messages React Refresh's overlay reads from it, the console, the overlay and the progress bar, and updates applied by `webpack/hot/dev-server`.
-`hot` — that server's option of the same name: `true` applies updates in place and reloads when one cannot be applied, `"only"` never reloads, `false` applies none. `true` by default.
691
+
-`liveReload` — reload the page on a build whose updates are not applied in place. `true` by default.
692
+
-`entry` — the runtime module, which its query is appended to. This package's copy by default; webpack-dev-server names its own `client/index.js`, which re-exports it.
693
+
-`hotEntry` — what applies the updates the runtime announces: `webpack/hot/dev-server`, or `webpack/hot/only-dev-server` for `hot: "only"`, by default, and `false` for nothing.
694
+
695
+
[`hot.client`](#client-options) is read as that server's `client` option: `path` in parts — `protocol`, `username`, `password`, `hostname`, `port`, `pathname` — and `logging`, `progress`, `overlay`, `reconnect` and `transport`. Each compilation that is not `devServer: false` gets what that server gave it:
|`entry`, with those options on its query | a browser runs the compilation and `hot.client` is not false |
700
+
|`hotEntry`| it is not `false` — by default, `hot` is not `false`|
701
+
|`__webpack_dev_server_client__`, the client it connects with | always |
702
+
|`HotModuleReplacementPlugin`|`hot` is not `false`|
703
+
704
+
A client is told `hot`, `liveReload`, `progress`, `reconnect` and `overlay` when it connects, then the last build's result; every build after that starts with `invalid` and ends with its `hash` and `ok`, `still-ok`, `warnings` or `errors`.
Copy file name to clipboardExpand all lines: src/hot.js
+69-6Lines changed: 69 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,23 @@
72
72
* @property {(boolean | string)=} token a secret the injected client carries and the endpoint requires; `true` mints one per run, a string uses that one, `false` requires none. Defaults to `false` on both transports; `true` in the next major release
73
73
* @property {boolean=} inject add the hot client entry and `HotModuleReplacementPlugin` to the compilation (default `true`); turn it off to wire them yourself
74
74
* @property {(HotClientOptions | false)=} client options handed to the browser runtime through its entry query; `false` adds no runtime to the page and still applies `HotModuleReplacementPlugin`
75
+
* @property {DevServerProtocol=} protocol speak webpack-dev-server 6's protocol and put its runtime in the page instead of this package's own, for webpack-dev-server itself until its next major release
76
+
*/
77
+
78
+
/**
79
+
* webpack-dev-server 6's protocol and runtime. `hot` and `liveReload` are that
80
+
* server's options of the same names, and `hot.client` is read as its `client`
81
+
* option: `path` in parts, `logging`, `progress`, `overlay`, `reconnect` and
82
+
* `transport`.
83
+
*
84
+
* TODO in the next major release remove this, once webpack-dev-server runs on
85
+
* this package's own runtime.
86
+
* @typedef {object} DevServerProtocol
87
+
* @property {"webpack-dev-server"} type the protocol
88
+
* @property {(boolean | "only")=} hot apply updates in place, `"only"` without falling back to a reload when one cannot be applied; `true` by default
89
+
* @property {boolean=} liveReload reload the page on a build when updates are not applied in place; `true` by default
90
+
* @property {string=} entry the runtime module, which its query is appended to; this package's copy by default — webpack-dev-server names its own `client/index.js`, which re-exports it
91
+
* @property {(string | false)=} hotEntry what applies the updates the runtime announces, added to every compilation; `webpack/hot/dev-server`, or `webpack/hot/only-dev-server` for `hot: "only"`, by default, and `false` for nothing
* @property {((req: IncomingMessage, res: ServerResponse) => void)=} handler answer a request on the endpoint's path; without one a request there is answered `426 Upgrade Required`
149
175
* @property {(() => boolean)=} hasClients true when at least one client is connected; without one a payload is built even if nobody is listening
150
176
* @property {(fn: (client: TClient, req: IncomingMessage) => void) => void} onConnect called with each client once it has joined, and the request it joined with
151
-
* @property {(payload: Payload | CustomPayload) => void} publish publish a payload to every client
152
-
* @property {(client: TClient, payload: Payload | CustomPayload) => void} publishTo publish a payload to a single client
177
+
* @property {(payload: Payload | CustomPayload | DevServerMessage) => void} publish publish a payload to every client
178
+
* @property {(client: TClient, payload: Payload | CustomPayload | DevServerMessage) => void} publishTo publish a payload to a single client
153
179
* @property {() => void} close end every client and stop the heartbeat
154
180
* @property {((server: HttpServer) => void)=} attach answer upgrades on this server
* @property {((req: IncomingMessage, socket: Duplex, head: Buffer) => boolean)=} handleUpgrade answer one upgrade, for a caller that owns the server's `upgrade` event; returns false when the request is not this endpoint's
183
+
* @property {EXPECTED_ANY=} implementation the server underneath, when there is one to hand out — the `ws` server behind the `"ws"` transport
157
184
*/
158
185
159
186
/**
@@ -479,9 +506,10 @@ function publishBundles(bundles, previousBundles, eventStream) {
479
506
* @property {(req: IncomingMessage, socket: Duplex, head: Buffer) => boolean} handleUpgrade answer one WebSocket upgrade, for a caller that owns the server's `upgrade` event and wants to decide each one; returns false when the request is not the endpoint's, or the transport does not answer upgrades
480
507
* @property {(fn: (client: EXPECTED_ANY, req: IncomingMessage) => void) => void} onConnect called with each client once it has joined, and the request it joined with, before anything is published to it
481
508
* @property {(req: IncomingMessage, res: ServerResponse) => void} handle answer a request on the endpoint's path
482
-
* @property {(payload: Payload | CustomPayload) => void} publish publish a payload to every client
483
-
* @property {(client: EXPECTED_ANY, payload: Payload | CustomPayload) => void} publishTo publish a payload to one client, for answering a single connection
509
+
* @property {(payload: Payload | CustomPayload | DevServerMessage) => void} publish publish a payload to every client
510
+
* @property {(client: EXPECTED_ANY, payload: Payload | CustomPayload | DevServerMessage) => void} publishTo publish a payload to one client, for answering a single connection
484
511
* @property {() => void} close end every client and detach the heartbeat
512
+
* @property {EXPECTED_ANY=} implementation the server underneath the transport, when it has one: the `ws` server behind `"ws"`
485
513
*/
486
514
487
515
/**
@@ -504,7 +532,18 @@ function createHot(compiler, userOptions, statsOption) {
Copy file name to clipboardExpand all lines: src/options.json
+46-1Lines changed: 46 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -179,7 +179,7 @@
179
179
"type": "boolean"
180
180
},
181
181
"reconnect": {
182
-
"description": "How many times to reconnect before giving up. Unset, Server-Sent Events keep trying for as long as the page is open — a dev server is expected to come back — while a WebSocket gives up after 10. Setting it applies to both. Deprecated, and removed in the next major release: use `connect`.",
182
+
"description": "How many times to reconnect before giving up. Unset, Server-Sent Events keep trying for as long as the page is open — a dev server is expected to come back — while a WebSocket gives up after 10. Setting it applies to both. Deprecated, and removed in the next major release: use `connect` — except with `hot.protocol`, whose runtime reads this one.",
183
183
"type": "number",
184
184
"minimum": 0
185
185
},
@@ -573,6 +573,51 @@
573
573
"$ref": "#/definitions/HotClient"
574
574
}
575
575
]
576
+
},
577
+
"protocol": {
578
+
"description": "Speak webpack-dev-server 6's protocol and put its runtime in the page, instead of this package's own: what webpack-dev-server runs on until its next major release, when this option is removed. `hot` and `liveReload` are that server's options of the same names, and `hot.client` is read as its `client` option.",
"description": "Apply updates in place; `\"only\"` never falls back to a reload when one cannot be applied. `true` by default.",
590
+
"anyOf": [
591
+
{
592
+
"type": "boolean"
593
+
},
594
+
{
595
+
"enum": ["only"]
596
+
}
597
+
]
598
+
},
599
+
"liveReload": {
600
+
"description": "Reload the page on a build whose updates are not applied in place. `true` by default.",
601
+
"type": "boolean"
602
+
},
603
+
"entry": {
604
+
"description": "The runtime module, which its query is appended to. This package's copy by default; webpack-dev-server names its own `client/index.js`, which re-exports it.",
605
+
"type": "string",
606
+
"minLength": 1
607
+
},
608
+
"hotEntry": {
609
+
"description": "What applies the updates the runtime announces, added to every compilation: `webpack/hot/dev-server`, or `webpack/hot/only-dev-server` for `hot: \"only\"`, by default, and `false` for nothing.",
0 commit comments