Unverified Commit 059538bc authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure Undici is enabled for appDir in all cases (#42382)

Fixes
https://github.com/vercel/next.js/discussions/41745#discussioncomment-4040309

<!--
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: 's avatarJJ Kasper <jj@jjsweb.site>
parent 6e442911
......@@ -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(
......@@ -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(
......
......@@ -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'
......@@ -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
......
This diff is collapsed.
export default async function Home() {
const res = await fetch(
`http://localhost:${process.env.API_SERVER_PORT || 3000}/api/large-data`
`https://data-api-endpoint-nmw78dd69-ijjk-testing.vercel.app/api/data?amount=128000`
)
const resClone = res.clone()
const json = await resClone.json()
const firstItem = json.arrayOfObjects[0]
return (
<>
<h1 id="done">Hello world</h1>
<p id="index">{firstItem.index}</p>
<p id="random">{firstItem.random}</p>
<p>item count {json.data.length}</p>
</>
)
}
......@@ -4,11 +4,8 @@ import { NextInstance } from 'test/lib/next-modes/base'
import {
check,
fetchViaHTTP,
findPort,
getRedboxHeader,
hasRedbox,
initNextServerScript,
killApp,
renderViaHTTP,
waitFor,
} from 'next-test-utils'
......@@ -19,13 +16,9 @@ import webdriver from 'next-webdriver'
describe('app dir', () => {
const isDev = (global as any).isNextDev
let next: NextInstance
let apiServerPort: number
let apiInstance: any
function runTests() {
beforeAll(async () => {
apiServerPort = await findPort()
next = await createNext({
files: new FileRef(path.join(__dirname, 'app')),
dependencies: {
......@@ -34,25 +27,10 @@ describe('app dir', () => {
'react-dom': 'latest',
sass: 'latest',
},
env: {
API_SERVER_PORT: apiServerPort.toString(),
},
skipStart: true,
})
apiInstance = await initNextServerScript(
path.join(__dirname, 'app', 'api-server.js'),
/Listening on/,
{ ...process.env, PORT: apiServerPort },
undefined,
{ cwd: next.testDir }
)
await next.start()
})
afterAll(() => {
next.destroy()
killApp(apiInstance)
afterAll(async () => {
await next.destroy()
})
if (!(global as any).isNextDeploy) {
......@@ -292,10 +270,13 @@ describe('app dir', () => {
)
})
it('should serve page as a segment name correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/page')
expect(html).toContain('hello dashboard/page!')
})
// TODO-APP: fix to ensure behavior matches on deploy
if (!(global as any).isNextDeploy) {
it('should serve page as a segment name correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/page')
expect(html).toContain('hello dashboard/page!')
})
}
it('should include document html and body', async () => {
const html = await renderViaHTTP(next.url, '/dashboard')
......@@ -2297,21 +2278,13 @@ describe('app dir', () => {
})
describe('data fetch with response over 16KB with chunked encoding', () => {
// TODO-APP: increase timeouts for testing against deploy?
if (!(global as any).isNextDeploy) {
it('should load page when fetching a large amount of data', async () => {
const browser = await webdriver(next.url, '/very-large-data-fetch')
expect(
await (await browser.waitForElementByCss('#done', 5000)).text()
).toBe('Hello world')
expect(
await (await browser.waitForElementByCss('#index', 2000)).text()
).toBe('0')
expect(
await (await browser.waitForElementByCss('#random', 2000)).text()
).toBe('5')
})
}
it('should load page when fetching a large amount of data', async () => {
const browser = await webdriver(next.url, '/very-large-data-fetch')
expect(await (await browser.waitForElementByCss('#done')).text()).toBe(
'Hello world'
)
expect(await browser.elementByCss('p').text()).toBe('item count 128000')
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment