Skip to content

Commit 8165a95

Browse files
authored
Add option to disable http2 when using https (#562)
1 parent 5aff4c3 commit 8165a95

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

.changeset/blue-spies-destroy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ladle/react": minor
3+
---
4+
5+
Add option to disable http2 when using https. We observed that some bigger Ladle instances throw ERR_HTTP2_PROTOCOL_ERROR errors after upgrading from Node18 to Node20. This setting can be used as a workaround.

packages/ladle/lib/cli/vite-dev.js

+29-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createServer, searchForWorkspaceRoot } from "vite";
22
import koa from "koa";
33
import http from "http";
44
import http2 from "http2";
5+
import https from "https";
56
import c2k from "koa-connect";
67
import path from "path";
78
import getPort from "get-port";
@@ -102,8 +103,8 @@ const bundler = async (config, configFolder) => {
102103
(vite.config.server.host === true
103104
? "0.0.0.0"
104105
: typeof vite.config.server.host === "string"
105-
? vite.config.server.host
106-
: "localhost");
106+
? vite.config.server.host
107+
: "localhost");
107108
const serverUrl = `${useHttps ? "https" : "http"}://${hostname}:${port}${
108109
vite.config.base || ""
109110
}`;
@@ -131,27 +132,33 @@ const bundler = async (config, configFolder) => {
131132
};
132133

133134
if (useHttps) {
134-
http2
135-
.createSecureServer(
136-
{
137-
// Support HMR WS connection
138-
allowHTTP1: true,
139-
maxSessionMemory: 100,
140-
settings: {
141-
// Note: Chromium-based browser will initially allow 100 concurrent streams to be open
142-
// over a single HTTP/2 connection, unless HTTP/2 server advertises a different value,
143-
// in which case it will be capped at maximum of 256 concurrent streams. Hence pushing
144-
// to the limit while in development, in an attempt to maximize the dev performance by
145-
// minimizing the chances of the module requests queuing/stalling on the client-side.
146-
// @see https://source.chromium.org/chromium/chromium/src/+/4c44ff10bcbdb2d113dcc43c72f3f47a84a8dd45:net/spdy/spdy_session.cc;l=477-479
147-
maxConcurrentStreams: 256,
135+
if (config.disableHttp2) {
136+
https
137+
.createServer({ ...vite.config.server.https }, app.callback())
138+
.listen(port, hostname, listenCallback);
139+
} else {
140+
http2
141+
.createSecureServer(
142+
{
143+
// Support HMR WS connection
144+
allowHTTP1: true,
145+
maxSessionMemory: 100,
146+
settings: {
147+
// Note: Chromium-based browser will initially allow 100 concurrent streams to be open
148+
// over a single HTTP/2 connection, unless HTTP/2 server advertises a different value,
149+
// in which case it will be capped at maximum of 256 concurrent streams. Hence pushing
150+
// to the limit while in development, in an attempt to maximize the dev performance by
151+
// minimizing the chances of the module requests queuing/stalling on the client-side.
152+
// @see https://source.chromium.org/chromium/chromium/src/+/4c44ff10bcbdb2d113dcc43c72f3f47a84a8dd45:net/spdy/spdy_session.cc;l=477-479
153+
maxConcurrentStreams: 256,
154+
},
155+
// @ts-ignore
156+
...vite.config.server.https,
148157
},
149-
// @ts-ignore
150-
...vite.config.server.https,
151-
},
152-
app.callback(),
153-
)
154-
.listen(port, hostname, listenCallback);
158+
app.callback(),
159+
)
160+
.listen(port, hostname, listenCallback);
161+
}
155162
} else {
156163
http.createServer(app.callback()).listen(port, hostname, listenCallback);
157164
}

packages/ladle/lib/shared/default-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
storyOrder: (stories) => stories, // default is alphabetical
88
viteConfig: undefined,
99
appendToHead: "",
10+
disableHttp2: false,
1011
noWatch: false,
1112
port: 61000,
1213
previewPort: 8080,

packages/ladle/lib/shared/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export type Config = {
178178
defaultStory: string;
179179
storyOrder: StoryOrder;
180180
appendToHead: string;
181+
disableHttp2: boolean;
181182
viteConfig?: string;
182183
host?: string;
183184
port: number;

0 commit comments

Comments
 (0)