Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump undici #55007

Merged
merged 5 commits into from
Sep 5, 2023
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
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"timers-browserify": "2.0.12",
"tty-browserify": "0.0.1",
"ua-parser-js": "1.0.35",
"undici": "5.22.0",
"undici": "5.23.0",
"unistore": "3.4.1",
"util": "0.12.4",
"uuid": "8.3.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/next/src/compiled/undici/index.js

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions packages/next/src/server/node-polyfill-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
// TODO: Remove use of `any` type.
// Polyfill fetch() in the Node.js environment
// TODO: Remove this file when Node.js 16 is not supported anymore

if (typeof fetch === 'undefined' && typeof globalThis.fetch === 'undefined') {
function getFetchImpl() {
return require('next/dist/compiled/undici')
}

function getRequestImpl() {
const OriginRequest = getFetchImpl().Request
return class Request extends OriginRequest {
constructor(input: any, init: any) {
const OriginalRequest = getFetchImpl().Request
return class extends OriginalRequest {
constructor(input: RequestInfo | URL, init: RequestInit) {
super(input, init)
this.next = init?.next
}
}
}

// Due to limitation of global configuration, we have to do this resolution at runtime
globalThis.fetch = (...args: any[]) => {
globalThis.fetch = (...args: Parameters<typeof fetch>) => {
const fetchImpl = getFetchImpl()

// Undici does not support the `keepAlive` option,
// instead we have to pass a custom dispatcher
if (
!(global as any).__NEXT_HTTP_AGENT_OPTIONS?.keepAlive &&
!(global as any).__NEXT_UNDICI_AGENT_SET
!global.__NEXT_HTTP_AGENT_OPTIONS?.keepAlive &&
!global.__NEXT_UNDICI_AGENT_SET
) {
;(global as any).__NEXT_UNDICI_AGENT_SET = true
global.__NEXT_UNDICI_AGENT_SET = true
fetchImpl.setGlobalDispatcher(new fetchImpl.Agent({ pipelining: 0 }))
console.warn(
'Warning - Configuring `keepAlive: false` is deprecated. Use `{ headers: { connection: "close" } }` instead.'
Expand Down
12 changes: 4 additions & 8 deletions packages/next/src/server/setup-http-agent-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NextConfig } from '../../types'
export function setHttpClientAndAgentOptions(config: {
httpAgentOptions?: NextConfig['httpAgentOptions']
}) {
if ((globalThis as any).__NEXT_HTTP_AGENT) {
if (globalThis.__NEXT_HTTP_AGENT) {
// We only need to assign once because we want
// to reuse the same agent for all requests.
return
Expand All @@ -15,11 +15,7 @@ export function setHttpClientAndAgentOptions(config: {
throw new Error('Expected config.httpAgentOptions to be an object')
}

;(globalThis as any).__NEXT_HTTP_AGENT_OPTIONS = config.httpAgentOptions
;(globalThis as any).__NEXT_HTTP_AGENT = new HttpAgent(
config.httpAgentOptions
)
;(globalThis as any).__NEXT_HTTPS_AGENT = new HttpsAgent(
config.httpAgentOptions
)
globalThis.__NEXT_HTTP_AGENT_OPTIONS = config.httpAgentOptions
globalThis.__NEXT_HTTP_AGENT = new HttpAgent(config.httpAgentOptions)
globalThis.__NEXT_HTTPS_AGENT = new HttpsAgent(config.httpAgentOptions)
}
8 changes: 8 additions & 0 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
/// <reference types="react-dom" />
/// <reference types="react-dom/experimental" />

import type { Agent as HttpAgent } from 'http'
import type { Agent as HttpsAgent } from 'https'

import React from 'react'
import { ParsedUrlQuery } from 'querystring'
import { IncomingMessage, ServerResponse } from 'http'
Expand Down Expand Up @@ -314,6 +317,11 @@ declare global {
): T
randomUUID(): string
}

var __NEXT_HTTP_AGENT_OPTIONS: { keepAlive?: boolean } | undefined
var __NEXT_UNDICI_AGENT_SET: boolean
var __NEXT_HTTP_AGENT: HttpAgent
var __NEXT_HTTPS_AGENT: HttpsAgent
}

export default next
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.