diff --git a/.changeset/socket-mode-undici-v8.md b/.changeset/socket-mode-undici-v8.md new file mode 100644 index 000000000..38fd6e865 --- /dev/null +++ b/.changeset/socket-mode-undici-v8.md @@ -0,0 +1,7 @@ +--- +"@slack/socket-mode": minor +--- + +Support `undici@^8` as a peer dependency in addition to `undici@^7`. `undici@^8` requires Node.js >=22.19; `undici@^7` continues to support Node.js >=20. + +The default dispatcher now pins the WebSocket connection to HTTP/1.1, since `undici@^8` offers HTTP/2 by default. To do the same with a custom `ProxyAgent` dispatcher, pass `requestTls: { allowH2: false }`. diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index d5afe57af..fb35e3acc 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -23,6 +23,12 @@ jobs: - "22.x" - "24.x" - "26.x" + undici: + - "undici@^7" + - "undici@^8" + exclude: + - node-version: "20.x" + undici: "undici@^8" runs-on: ${{ matrix.os }} permissions: contents: read @@ -45,6 +51,8 @@ jobs: npm --version - name: Install dependencies run: npm ci --verbose + - name: Install undici + run: npm install ${{ matrix.undici }} --workspace=packages/socket-mode --no-save - name: Build packages run: npm run build - name: Lint diff --git a/packages/socket-mode/package.json b/packages/socket-mode/package.json index 4682345e1..f05cc6ebf 100644 --- a/packages/socket-mode/package.json +++ b/packages/socket-mode/package.json @@ -57,7 +57,7 @@ "eventemitter3": "^5" }, "peerDependencies": { - "undici": "^7.0.0" + "undici": "^7.0.0 || ^8.0.0" }, "devDependencies": { "@types/proxyquire": "^1.3.31", diff --git a/packages/socket-mode/src/SlackWebSocket.ts b/packages/socket-mode/src/SlackWebSocket.ts index 4340db39b..62f90ce82 100644 --- a/packages/socket-mode/src/SlackWebSocket.ts +++ b/packages/socket-mode/src/SlackWebSocket.ts @@ -229,7 +229,8 @@ export class SlackWebSocket { * leaving no other way to close a stalled peer. */ private buildDefaultDispatcher(): Dispatcher { - const baseConnect = buildConnector({}); + // undici v8 defaults allowH2 to true; pin HTTP/1.1 so the WebSocket keeps a dedicated socket. + const baseConnect = buildConnector({ allowH2: false }); return new Agent({ connect: (opts, callback) => { baseConnect(opts, (err, socket) => {