Skip to content

Commit 730d0d0

Browse files
committed
feat: enable reload option for HMR by default and update tests
1 parent 6037127 commit 730d0d0

3 files changed

Lines changed: 68 additions & 15 deletions

File tree

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -368,26 +368,26 @@ The runtime connects to `/__webpack_hmr` by default. Any of the options below ca
368368

369369
```js
370370
entry: [
371-
"webpack-dev-middleware/client?reload=true&overlay=false",
371+
"webpack-dev-middleware/client?reload=false&overlay=false",
372372
"./src/app.js",
373373
];
374374
```
375375

376376
### Client options
377377

378-
| Name | Type | Default | Description |
379-
| :-----------------: | :-------: | :--------------: | :------------------------------------------------------------------------------------------------------------------ |
380-
| `path` | `string` | `/__webpack_hmr` | Path the SSE endpoint is served at. Must match the server `hot.path`. |
381-
| `timeout` | `number` | `20000` | Reconnection / heartbeat watchdog timeout in milliseconds. |
382-
| `overlay` | `boolean` | `true` | Show compile-time errors in an in-page overlay. |
383-
| `overlayWarnings` | `boolean` | `false` | Also show compile-time warnings in the overlay. |
384-
| `overlayStyles` | `Object` | `{}` | JSON object of CSS overrides for the overlay container. Pass JSON-encoded value via query string. |
385-
| `ansiColors` | `Object` | `{}` | JSON object overriding the ANSI → HTML color map used by the overlay. |
386-
| `reload` | `boolean` | `false` | Reload the page when an update cannot be applied through HMR. |
387-
| `logging` | `string` | `"info"` | Logger level — one of `"none"`, `"error"`, `"warn"`, `"info"`, `"log"`, `"verbose"`. Uses webpack's runtime logger. |
388-
| `name` | `string` | `""` | Restrict updates to a specific compilation name (useful with multi-compiler). |
389-
| `autoConnect` | `boolean` | `true` | Connect on load; set to `false` and call `setOptionsAndConnect()` manually. |
390-
| `dynamicPublicPath` | `boolean` | `false` | Prefix `path` with `__webpack_public_path__` at runtime. |
378+
| Name | Type | Default | Description |
379+
| :-----------------: | :-------: | :--------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
380+
| `path` | `string` | `/__webpack_hmr` | Path the SSE endpoint is served at. Must match the server `hot.path`. |
381+
| `timeout` | `number` | `20000` | Reconnection / heartbeat watchdog timeout in milliseconds. |
382+
| `overlay` | `boolean` | `true` | Show compile-time errors in an in-page overlay. |
383+
| `overlayWarnings` | `boolean` | `false` | Also show compile-time warnings in the overlay. |
384+
| `overlayStyles` | `Object` | `{}` | JSON object of CSS overrides for the overlay container. Pass JSON-encoded value via query string. |
385+
| `ansiColors` | `Object` | `{}` | JSON object overriding the ANSI → HTML color map used by the overlay. |
386+
| `reload` | `boolean` | `true` | Fall back to a full page reload when an update cannot be applied through HMR (e.g. recovering from a broken build). Set to `false` to keep HMR-only. |
387+
| `logging` | `string` | `"info"` | Logger level — one of `"none"`, `"error"`, `"warn"`, `"info"`, `"log"`, `"verbose"`. Uses webpack's runtime logger. |
388+
| `name` | `string` | `""` | Restrict updates to a specific compilation name (useful with multi-compiler). |
389+
| `autoConnect` | `boolean` | `true` | Connect on load; set to `false` and call `setOptionsAndConnect()` manually. |
390+
| `dynamicPublicPath` | `boolean` | `false` | Prefix `path` with `__webpack_public_path__` at runtime. |
391391

392392
### Programmatic API
393393

client-src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const options = {
2727
path: "/__webpack_hmr",
2828
timeout: 20 * 1000,
2929
overlay: true,
30-
reload: false,
30+
reload: true,
3131
logging: "info",
3232
name: "",
3333
autoConnect: true,

test/client.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ describe("client", () => {
128128
expect(processUpdate).toHaveBeenCalledTimes(1);
129129
});
130130

131+
it("passes reload:true to the updater by default", () => {
132+
EventSourceStub.lastInstance().onmessage(
133+
makeMessage({
134+
action: "built",
135+
time: 100,
136+
hash: "1234567890abcdef",
137+
errors: [],
138+
warnings: [],
139+
modules: [],
140+
}),
141+
);
142+
expect(processUpdate).toHaveBeenCalledWith(
143+
"1234567890abcdef",
144+
expect.anything(),
145+
expect.objectContaining({ reload: true }),
146+
);
147+
});
148+
131149
it("triggers webpack on successful syncs", () => {
132150
EventSourceStub.lastInstance().onmessage(
133151
makeMessage({
@@ -483,6 +501,41 @@ describe("client", () => {
483501
});
484502
});
485503

504+
describe("with reload disabled", () => {
505+
let EventSourceStub;
506+
507+
beforeEach(() => {
508+
EventSourceStub = makeEventSourceStub();
509+
globalThis.EventSource = EventSourceStub;
510+
jest.spyOn(console, "info").mockImplementation(() => {});
511+
jest.spyOn(console, "log").mockImplementation(() => {});
512+
jest.spyOn(console, "warn").mockImplementation(() => {});
513+
loadClient("?reload=false");
514+
});
515+
516+
afterEach(() => {
517+
jest.restoreAllMocks();
518+
});
519+
520+
it("passes reload:false to the updater", () => {
521+
EventSourceStub.lastInstance().onmessage(
522+
makeMessage({
523+
action: "built",
524+
time: 100,
525+
hash: "1234567890abcdef",
526+
errors: [],
527+
warnings: [],
528+
modules: [],
529+
}),
530+
);
531+
expect(processUpdate).toHaveBeenCalledWith(
532+
"1234567890abcdef",
533+
expect.anything(),
534+
expect.objectContaining({ reload: false }),
535+
);
536+
});
537+
});
538+
486539
describe("connection lifecycle", () => {
487540
let EventSourceStub;
488541
let client;

0 commit comments

Comments
 (0)