diff --git a/.vscode/launch.json b/.vscode/launch.json index e88773d91c2cac1..31757a73457093a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "cwd": "${workspaceFolder}", "runtimeExecutable": "pnpm", - "runtimeArgs": ["debug-react-exp", "dev", "test/e2e/app-dir/app"], + "runtimeArgs": ["debug", "dev", "test/e2e/app-dir/app"], "skipFiles": ["/**"], "env": { "NEXT_PRIVATE_LOCAL_WEBPACK": "1" diff --git a/packages/next/server/config.ts b/packages/next/server/config.ts index 018de2e5432d3bb..c852c647bfe0b9b 100644 --- a/packages/next/server/config.ts +++ b/packages/next/server/config.ts @@ -28,6 +28,11 @@ import { getDependencies } from '../lib/get-package-version' export { DomainLocale, NextConfig, normalizeConfig } from './config-shared' +const NODE_16_VERSION = '16.8.0' +const NODE_18_VERSION = '18.0.0' +const isAboveNodejs16 = semverGte(process.version, NODE_16_VERSION) +const isAboveNodejs18 = semverGte(process.version, NODE_18_VERSION) + const experimentalWarning = execOnce( (configFileName: string, features: string[]) => { const s = features.length > 1 ? 's' : '' @@ -52,21 +57,21 @@ const experimentalWarning = execOnce( } ) -export function setHttpClientAndAgentOptions(options: NextConfig) { - if (semverGte(process.version, '16.8.0')) { - if ( - options.experimental?.enableUndici && - semverGte(process.version, '18.0.0') - ) { +export function setHttpClientAndAgentOptions(config: NextConfig) { + if (isAboveNodejs16) { + if (config.experimental?.enableUndici && isAboveNodejs18) { Log.warn( - '`enableUndici` option is unnecessary in Node.js v18.0.0 or greater.' + `\`enableUndici\` option is unnecessary in Node.js v${NODE_18_VERSION} or greater.` ) } else { - ;(global as any).__NEXT_USE_UNDICI = options.experimental?.enableUndici + // 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 } - } else if (options.experimental?.enableUndici) { + } else if (config.experimental?.enableUndici) { Log.warn( - '`enableUndici` option requires Node.js v16.8.0 or greater. Falling back to `node-fetch`' + `\`enableUndici\` option requires Node.js v${NODE_16_VERSION} or greater. Falling back to \`node-fetch\`` ) } if ((global as any).__NEXT_HTTP_AGENT) { @@ -75,13 +80,13 @@ export function setHttpClientAndAgentOptions(options: NextConfig) { return } - if (!options) { + if (!config) { throw new Error('Expected config.httpAgentOptions to be an object') } - ;(global as any).__NEXT_HTTP_AGENT_OPTIONS = options.httpAgentOptions - ;(global as any).__NEXT_HTTP_AGENT = new HttpAgent(options.httpAgentOptions) - ;(global as any).__NEXT_HTTPS_AGENT = new HttpsAgent(options.httpAgentOptions) + ;(global as any).__NEXT_HTTP_AGENT_OPTIONS = config.httpAgentOptions + ;(global as any).__NEXT_HTTP_AGENT = new HttpAgent(config.httpAgentOptions) + ;(global as any).__NEXT_HTTPS_AGENT = new HttpsAgent(config.httpAgentOptions) } async function setFontLoaderDefaults(config: NextConfigComplete, dir: string) { @@ -154,6 +159,16 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) { for (const featureName of Object.keys( value ) as (keyof ExperimentalConfig)[]) { + const featureValue = value[featureName] + if ( + featureName === 'appDir' && + featureValue === true && + !isAboveNodejs16 + ) { + throw new Error( + `experimental.appDir requires Node v${NODE_16_VERSION} or later.` + ) + } if ( value[featureName] !== defaultConfig.experimental[featureName] ) { @@ -608,8 +623,6 @@ function assignDefaults(dir: string, userConfig: { [key: string]: any }) { result.output = undefined } - // TODO: Change defaultConfig type to NextConfigComplete - // so we don't need "!" here. setHttpClientAndAgentOptions(result || defaultConfig) if (result.i18n) { diff --git a/test/e2e/app-dir/app/api-server.js b/test/e2e/app-dir/app/api-server.js new file mode 100644 index 000000000000000..f256a412a4acff8 --- /dev/null +++ b/test/e2e/app-dir/app/api-server.js @@ -0,0 +1,2087 @@ +function largeData(_req, res) { + res.setHeader('Content-Type', 'application/json; charset=utf-8') + return res.end( + JSON.stringify({ + arrayOfObjects: [ + { + index: '0', + random: '5', + }, + { + index: '1', + 'index start at 5': '6', + }, + { + index: '2', + 'index start at 5': '7', + }, + { + index: '3', + 'index start at 5': '8', + }, + { + index: '4', + 'index start at 5': '9', + }, + { + index: '5', + 'index start at 5': '10', + }, + { + index: '6', + 'index start at 5': '11', + }, + { + index: '7', + 'index start at 5': '12', + }, + { + index: '8', + 'index start at 5': '13', + }, + { + index: '9', + 'index start at 5': '14', + }, + { + index: '10', + 'index start at 5': '15', + }, + { + index: '11', + 'index start at 5': '16', + }, + { + index: '12', + 'index start at 5': '17', + }, + { + index: '13', + 'index start at 5': '18', + }, + { + index: '14', + 'index start at 5': '19', + }, + { + index: '15', + 'index start at 5': '20', + }, + { + index: '16', + 'index start at 5': '21', + }, + { + index: '17', + 'index start at 5': '22', + }, + { + index: '18', + 'index start at 5': '23', + }, + { + index: '19', + 'index start at 5': '24', + }, + { + index: '20', + 'index start at 5': '25', + }, + { + index: '21', + 'index start at 5': '26', + }, + { + index: '22', + 'index start at 5': '27', + }, + { + index: '23', + 'index start at 5': '28', + }, + { + index: '24', + 'index start at 5': '29', + }, + { + index: '25', + 'index start at 5': '30', + }, + { + index: '26', + 'index start at 5': '31', + }, + { + index: '27', + 'index start at 5': '32', + }, + { + index: '28', + 'index start at 5': '33', + }, + { + index: '29', + 'index start at 5': '34', + }, + { + index: '30', + 'index start at 5': '35', + }, + { + index: '31', + 'index start at 5': '36', + }, + { + index: '32', + 'index start at 5': '37', + }, + { + index: '33', + 'index start at 5': '38', + }, + { + index: '34', + 'index start at 5': '39', + }, + { + index: '35', + 'index start at 5': '40', + }, + { + index: '36', + 'index start at 5': '41', + }, + { + index: '37', + 'index start at 5': '42', + }, + { + index: '38', + 'index start at 5': '43', + }, + { + index: '39', + 'index start at 5': '44', + }, + { + index: '40', + 'index start at 5': '45', + }, + { + index: '41', + 'index start at 5': '46', + }, + { + index: '42', + 'index start at 5': '47', + }, + { + index: '43', + 'index start at 5': '48', + }, + { + index: '44', + 'index start at 5': '49', + }, + { + index: '45', + 'index start at 5': '50', + }, + { + index: '46', + 'index start at 5': '51', + }, + { + index: '47', + 'index start at 5': '52', + }, + { + index: '48', + 'index start at 5': '53', + }, + { + index: '49', + 'index start at 5': '54', + }, + { + index: '50', + 'index start at 5': '55', + }, + { + index: '51', + 'index start at 5': '56', + }, + { + index: '52', + 'index start at 5': '57', + }, + { + index: '53', + 'index start at 5': '58', + }, + { + index: '54', + 'index start at 5': '59', + }, + { + index: '55', + 'index start at 5': '60', + }, + { + index: '56', + 'index start at 5': '61', + }, + { + index: '57', + 'index start at 5': '62', + }, + { + index: '58', + 'index start at 5': '63', + }, + { + index: '59', + 'index start at 5': '64', + }, + { + index: '60', + 'index start at 5': '65', + }, + { + index: '61', + 'index start at 5': '66', + }, + { + index: '62', + 'index start at 5': '67', + }, + { + index: '63', + 'index start at 5': '68', + }, + { + index: '64', + 'index start at 5': '69', + }, + { + index: '65', + 'index start at 5': '70', + }, + { + index: '66', + 'index start at 5': '71', + }, + { + index: '67', + 'index start at 5': '72', + }, + { + index: '68', + 'index start at 5': '73', + }, + { + index: '69', + 'index start at 5': '74', + }, + { + index: '70', + 'index start at 5': '75', + }, + { + index: '71', + 'index start at 5': '76', + }, + { + index: '72', + 'index start at 5': '77', + }, + { + index: '73', + 'index start at 5': '78', + }, + { + index: '74', + 'index start at 5': '79', + }, + { + index: '75', + 'index start at 5': '80', + }, + { + index: '76', + 'index start at 5': '81', + }, + { + index: '77', + 'index start at 5': '82', + }, + { + index: '78', + 'index start at 5': '83', + }, + { + index: '79', + 'index start at 5': '84', + }, + { + index: '80', + 'index start at 5': '85', + }, + { + index: '81', + 'index start at 5': '86', + }, + { + index: '82', + 'index start at 5': '87', + }, + { + index: '83', + 'index start at 5': '88', + }, + { + index: '84', + 'index start at 5': '89', + }, + { + index: '85', + 'index start at 5': '90', + }, + { + index: '86', + 'index start at 5': '91', + }, + { + index: '87', + 'index start at 5': '92', + }, + { + index: '88', + 'index start at 5': '93', + }, + { + index: '89', + 'index start at 5': '94', + }, + { + index: '90', + 'index start at 5': '95', + }, + { + index: '91', + 'index start at 5': '96', + }, + { + index: '92', + 'index start at 5': '97', + }, + { + index: '93', + 'index start at 5': '98', + }, + { + index: '94', + 'index start at 5': '99', + }, + { + index: '95', + 'index start at 5': '100', + }, + { + index: '96', + 'index start at 5': '101', + }, + { + index: '97', + 'index start at 5': '102', + }, + { + index: '98', + 'index start at 5': '103', + }, + { + index: '99', + 'index start at 5': '104', + }, + { + index: '100', + 'index start at 5': '105', + }, + { + index: '101', + 'index start at 5': '106', + }, + { + index: '102', + 'index start at 5': '107', + }, + { + index: '103', + 'index start at 5': '108', + }, + { + index: '104', + 'index start at 5': '109', + }, + { + index: '105', + 'index start at 5': '110', + }, + { + index: '106', + 'index start at 5': '111', + }, + { + index: '107', + 'index start at 5': '112', + }, + { + index: '108', + 'index start at 5': '113', + }, + { + index: '109', + 'index start at 5': '114', + }, + { + index: '110', + 'index start at 5': '115', + }, + { + index: '111', + 'index start at 5': '116', + }, + { + index: '112', + 'index start at 5': '117', + }, + { + index: '113', + 'index start at 5': '118', + }, + { + index: '114', + 'index start at 5': '119', + }, + { + index: '115', + 'index start at 5': '120', + }, + { + index: '116', + 'index start at 5': '121', + }, + { + index: '117', + 'index start at 5': '122', + }, + { + index: '118', + 'index start at 5': '123', + }, + { + index: '119', + 'index start at 5': '124', + }, + { + index: '120', + 'index start at 5': '125', + }, + { + index: '121', + 'index start at 5': '126', + }, + { + index: '122', + 'index start at 5': '127', + }, + { + index: '123', + 'index start at 5': '128', + }, + { + index: '124', + 'index start at 5': '129', + }, + { + index: '125', + 'index start at 5': '130', + }, + { + index: '126', + 'index start at 5': '131', + }, + { + index: '127', + 'index start at 5': '132', + }, + { + index: '128', + 'index start at 5': '133', + }, + { + index: '129', + 'index start at 5': '134', + }, + { + index: '130', + 'index start at 5': '135', + }, + { + index: '131', + 'index start at 5': '136', + }, + { + index: '132', + 'index start at 5': '137', + }, + { + index: '133', + 'index start at 5': '138', + }, + { + index: '134', + 'index start at 5': '139', + }, + { + index: '135', + 'index start at 5': '140', + }, + { + index: '136', + 'index start at 5': '141', + }, + { + index: '137', + 'index start at 5': '142', + }, + { + index: '138', + 'index start at 5': '143', + }, + { + index: '139', + 'index start at 5': '144', + }, + { + index: '140', + 'index start at 5': '145', + }, + { + index: '141', + 'index start at 5': '146', + }, + { + index: '142', + 'index start at 5': '147', + }, + { + index: '143', + 'index start at 5': '148', + }, + { + index: '144', + 'index start at 5': '149', + }, + { + index: '145', + 'index start at 5': '150', + }, + { + index: '146', + 'index start at 5': '151', + }, + { + index: '147', + 'index start at 5': '152', + }, + { + index: '148', + 'index start at 5': '153', + }, + { + index: '149', + 'index start at 5': '154', + }, + { + index: '150', + 'index start at 5': '155', + }, + { + index: '151', + 'index start at 5': '156', + }, + { + index: '152', + 'index start at 5': '157', + }, + { + index: '153', + 'index start at 5': '158', + }, + { + index: '154', + 'index start at 5': '159', + }, + { + index: '155', + 'index start at 5': '160', + }, + { + index: '156', + 'index start at 5': '161', + }, + { + index: '157', + 'index start at 5': '162', + }, + { + index: '158', + 'index start at 5': '163', + }, + { + index: '159', + 'index start at 5': '164', + }, + { + index: '160', + 'index start at 5': '165', + }, + { + index: '161', + 'index start at 5': '166', + }, + { + index: '162', + 'index start at 5': '167', + }, + { + index: '163', + 'index start at 5': '168', + }, + { + index: '164', + 'index start at 5': '169', + }, + { + index: '165', + 'index start at 5': '170', + }, + { + index: '166', + 'index start at 5': '171', + }, + { + index: '167', + 'index start at 5': '172', + }, + { + index: '168', + 'index start at 5': '173', + }, + { + index: '169', + 'index start at 5': '174', + }, + { + index: '170', + 'index start at 5': '175', + }, + { + index: '171', + 'index start at 5': '176', + }, + { + index: '172', + 'index start at 5': '177', + }, + { + index: '173', + 'index start at 5': '178', + }, + { + index: '174', + 'index start at 5': '179', + }, + { + index: '175', + 'index start at 5': '180', + }, + { + index: '176', + 'index start at 5': '181', + }, + { + index: '177', + 'index start at 5': '182', + }, + { + index: '178', + 'index start at 5': '183', + }, + { + index: '179', + 'index start at 5': '184', + }, + { + index: '180', + 'index start at 5': '185', + }, + { + index: '181', + 'index start at 5': '186', + }, + { + index: '182', + 'index start at 5': '187', + }, + { + index: '183', + 'index start at 5': '188', + }, + { + index: '184', + 'index start at 5': '189', + }, + { + index: '185', + 'index start at 5': '190', + }, + { + index: '186', + 'index start at 5': '191', + }, + { + index: '187', + 'index start at 5': '192', + }, + { + index: '188', + 'index start at 5': '193', + }, + { + index: '189', + 'index start at 5': '194', + }, + { + index: '190', + 'index start at 5': '195', + }, + { + index: '191', + 'index start at 5': '196', + }, + { + index: '192', + 'index start at 5': '197', + }, + { + index: '193', + 'index start at 5': '198', + }, + { + index: '194', + 'index start at 5': '199', + }, + { + index: '195', + 'index start at 5': '200', + }, + { + index: '196', + 'index start at 5': '201', + }, + { + index: '197', + 'index start at 5': '202', + }, + { + index: '198', + 'index start at 5': '203', + }, + { + index: '199', + 'index start at 5': '204', + }, + { + index: '200', + 'index start at 5': '205', + }, + { + index: '201', + 'index start at 5': '206', + }, + { + index: '202', + 'index start at 5': '207', + }, + { + index: '203', + 'index start at 5': '208', + }, + { + index: '204', + 'index start at 5': '209', + }, + { + index: '205', + 'index start at 5': '210', + }, + { + index: '206', + 'index start at 5': '211', + }, + { + index: '207', + 'index start at 5': '212', + }, + { + index: '208', + 'index start at 5': '213', + }, + { + index: '209', + 'index start at 5': '214', + }, + { + index: '210', + 'index start at 5': '215', + }, + { + index: '211', + 'index start at 5': '216', + }, + { + index: '212', + 'index start at 5': '217', + }, + { + index: '213', + 'index start at 5': '218', + }, + { + index: '214', + 'index start at 5': '219', + }, + { + index: '215', + 'index start at 5': '220', + }, + { + index: '216', + 'index start at 5': '221', + }, + { + index: '217', + 'index start at 5': '222', + }, + { + index: '218', + 'index start at 5': '223', + }, + { + index: '219', + 'index start at 5': '224', + }, + { + index: '220', + 'index start at 5': '225', + }, + { + index: '221', + 'index start at 5': '226', + }, + { + index: '222', + 'index start at 5': '227', + }, + { + index: '223', + 'index start at 5': '228', + }, + { + index: '224', + 'index start at 5': '229', + }, + { + index: '225', + 'index start at 5': '230', + }, + { + index: '226', + 'index start at 5': '231', + }, + { + index: '227', + 'index start at 5': '232', + }, + { + index: '228', + 'index start at 5': '233', + }, + { + index: '229', + 'index start at 5': '234', + }, + { + index: '230', + 'index start at 5': '235', + }, + { + index: '231', + 'index start at 5': '236', + }, + { + index: '232', + 'index start at 5': '237', + }, + { + index: '233', + 'index start at 5': '238', + }, + { + index: '234', + 'index start at 5': '239', + }, + { + index: '235', + 'index start at 5': '240', + }, + { + index: '236', + 'index start at 5': '241', + }, + { + index: '237', + 'index start at 5': '242', + }, + { + index: '238', + 'index start at 5': '243', + }, + { + index: '239', + 'index start at 5': '244', + }, + { + index: '240', + 'index start at 5': '245', + }, + { + index: '241', + 'index start at 5': '246', + }, + { + index: '242', + 'index start at 5': '247', + }, + { + index: '243', + 'index start at 5': '248', + }, + { + index: '244', + 'index start at 5': '249', + }, + { + index: '245', + 'index start at 5': '250', + }, + { + index: '246', + 'index start at 5': '251', + }, + { + index: '247', + 'index start at 5': '252', + }, + { + index: '248', + 'index start at 5': '253', + }, + { + index: '249', + 'index start at 5': '254', + }, + { + index: '250', + 'index start at 5': '255', + }, + { + index: '251', + 'index start at 5': '256', + }, + { + index: '252', + 'index start at 5': '257', + }, + { + index: '253', + 'index start at 5': '258', + }, + { + index: '254', + 'index start at 5': '259', + }, + { + index: '255', + 'index start at 5': '260', + }, + { + index: '256', + 'index start at 5': '261', + }, + { + index: '257', + 'index start at 5': '262', + }, + { + index: '258', + 'index start at 5': '263', + }, + { + index: '259', + 'index start at 5': '264', + }, + { + index: '260', + 'index start at 5': '265', + }, + { + index: '261', + 'index start at 5': '266', + }, + { + index: '262', + 'index start at 5': '267', + }, + { + index: '263', + 'index start at 5': '268', + }, + { + index: '264', + 'index start at 5': '269', + }, + { + index: '265', + 'index start at 5': '270', + }, + { + index: '266', + 'index start at 5': '271', + }, + { + index: '267', + 'index start at 5': '272', + }, + { + index: '268', + 'index start at 5': '273', + }, + { + index: '269', + 'index start at 5': '274', + }, + { + index: '270', + 'index start at 5': '275', + }, + { + index: '271', + 'index start at 5': '276', + }, + { + index: '272', + 'index start at 5': '277', + }, + { + index: '273', + 'index start at 5': '278', + }, + { + index: '274', + 'index start at 5': '279', + }, + { + index: '275', + 'index start at 5': '280', + }, + { + index: '276', + 'index start at 5': '281', + }, + { + index: '277', + 'index start at 5': '282', + }, + { + index: '278', + 'index start at 5': '283', + }, + { + index: '279', + 'index start at 5': '284', + }, + { + index: '280', + 'index start at 5': '285', + }, + { + index: '281', + 'index start at 5': '286', + }, + { + index: '282', + 'index start at 5': '287', + }, + { + index: '283', + 'index start at 5': '288', + }, + { + index: '284', + 'index start at 5': '289', + }, + { + index: '285', + 'index start at 5': '290', + }, + { + index: '286', + 'index start at 5': '291', + }, + { + index: '287', + 'index start at 5': '292', + }, + { + index: '288', + 'index start at 5': '293', + }, + { + index: '289', + 'index start at 5': '294', + }, + { + index: '290', + 'index start at 5': '295', + }, + { + index: '291', + 'index start at 5': '296', + }, + { + index: '292', + 'index start at 5': '297', + }, + { + index: '293', + 'index start at 5': '298', + }, + { + index: '294', + 'index start at 5': '299', + }, + { + index: '295', + 'index start at 5': '300', + }, + { + index: '296', + 'index start at 5': '301', + }, + { + index: '297', + 'index start at 5': '302', + }, + { + index: '298', + 'index start at 5': '303', + }, + { + index: '299', + 'index start at 5': '304', + }, + { + index: '300', + 'index start at 5': '305', + }, + { + index: '301', + 'index start at 5': '306', + }, + { + index: '302', + 'index start at 5': '307', + }, + { + index: '303', + 'index start at 5': '308', + }, + { + index: '304', + 'index start at 5': '309', + }, + { + index: '305', + 'index start at 5': '310', + }, + { + index: '306', + 'index start at 5': '311', + }, + { + index: '307', + 'index start at 5': '312', + }, + { + index: '308', + 'index start at 5': '313', + }, + { + index: '309', + 'index start at 5': '314', + }, + { + index: '310', + 'index start at 5': '315', + }, + { + index: '311', + 'index start at 5': '316', + }, + { + index: '312', + 'index start at 5': '317', + }, + { + index: '313', + 'index start at 5': '318', + }, + { + index: '314', + 'index start at 5': '319', + }, + { + index: '315', + 'index start at 5': '320', + }, + { + index: '316', + 'index start at 5': '321', + }, + { + index: '317', + 'index start at 5': '322', + }, + { + index: '318', + 'index start at 5': '323', + }, + { + index: '319', + 'index start at 5': '324', + }, + { + index: '320', + 'index start at 5': '325', + }, + { + index: '321', + 'index start at 5': '326', + }, + { + index: '322', + 'index start at 5': '327', + }, + { + index: '323', + 'index start at 5': '328', + }, + { + index: '324', + 'index start at 5': '329', + }, + { + index: '325', + 'index start at 5': '330', + }, + { + index: '326', + 'index start at 5': '331', + }, + { + index: '327', + 'index start at 5': '332', + }, + { + index: '328', + 'index start at 5': '333', + }, + { + index: '329', + 'index start at 5': '334', + }, + { + index: '330', + 'index start at 5': '335', + }, + { + index: '331', + 'index start at 5': '336', + }, + { + index: '332', + 'index start at 5': '337', + }, + { + index: '333', + 'index start at 5': '338', + }, + { + index: '334', + 'index start at 5': '339', + }, + { + index: '335', + 'index start at 5': '340', + }, + { + index: '336', + 'index start at 5': '341', + }, + { + index: '337', + 'index start at 5': '342', + }, + { + index: '338', + 'index start at 5': '343', + }, + { + index: '339', + 'index start at 5': '344', + }, + { + index: '340', + 'index start at 5': '345', + }, + { + index: '341', + 'index start at 5': '346', + }, + { + index: '342', + 'index start at 5': '347', + }, + { + index: '343', + 'index start at 5': '348', + }, + { + index: '344', + 'index start at 5': '349', + }, + { + index: '345', + 'index start at 5': '350', + }, + { + index: '346', + 'index start at 5': '351', + }, + { + index: '347', + 'index start at 5': '352', + }, + { + index: '348', + 'index start at 5': '353', + }, + { + index: '349', + 'index start at 5': '354', + }, + { + index: '294', + 'index start at 5': '299', + }, + { + index: '295', + 'index start at 5': '300', + }, + { + index: '296', + 'index start at 5': '301', + }, + { + index: '297', + 'index start at 5': '302', + }, + { + index: '298', + 'index start at 5': '303', + }, + { + index: '299', + 'index start at 5': '304', + }, + { + index: '300', + 'index start at 5': '305', + }, + { + index: '301', + 'index start at 5': '306', + }, + { + index: '302', + 'index start at 5': '307', + }, + { + index: '303', + 'index start at 5': '308', + }, + { + index: '304', + 'index start at 5': '309', + }, + { + index: '305', + 'index start at 5': '310', + }, + { + index: '306', + 'index start at 5': '311', + }, + { + index: '307', + 'index start at 5': '312', + }, + { + index: '308', + 'index start at 5': '313', + }, + { + index: '309', + 'index start at 5': '314', + }, + { + index: '310', + 'index start at 5': '315', + }, + { + index: '311', + 'index start at 5': '316', + }, + { + index: '312', + 'index start at 5': '317', + }, + { + index: '313', + 'index start at 5': '318', + }, + { + index: '314', + 'index start at 5': '319', + }, + { + index: '315', + 'index start at 5': '320', + }, + { + index: '316', + 'index start at 5': '321', + }, + { + index: '317', + 'index start at 5': '322', + }, + { + index: '318', + 'index start at 5': '323', + }, + { + index: '319', + 'index start at 5': '324', + }, + { + index: '320', + 'index start at 5': '325', + }, + { + index: '321', + 'index start at 5': '326', + }, + { + index: '322', + 'index start at 5': '327', + }, + { + index: '323', + 'index start at 5': '328', + }, + { + index: '324', + 'index start at 5': '329', + }, + { + index: '325', + 'index start at 5': '330', + }, + { + index: '326', + 'index start at 5': '331', + }, + { + index: '327', + 'index start at 5': '332', + }, + { + index: '328', + 'index start at 5': '333', + }, + { + index: '329', + 'index start at 5': '334', + }, + { + index: '330', + 'index start at 5': '335', + }, + { + index: '331', + 'index start at 5': '336', + }, + { + index: '332', + 'index start at 5': '337', + }, + { + index: '333', + 'index start at 5': '338', + }, + { + index: '334', + 'index start at 5': '339', + }, + { + index: '335', + 'index start at 5': '340', + }, + { + index: '336', + 'index start at 5': '341', + }, + { + index: '337', + 'index start at 5': '342', + }, + { + index: '338', + 'index start at 5': '343', + }, + { + index: '339', + 'index start at 5': '344', + }, + { + index: '340', + 'index start at 5': '345', + }, + { + index: '341', + 'index start at 5': '346', + }, + { + index: '342', + 'index start at 5': '347', + }, + { + index: '343', + 'index start at 5': '348', + }, + { + index: '344', + 'index start at 5': '349', + }, + { + index: '345', + 'index start at 5': '350', + }, + { + index: '346', + 'index start at 5': '351', + }, + { + index: '347', + 'index start at 5': '352', + }, + { + index: '348', + 'index start at 5': '353', + }, + { + index: '349', + 'index start at 5': '354', + }, + { + index: '294', + 'index start at 5': '299', + }, + { + index: '295', + 'index start at 5': '300', + }, + { + index: '296', + 'index start at 5': '301', + }, + { + index: '297', + 'index start at 5': '302', + }, + { + index: '298', + 'index start at 5': '303', + }, + { + index: '299', + 'index start at 5': '304', + }, + { + index: '300', + 'index start at 5': '305', + }, + { + index: '301', + 'index start at 5': '306', + }, + { + index: '302', + 'index start at 5': '307', + }, + { + index: '303', + 'index start at 5': '308', + }, + { + index: '304', + 'index start at 5': '309', + }, + { + index: '305', + 'index start at 5': '310', + }, + { + index: '306', + 'index start at 5': '311', + }, + { + index: '307', + 'index start at 5': '312', + }, + { + index: '308', + 'index start at 5': '313', + }, + { + index: '309', + 'index start at 5': '314', + }, + { + index: '310', + 'index start at 5': '315', + }, + { + index: '311', + 'index start at 5': '316', + }, + { + index: '312', + 'index start at 5': '317', + }, + { + index: '313', + 'index start at 5': '318', + }, + { + index: '314', + 'index start at 5': '319', + }, + { + index: '315', + 'index start at 5': '320', + }, + { + index: '316', + 'index start at 5': '321', + }, + { + index: '317', + 'index start at 5': '322', + }, + { + index: '318', + 'index start at 5': '323', + }, + { + index: '319', + 'index start at 5': '324', + }, + { + index: '320', + 'index start at 5': '325', + }, + { + index: '321', + 'index start at 5': '326', + }, + { + index: '322', + 'index start at 5': '327', + }, + { + index: '323', + 'index start at 5': '328', + }, + { + index: '324', + 'index start at 5': '329', + }, + { + index: '325', + 'index start at 5': '330', + }, + { + index: '326', + 'index start at 5': '331', + }, + { + index: '327', + 'index start at 5': '332', + }, + { + index: '328', + 'index start at 5': '333', + }, + { + index: '329', + 'index start at 5': '334', + }, + { + index: '330', + 'index start at 5': '335', + }, + { + index: '331', + 'index start at 5': '336', + }, + { + index: '332', + 'index start at 5': '337', + }, + { + index: '333', + 'index start at 5': '338', + }, + { + index: '334', + 'index start at 5': '339', + }, + { + index: '335', + 'index start at 5': '340', + }, + { + index: '336', + 'index start at 5': '341', + }, + { + index: '337', + 'index start at 5': '342', + }, + { + index: '338', + 'index start at 5': '343', + }, + { + index: '339', + 'index start at 5': '344', + }, + { + index: '340', + 'index start at 5': '345', + }, + { + index: '341', + 'index start at 5': '346', + }, + { + index: '342', + 'index start at 5': '347', + }, + { + index: '343', + 'index start at 5': '348', + }, + { + index: '344', + 'index start at 5': '349', + }, + { + index: '345', + 'index start at 5': '350', + }, + { + index: '346', + 'index start at 5': '351', + }, + { + index: '347', + 'index start at 5': '352', + }, + { + index: '348', + 'index start at 5': '353', + }, + { + index: '349', + 'index start at 5': '354', + }, + { + index: '294', + 'index start at 5': '299', + }, + { + index: '295', + 'index start at 5': '300', + }, + { + index: '296', + 'index start at 5': '301', + }, + { + index: '297', + 'index start at 5': '302', + }, + { + index: '298', + 'index start at 5': '303', + }, + { + index: '299', + 'index start at 5': '304', + }, + { + index: '300', + 'index start at 5': '305', + }, + { + index: '301', + 'index start at 5': '306', + }, + { + index: '302', + 'index start at 5': '307', + }, + { + index: '303', + 'index start at 5': '308', + }, + { + index: '304', + 'index start at 5': '309', + }, + { + index: '305', + 'index start at 5': '310', + }, + { + index: '306', + 'index start at 5': '311', + }, + { + index: '307', + 'index start at 5': '312', + }, + { + index: '308', + 'index start at 5': '313', + }, + { + index: '309', + 'index start at 5': '314', + }, + { + index: '310', + 'index start at 5': '315', + }, + { + index: '311', + 'index start at 5': '316', + }, + { + index: '312', + 'index start at 5': '317', + }, + { + index: '313', + 'index start at 5': '318', + }, + { + index: '314', + 'index start at 5': '319', + }, + { + index: '315', + 'index start at 5': '320', + }, + { + index: '316', + 'index start at 5': '321', + }, + { + index: '317', + 'index start at 5': '322', + }, + { + index: '318', + 'index start at 5': '323', + }, + { + index: '319', + 'index start at 5': '324', + }, + { + index: '320', + 'index start at 5': '325', + }, + { + index: '321', + 'index start at 5': '326', + }, + { + index: '322', + 'index start at 5': '327', + }, + { + index: '323', + 'index start at 5': '328', + }, + { + index: '324', + 'index start at 5': '329', + }, + { + index: '325', + 'index start at 5': '330', + }, + { + index: '326', + 'index start at 5': '331', + }, + { + index: '327', + 'index start at 5': '332', + }, + { + index: '328', + 'index start at 5': '333', + }, + { + index: '329', + 'index start at 5': '334', + }, + { + index: '330', + 'index start at 5': '335', + }, + { + index: '331', + 'index start at 5': '336', + }, + { + index: '332', + 'index start at 5': '337', + }, + { + index: '333', + 'index start at 5': '338', + }, + { + index: '334', + 'index start at 5': '339', + }, + { + index: '335', + 'index start at 5': '340', + }, + { + index: '336', + 'index start at 5': '341', + }, + { + index: '337', + 'index start at 5': '342', + }, + { + index: '338', + 'index start at 5': '343', + }, + { + index: '339', + 'index start at 5': '344', + }, + { + index: '340', + 'index start at 5': '345', + }, + { + index: '341', + 'index start at 5': '346', + }, + { + index: '342', + 'index start at 5': '347', + }, + { + index: '343', + 'index start at 5': '348', + }, + { + index: '344', + 'index start at 5': '349', + }, + { + index: '345', + 'index start at 5': '350', + }, + { + index: '346', + 'index start at 5': '351', + }, + { + index: '347', + 'index start at 5': '352', + }, + { + index: '348', + 'index start at 5': '353', + }, + { + index: '349', + 'index start at 5': '354', + }, + ], + }) + ) +} + +const server = require('http').Server(largeData) + +server.listen(process.env.PORT || 3000, () => { + console.log('Listening on port 3000') +}) diff --git a/test/e2e/app-dir/app/app/very-large-data-fetch/page.js b/test/e2e/app-dir/app/app/very-large-data-fetch/page.js new file mode 100644 index 000000000000000..8bd01d09ef96f26 --- /dev/null +++ b/test/e2e/app-dir/app/app/very-large-data-fetch/page.js @@ -0,0 +1,16 @@ +export default async function Home() { + const res = await fetch( + `http://localhost:${process.env.API_SERVER_PORT || 3000}/api/large-data` + ) + const resClone = res.clone() + const json = await resClone.json() + const firstItem = json.arrayOfObjects[0] + + return ( + <> +

Hello world

+

{firstItem.index}

+

{firstItem.random}

+ + ) +} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index e1b7f007342f48a..820f718d01e0e9d 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -4,8 +4,11 @@ import { NextInstance } from 'test/lib/next-modes/base' import { check, fetchViaHTTP, + findPort, getRedboxHeader, hasRedbox, + initNextServerScript, + killApp, renderViaHTTP, waitFor, } from 'next-test-utils' @@ -16,9 +19,13 @@ 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: { @@ -27,12 +34,26 @@ 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()) + afterAll(() => { + next.destroy() + killApp(apiInstance) + }) if (!(global as any).isNextDeploy) { it('should not share edge workers', async () => { @@ -2198,6 +2219,21 @@ describe('app dir', () => { ) }) }) + + describe('data fetch with response over 16KB with chunked encoding', () => { + 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') + }) + }) } runTests()