From 3c30cab02d82d702d2fa917d9eb080921e69920b Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 5 Oct 2023 18:53:20 -0400 Subject: [PATCH 01/11] wip - add test --- test/e2e/app-dir/app-edge/app-edge.test.ts | 9 +++++++++ test/e2e/app-dir/app-edge/app/with-client/page.tsx | 13 +++++++++++++ test/e2e/app-dir/app-edge/components/button.tsx | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/e2e/app-dir/app-edge/app/with-client/page.tsx create mode 100644 test/e2e/app-dir/app-edge/components/button.tsx diff --git a/test/e2e/app-dir/app-edge/app-edge.test.ts b/test/e2e/app-dir/app-edge/app-edge.test.ts index 1642e07b3abd..34e8f16f144f 100644 --- a/test/e2e/app-dir/app-edge/app-edge.test.ts +++ b/test/e2e/app-dir/app-edge/app-edge.test.ts @@ -61,6 +61,15 @@ createNextDescribe( ).toBe(false) }) + it('should resolve client component without error', async () => { + const logs = [] + next.on('stderr', (log) => { + logs.push(log) + }) + await next.render('with-client') + expect(logs).toEqual([]) + }) + it('should handle edge rsc hmr', async () => { const pageFile = 'app/edge/basic/page.tsx' const content = await next.readFile(pageFile) diff --git a/test/e2e/app-dir/app-edge/app/with-client/page.tsx b/test/e2e/app-dir/app-edge/app/with-client/page.tsx new file mode 100644 index 000000000000..1a2ee1c21d37 --- /dev/null +++ b/test/e2e/app-dir/app-edge/app/with-client/page.tsx @@ -0,0 +1,13 @@ +import Button from '../../components/button' +import React from 'react' + +export const runtime = 'edge' + +export default function Home() { + return ( + <> +

Import a client component

+ +} From 548e66a83c2271bd611eec3b6f82b49fcd83cdfb Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 5 Oct 2023 19:49:47 -0400 Subject: [PATCH 02/11] remove `ls` since it doesnt work on windows --- .github/actions/next-stats-action/src/index.js | 3 --- .github/actions/next-stats-action/src/prepare/repo-setup.js | 4 ---- 2 files changed, 7 deletions(-) diff --git a/.github/actions/next-stats-action/src/index.js b/.github/actions/next-stats-action/src/index.js index 402c7cfadfcb..f930c07de5a8 100644 --- a/.github/actions/next-stats-action/src/index.js +++ b/.github/actions/next-stats-action/src/index.js @@ -127,9 +127,6 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) { ) .catch(console.error) - console.log(await exec(`ls ${path.join(__dirname, '../native')}`)) - console.log(await exec(`cd ${dir} && ls ${dir}/packages/next-swc/native`)) - logger(`Linking packages in ${dir}`) const isMainRepo = dir === mainRepoDir const pkgPaths = await linkPackages({ diff --git a/.github/actions/next-stats-action/src/prepare/repo-setup.js b/.github/actions/next-stats-action/src/prepare/repo-setup.js index 660a6f4a0b01..6ca9c83d751f 100644 --- a/.github/actions/next-stats-action/src/prepare/repo-setup.js +++ b/.github/actions/next-stats-action/src/prepare/repo-setup.js @@ -104,10 +104,6 @@ module.exports = (actionInfo) => { pkgData.files = [] } pkgData.files.push('native') - require('console').log( - 'using swc binaries: ', - await exec(`ls ${path.join(path.dirname(pkgDataPath), 'native')}`) - ) } if (pkg === 'next') { From f2836797cea31538d433662dd6c566b3df153e56 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 5 Oct 2023 19:51:38 -0400 Subject: [PATCH 03/11] enable azure tests --- azure-pipelines.yml | 146 ++++++++++++++++++++++---------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4c5c09be61c4..322da2b9d00a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -111,76 +111,76 @@ stages: env: NEXT_TEST_MODE: 'dev' - # - job: test_e2e_dev - # pool: - # vmImage: 'windows-2019' - # steps: - # - task: NodeTool@0 - # inputs: - # versionSpec: $(node_16_version) - # displayName: 'Install Node.js' - - # - bash: | - # node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No" - # displayName: 'Check Docs Only Change' - - # - script: corepack enable - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Enable Corepack' - - # - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER) - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: pnpm store path - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: pnpm install && pnpm run build - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Install and build' - - # - script: npx playwright@1.35.1 install chromium - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: | - # node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Run tests (E2E Development)' - # env: - # NEXT_TEST_MODE: 'dev' - - # - job: test_e2e_prod - # pool: - # vmImage: 'windows-2019' - # steps: - # - task: NodeTool@0 - # inputs: - # versionSpec: $(node_16_version) - # displayName: 'Install Node.js' - - # - bash: | - # node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No" - # displayName: 'Check Docs Only Change' - - # - script: corepack enable - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Enable Corepack' - - # - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER) - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: pnpm store path - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: pnpm install && pnpm run build - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Install and build' - - # - script: npx playwright@1.35.1 install chromium - # condition: eq(variables['isDocsOnly'], 'No') - - # - script: | - # node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts - # condition: eq(variables['isDocsOnly'], 'No') - # displayName: 'Run tests (E2E Production)' - # env: - # NEXT_TEST_MODE: 'start' + - job: test_e2e_dev + pool: + vmImage: 'windows-2019' + steps: + - task: NodeTool@0 + inputs: + versionSpec: $(node_16_version) + displayName: 'Install Node.js' + + - bash: | + node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No" + displayName: 'Check Docs Only Change' + + - script: corepack enable + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Enable Corepack' + + - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER) + condition: eq(variables['isDocsOnly'], 'No') + + - script: pnpm store path + condition: eq(variables['isDocsOnly'], 'No') + + - script: pnpm install && pnpm run build + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Install and build' + + - script: npx playwright@1.35.1 install chromium + condition: eq(variables['isDocsOnly'], 'No') + + - script: | + node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Run tests (E2E Development)' + env: + NEXT_TEST_MODE: 'dev' + + - job: test_e2e_prod + pool: + vmImage: 'windows-2019' + steps: + - task: NodeTool@0 + inputs: + versionSpec: $(node_16_version) + displayName: 'Install Node.js' + + - bash: | + node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No" + displayName: 'Check Docs Only Change' + + - script: corepack enable + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Enable Corepack' + + - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER) + condition: eq(variables['isDocsOnly'], 'No') + + - script: pnpm store path + condition: eq(variables['isDocsOnly'], 'No') + + - script: pnpm install && pnpm run build + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Install and build' + + - script: npx playwright@1.35.1 install chromium + condition: eq(variables['isDocsOnly'], 'No') + + - script: | + node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts + condition: eq(variables['isDocsOnly'], 'No') + displayName: 'Run tests (E2E Production)' + env: + NEXT_TEST_MODE: 'start' From 469bb6bb2ee1d540dd65d00001f997c03dcedfe4 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 5 Oct 2023 19:54:17 -0400 Subject: [PATCH 04/11] add onClick to Button --- test/e2e/app-dir/app-edge/components/button.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/app-dir/app-edge/components/button.tsx b/test/e2e/app-dir/app-edge/components/button.tsx index add4b370eb2c..47f034f8e09d 100644 --- a/test/e2e/app-dir/app-edge/components/button.tsx +++ b/test/e2e/app-dir/app-edge/components/button.tsx @@ -4,5 +4,6 @@ import React from 'react' export default function Button() { const router = useRouter() - return + const onClick = () => router.push('/') + return } From ac67abfb8517bd0ee78a8501b35bc3f5aed2aedf Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 08:55:07 -0400 Subject: [PATCH 05/11] adding missing slash --- test/e2e/app-dir/app-edge/app-edge.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/app-dir/app-edge/app-edge.test.ts b/test/e2e/app-dir/app-edge/app-edge.test.ts index 34e8f16f144f..6c201147e080 100644 --- a/test/e2e/app-dir/app-edge/app-edge.test.ts +++ b/test/e2e/app-dir/app-edge/app-edge.test.ts @@ -55,7 +55,7 @@ createNextDescribe( next.on('stderr', (log) => { logs.push(log) }) - await next.render('app-edge') + await next.render('/app-edge') expect( logs.some((log) => log.includes(`Attempted import error:`)) ).toBe(false) From c323d60b8ff547c0facb15099d454eb33ccdac79 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 08:55:59 -0400 Subject: [PATCH 06/11] add `app-edge` tests --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 322da2b9d00a..21603e2d9723 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -142,7 +142,7 @@ stages: condition: eq(variables['isDocsOnly'], 'No') - script: | - node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts + node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts test/e2e/app-dir/app-edge/app-edge.test.ts condition: eq(variables['isDocsOnly'], 'No') displayName: 'Run tests (E2E Development)' env: @@ -179,7 +179,7 @@ stages: condition: eq(variables['isDocsOnly'], 'No') - script: | - node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts + node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts test/e2e/app-dir/app-edge/app-edge.test.ts condition: eq(variables['isDocsOnly'], 'No') displayName: 'Run tests (E2E Production)' env: From 4f30eed521360a96464ef8e327f86dfc0579dc6c Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 15:50:03 -0400 Subject: [PATCH 07/11] add console.log --- packages/next/src/build/webpack-config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index de5d19591b09..5f3150ac9d21 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -90,6 +90,11 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join( 'client' ) +console.log({ + broken: `${NEXT_PROJECT_ROOT}/dist/client/link`, + fixed: require.resolve('next/dist/client/link'), +}) + if (parseInt(React.version) < 18) { throw new Error('Next.js requires react >= 18.2.0 to be installed.') } From c33d2443ff3aba6a1eab32eba1919e658def1b67 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 16:05:06 -0400 Subject: [PATCH 08/11] try with path.join() --- packages/next/src/build/webpack-config.ts | 37 +++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 5f3150ac9d21..fb6625205787 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -93,6 +93,7 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join( console.log({ broken: `${NEXT_PROJECT_ROOT}/dist/client/link`, fixed: require.resolve('next/dist/client/link'), + attempt: path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'link'), }) if (parseInt(React.version) < 18) { @@ -827,27 +828,37 @@ export default async function getBaseWebpackConfig( 'next/dist/server': 'next/dist/esm/server', // Alias the usage of next public APIs - [`${NEXT_PROJECT_ROOT}/server`]: + [path.join(NEXT_PROJECT_ROOT, 'server')]: 'next/dist/esm/server/web/exports/index', - [`${NEXT_PROJECT_ROOT}/dist/client/link`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'link')]: 'next/dist/esm/client/link', - [`${NEXT_PROJECT_ROOT}/dist/shared/lib/image-external`]: - 'next/dist/esm/shared/lib/image-external', - [`${NEXT_PROJECT_ROOT}/dist/client/script`]: + [path.join( + NEXT_PROJECT_ROOT, + 'dist', + 'shared', + 'lib', + 'image-external' + )]: 'next/dist/esm/shared/lib/image-external', + [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'script')]: 'next/dist/esm/client/script', - [`${NEXT_PROJECT_ROOT}/dist/client/router`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'router')]: 'next/dist/esm/client/router', - [`${NEXT_PROJECT_ROOT}/dist/shared/lib/head`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'shared', 'lib', 'head')]: 'next/dist/esm/shared/lib/head', - [`${NEXT_PROJECT_ROOT}/dist/shared/lib/dynamic`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'shared', 'lib', 'dynamic')]: 'next/dist/esm/shared/lib/dynamic', - [`${NEXT_PROJECT_ROOT}/dist/pages/_document`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'pages', '_document')]: 'next/dist/esm/pages/_document', - [`${NEXT_PROJECT_ROOT}/dist/pages/_app`]: + [path.join(NEXT_PROJECT_ROOT, 'dist', 'pages', '_app')]: 'next/dist/esm/pages/_app', - [`${NEXT_PROJECT_ROOT}/dist/client/components/navigation`]: - 'next/dist/esm/client/components/navigation', - [`${NEXT_PROJECT_ROOT}/dist/client/components/headers`]: + [path.join( + NEXT_PROJECT_ROOT, + 'dist', + 'client', + 'components', + 'navigation' + )]: 'next/dist/esm/client/components/navigation', + [path.join(NEXT_PROJECT_ROOT, 'dist', 'components', 'headers')]: 'next/dist/esm/client/components/headers', } : undefined), From 1949a9d93988fb92a9b76a9f6e9cf1785aa7c4ea Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 16:15:26 -0400 Subject: [PATCH 09/11] cleanup --- packages/next/src/build/webpack-config.ts | 6 ------ test/e2e/app-dir/app-edge/app-edge.test.ts | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index fb6625205787..e61692c18637 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -90,12 +90,6 @@ const NEXT_PROJECT_ROOT_DIST_CLIENT = path.join( 'client' ) -console.log({ - broken: `${NEXT_PROJECT_ROOT}/dist/client/link`, - fixed: require.resolve('next/dist/client/link'), - attempt: path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'link'), -}) - if (parseInt(React.version) < 18) { throw new Error('Next.js requires react >= 18.2.0 to be installed.') } diff --git a/test/e2e/app-dir/app-edge/app-edge.test.ts b/test/e2e/app-dir/app-edge/app-edge.test.ts index 6c201147e080..e06e13458c42 100644 --- a/test/e2e/app-dir/app-edge/app-edge.test.ts +++ b/test/e2e/app-dir/app-edge/app-edge.test.ts @@ -66,7 +66,8 @@ createNextDescribe( next.on('stderr', (log) => { logs.push(log) }) - await next.render('with-client') + const html = await next.render('/with-client') + expect(html).toContain('My Button') expect(logs).toEqual([]) }) From 4d6c267973ef8d3f39c0b11b7cec29d01e5e3eab Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 16:53:21 -0400 Subject: [PATCH 10/11] fix typo --- packages/next/src/build/webpack-config.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index e61692c18637..d4cc7be9e538 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -852,8 +852,13 @@ export default async function getBaseWebpackConfig( 'components', 'navigation' )]: 'next/dist/esm/client/components/navigation', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'components', 'headers')]: - 'next/dist/esm/client/components/headers', + [path.join( + NEXT_PROJECT_ROOT, + 'dist', + 'client', + 'components', + 'headers' + )]: 'next/dist/esm/client/components/headers', } : undefined), From 678dc08398f93738d51dc6d6eb6caae6de06a727 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 6 Oct 2023 16:58:25 -0400 Subject: [PATCH 11/11] use NEXT_PROJECT_ROOT_DIST --- packages/next/src/build/webpack-config.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index d4cc7be9e538..b26cd03b8d52 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -824,7 +824,7 @@ export default async function getBaseWebpackConfig( // Alias the usage of next public APIs [path.join(NEXT_PROJECT_ROOT, 'server')]: 'next/dist/esm/server/web/exports/index', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'link')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'link')]: 'next/dist/esm/client/link', [path.join( NEXT_PROJECT_ROOT, @@ -833,28 +833,26 @@ export default async function getBaseWebpackConfig( 'lib', 'image-external' )]: 'next/dist/esm/shared/lib/image-external', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'script')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'script')]: 'next/dist/esm/client/script', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'client', 'router')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'router')]: 'next/dist/esm/client/router', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'shared', 'lib', 'head')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'shared', 'lib', 'head')]: 'next/dist/esm/shared/lib/head', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'shared', 'lib', 'dynamic')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'shared', 'lib', 'dynamic')]: 'next/dist/esm/shared/lib/dynamic', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'pages', '_document')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'pages', '_document')]: 'next/dist/esm/pages/_document', - [path.join(NEXT_PROJECT_ROOT, 'dist', 'pages', '_app')]: + [path.join(NEXT_PROJECT_ROOT_DIST, 'pages', '_app')]: 'next/dist/esm/pages/_app', [path.join( - NEXT_PROJECT_ROOT, - 'dist', + NEXT_PROJECT_ROOT_DIST, 'client', 'components', 'navigation' )]: 'next/dist/esm/client/components/navigation', [path.join( - NEXT_PROJECT_ROOT, - 'dist', + NEXT_PROJECT_ROOT_DIST, 'client', 'components', 'headers'