Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/autoconnect-query-parsing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-dev-middleware": patch
---

Fixed `autoConnect` on the client's query being read differently from every other boolean there. It tested `=== "true"` while the rest test `!== "false"`, so a value it did not recognise — `?autoConnect=1` — turned the client off rather than leaving it on, and since the default is already on, turning it off is the only thing anyone writes it for.
5 changes: 4 additions & 1 deletion client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ function turnedOffByUrl(setting) {
*/
function setOverrides(overrides) {
if (overrides.autoConnect) {
options.autoConnect = overrides.autoConnect === "true";
// `!== "false"` like every other boolean here, not `=== "true"`: the
// default is already on, so the only thing anyone writes this for is
// turning it off, and `?autoConnect=1` used to do that by accident.
options.autoConnect = overrides.autoConnect !== "false";
}
if (overrides.transport === "sse" || overrides.transport === "ws") {
options.transport = overrides.transport;
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,46 @@ describe("hot client (browser)", () => {
expect(await readReloadMarker(page)).toBeUndefined();
});

// Every boolean on the query turns off on `false` and is left alone by
// anything else. `autoConnect` read `=== "true"` instead, so a value it did
// not recognise turned it off — and since the default is on, turning it off
// is the only thing anyone writes it for.
it("stays connected for an autoConnect value that is not `false`", async () => {
app = await createHotApp({
query: "?autoConnect=1",
code: acceptedApp("v1"),
});
({ page, browser } = await runBrowser());
const console_ = collectConsole(page);

await page.goto(app.url);
await waitForAppText(page, "v1");
await console_.waitFor("connected");

// Connected, so a build reaches the page.
app.edit(acceptedApp("v2"));
await waitForAppText(page, "v2");

expect(
await page.evaluate(() => document.getElementById("app").textContent),
).toBe("v2");
expect(console_.messages.join("\n")).toContain("connected");
});

it("does not connect when autoConnect is `false`", async () => {
app = await createHotApp({
query: "?autoConnect=false",
code: acceptedApp("v1"),
});
({ page, browser } = await runBrowser());
const console_ = collectConsole(page);

await page.goto(app.url);
await waitForAppText(page, "v1");

expect(console_.messages.join("\n")).not.toContain("connected");
});

it("warns instead of reloading when reload=false", async () => {
app = await createHotApp({
query: "?reload=false",
Expand Down
Loading