Skip to content

Commit

Permalink
Ensure Undici is enabled for appDir in all cases (#42382)
Browse files Browse the repository at this point in the history
Fixes
#41745 (comment)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

Co-authored-by: JJ Kasper <[email protected]>
  • Loading branch information
timneutkens and ijjk authored Nov 3, 2022
1 parent 6e44291 commit 059538b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2,137 deletions.
8 changes: 5 additions & 3 deletions packages/next/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export function setHttpClientAndAgentOptions(config: NextConfig) {
)
} else {
// When appDir is enabled undici is the default because of Response.clone() issues in node-fetch
;(global as any).__NEXT_USE_UNDICI = config.experimental?.appDir
? true
: config.experimental?.enableUndici
;(global as any).__NEXT_USE_UNDICI = config.experimental?.enableUndici
}
} else if (config.experimental?.enableUndici) {
Log.warn(
Expand Down Expand Up @@ -260,6 +258,10 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) {
)
}

if (result.experimental?.appDir) {
result.experimental.enableUndici = true
}

if (result.basePath !== '') {
if (result.basePath === '/') {
throw new Error(
Expand Down
3 changes: 3 additions & 0 deletions packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import { IncrementalCache } from './lib/incremental-cache'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'

import { renderToHTMLOrFlight as appRenderToHTMLOrFlight } from './app-render'
import { setHttpClientAndAgentOptions } from './config'

export * from './base-server'

Expand Down Expand Up @@ -260,6 +261,8 @@ export default class NextNodeServer extends BaseServer {
const { AsyncLocalStorage } = require('async_hooks')
;(global as any).AsyncLocalStorage = AsyncLocalStorage
}
// ensure options are set when loadConfig isn't called
setHttpClientAndAgentOptions(this.nextConfig)
}

private compression = this.nextConfig.compress
Expand Down
Loading

0 comments on commit 059538b

Please sign in to comment.