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) { ...@@ -65,9 +65,7 @@ export function setHttpClientAndAgentOptions(config: NextConfig) {
) )
} else { } else {
// When appDir is enabled undici is the default because of Response.clone() issues in node-fetch // 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 ;(global as any).__NEXT_USE_UNDICI = config.experimental?.enableUndici
? true
: config.experimental?.enableUndici
} }
} else if (config.experimental?.enableUndici) { } else if (config.experimental?.enableUndici) {
Log.warn( Log.warn(
...@@ -260,6 +258,10 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) { ...@@ -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 !== '') {
if (result.basePath === '/') { if (result.basePath === '/') {
throw new Error( throw new Error(
......
...@@ -99,6 +99,7 @@ import { IncrementalCache } from './lib/incremental-cache' ...@@ -99,6 +99,7 @@ import { IncrementalCache } from './lib/incremental-cache'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import { renderToHTMLOrFlight as appRenderToHTMLOrFlight } from './app-render' import { renderToHTMLOrFlight as appRenderToHTMLOrFlight } from './app-render'
import { setHttpClientAndAgentOptions } from './config'
export * from './base-server' export * from './base-server'
...@@ -260,6 +261,8 @@ export default class NextNodeServer extends BaseServer { ...@@ -260,6 +261,8 @@ export default class NextNodeServer extends BaseServer {
const { AsyncLocalStorage } = require('async_hooks') const { AsyncLocalStorage } = require('async_hooks')
;(global as any).AsyncLocalStorage = AsyncLocalStorage ;(global as any).AsyncLocalStorage = AsyncLocalStorage
} }
// ensure options are set when loadConfig isn't called
setHttpClientAndAgentOptions(this.nextConfig)
} }
private compression = this.nextConfig.compress private compression = this.nextConfig.compress
......
This diff is collapsed.
export default async function Home() { export default async function Home() {
const res = await fetch( 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 resClone = res.clone()
const json = await resClone.json() const json = await resClone.json()
const firstItem = json.arrayOfObjects[0]
return ( return (
<> <>
<h1 id="done">Hello world</h1> <h1 id="done">Hello world</h1>
<p id="index">{firstItem.index}</p> <p>item count {json.data.length}</p>
<p id="random">{firstItem.random}</p>
</> </>
) )
} }
...@@ -4,11 +4,8 @@ import { NextInstance } from 'test/lib/next-modes/base' ...@@ -4,11 +4,8 @@ import { NextInstance } from 'test/lib/next-modes/base'
import { import {
check, check,
fetchViaHTTP, fetchViaHTTP,
findPort,
getRedboxHeader, getRedboxHeader,
hasRedbox, hasRedbox,
initNextServerScript,
killApp,
renderViaHTTP, renderViaHTTP,
waitFor, waitFor,
} from 'next-test-utils' } from 'next-test-utils'
...@@ -19,13 +16,9 @@ import webdriver from 'next-webdriver' ...@@ -19,13 +16,9 @@ import webdriver from 'next-webdriver'
describe('app dir', () => { describe('app dir', () => {
const isDev = (global as any).isNextDev const isDev = (global as any).isNextDev
let next: NextInstance let next: NextInstance
let apiServerPort: number
let apiInstance: any
function runTests() { function runTests() {
beforeAll(async () => { beforeAll(async () => {
apiServerPort = await findPort()
next = await createNext({ next = await createNext({
files: new FileRef(path.join(__dirname, 'app')), files: new FileRef(path.join(__dirname, 'app')),
dependencies: { dependencies: {
...@@ -34,25 +27,10 @@ describe('app dir', () => { ...@@ -34,25 +27,10 @@ describe('app dir', () => {
'react-dom': 'latest', 'react-dom': 'latest',
sass: '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(() => { afterAll(async () => {
next.destroy() await next.destroy()
killApp(apiInstance)
}) })
if (!(global as any).isNextDeploy) { if (!(global as any).isNextDeploy) {
...@@ -292,10 +270,13 @@ describe('app dir', () => { ...@@ -292,10 +270,13 @@ describe('app dir', () => {
) )
}) })
// TODO-APP: fix to ensure behavior matches on deploy
if (!(global as any).isNextDeploy) {
it('should serve page as a segment name correctly', async () => { it('should serve page as a segment name correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/page') const html = await renderViaHTTP(next.url, '/dashboard/page')
expect(html).toContain('hello dashboard/page!') expect(html).toContain('hello dashboard/page!')
}) })
}
it('should include document html and body', async () => { it('should include document html and body', async () => {
const html = await renderViaHTTP(next.url, '/dashboard') const html = await renderViaHTTP(next.url, '/dashboard')
...@@ -2297,21 +2278,13 @@ describe('app dir', () => { ...@@ -2297,21 +2278,13 @@ describe('app dir', () => {
}) })
describe('data fetch with response over 16KB with chunked encoding', () => { 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 () => { it('should load page when fetching a large amount of data', async () => {
const browser = await webdriver(next.url, '/very-large-data-fetch') const browser = await webdriver(next.url, '/very-large-data-fetch')
expect( expect(await (await browser.waitForElementByCss('#done')).text()).toBe(
await (await browser.waitForElementByCss('#done', 5000)).text() 'Hello world'
).toBe('Hello world') )
expect( expect(await browser.elementByCss('p').text()).toBe('item count 128000')
await (await browser.waitForElementByCss('#index', 2000)).text()
).toBe('0')
expect(
await (await browser.waitForElementByCss('#random', 2000)).text()
).toBe('5')
}) })
}
}) })
} }
......
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