From 61bc6ca3ad36fabea0ae5c5d41383403dbc24979 Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Mon, 30 Oct 2023 09:50:45 -0700 Subject: [PATCH 1/2] fix gsp tracing issue --- packages/next/src/build/collect-build-traces.ts | 2 +- test/e2e/app-dir/app/pages/gsp.js | 15 +++++++++++++++ test/e2e/app-dir/app/standalone.test.ts | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/e2e/app-dir/app/pages/gsp.js diff --git a/packages/next/src/build/collect-build-traces.ts b/packages/next/src/build/collect-build-traces.ts index 4a38017e52f98..9dde7a2952035 100644 --- a/packages/next/src/build/collect-build-traces.ts +++ b/packages/next/src/build/collect-build-traces.ts @@ -266,7 +266,6 @@ export async function collectBuildTraces({ const sharedIgnores = [ '**/next/dist/compiled/next-server/**/*.dev.js', - '**/node_modules/react{,-dom,-dom-server-turbopack}/**/*.development.js', isStandalone ? null : '**/next/dist/compiled/jest-worker/**/*', '**/next/dist/compiled/webpack/(bundle4|bundle5).js', '**/node_modules/webpack5/**/*', @@ -294,6 +293,7 @@ export async function collectBuildTraces({ const serverIgnores = [ ...sharedIgnores, + '**/node_modules/react{,-dom,-dom-server-turbopack}/**/*.development.js', '**/*.d.ts', '**/*.map', '**/next/dist/pages/**/*', diff --git a/test/e2e/app-dir/app/pages/gsp.js b/test/e2e/app-dir/app/pages/gsp.js new file mode 100644 index 0000000000000..28094d7e6be1f --- /dev/null +++ b/test/e2e/app-dir/app/pages/gsp.js @@ -0,0 +1,15 @@ +import useSWR from 'swr' + +console.log(useSWR) + +export default function Home() { + return

Hello

+} + +export async function getStaticProps() { + return { + props: { + foo: 'bar', + }, + } +} diff --git a/test/e2e/app-dir/app/standalone.test.ts b/test/e2e/app-dir/app/standalone.test.ts index b907e06bca184..2f351454baebc 100644 --- a/test/e2e/app-dir/app/standalone.test.ts +++ b/test/e2e/app-dir/app/standalone.test.ts @@ -17,6 +17,9 @@ if (!(globalThis as any).isNextStart) { { files: __dirname, skipStart: true, + dependencies: { + swr: 'latest', + }, }, ({ next }) => { beforeAll(async () => { @@ -90,6 +93,7 @@ if (!(globalThis as any).isNextStart) { '/dashboard/hello', '/dashboard/project/123', '/catch-all/first', + '/gsp', ]) { const res = await fetchViaHTTP(appPort, testPath) expect(res.status).toBe(200) From c76040b31f9ca44546ebae4028f00ca27b68bbfb Mon Sep 17 00:00:00 2001 From: Zack Tanner Date: Mon, 30 Oct 2023 10:11:51 -0700 Subject: [PATCH 2/2] test tweak --- test/e2e/app-dir/app/pages/gsp.js | 15 ---- test/e2e/app-dir/app/standalone-gsp.test.ts | 88 +++++++++++++++++++++ test/e2e/app-dir/app/standalone.test.ts | 4 - 3 files changed, 88 insertions(+), 19 deletions(-) delete mode 100644 test/e2e/app-dir/app/pages/gsp.js create mode 100644 test/e2e/app-dir/app/standalone-gsp.test.ts diff --git a/test/e2e/app-dir/app/pages/gsp.js b/test/e2e/app-dir/app/pages/gsp.js deleted file mode 100644 index 28094d7e6be1f..0000000000000 --- a/test/e2e/app-dir/app/pages/gsp.js +++ /dev/null @@ -1,15 +0,0 @@ -import useSWR from 'swr' - -console.log(useSWR) - -export default function Home() { - return

Hello

-} - -export async function getStaticProps() { - return { - props: { - foo: 'bar', - }, - } -} diff --git a/test/e2e/app-dir/app/standalone-gsp.test.ts b/test/e2e/app-dir/app/standalone-gsp.test.ts new file mode 100644 index 0000000000000..99a281078ac58 --- /dev/null +++ b/test/e2e/app-dir/app/standalone-gsp.test.ts @@ -0,0 +1,88 @@ +import { createNextDescribe } from 'e2e-utils' +import fs from 'fs-extra' +import os from 'os' +import path from 'path' +import { + findPort, + initNextServerScript, + killApp, + fetchViaHTTP, +} from 'next-test-utils' + +if (!(globalThis as any).isNextStart) { + it('should skip for non-next start', () => {}) +} else { + createNextDescribe( + 'output: standalone with getStaticProps', + { + files: __dirname, + skipStart: true, + dependencies: { + swr: 'latest', + }, + }, + ({ next }) => { + beforeAll(async () => { + await next.patchFile( + 'next.config.js', + (await next.readFile('next.config.js')).replace('// output', 'output') + ) + + await next.patchFile( + 'pages/gsp.js', + ` + import useSWR from 'swr' + + console.log(useSWR) + + export default function Home() { + return

Hello

+ } + + export async function getStaticProps() { + return { + props: { + foo: "bar", + }, + }; + } + ` + ) + + await next.start() + }) + + it('should work correctly with output standalone', async () => { + const tmpFolder = path.join( + os.tmpdir(), + 'next-standalone-' + Date.now() + ) + await fs.move(path.join(next.testDir, '.next/standalone'), tmpFolder) + let server: any + + try { + const testServer = path.join(tmpFolder, 'server.js') + const appPort = await findPort() + server = await initNextServerScript( + testServer, + /- Local:/, + { + ...process.env, + PORT: appPort.toString(), + }, + undefined, + { + cwd: tmpFolder, + } + ) + + const res = await fetchViaHTTP(appPort, '/gsp') + expect(res.status).toBe(200) + } finally { + if (server) await killApp(server) + await fs.remove(tmpFolder) + } + }) + } + ) +} diff --git a/test/e2e/app-dir/app/standalone.test.ts b/test/e2e/app-dir/app/standalone.test.ts index 2f351454baebc..b907e06bca184 100644 --- a/test/e2e/app-dir/app/standalone.test.ts +++ b/test/e2e/app-dir/app/standalone.test.ts @@ -17,9 +17,6 @@ if (!(globalThis as any).isNextStart) { { files: __dirname, skipStart: true, - dependencies: { - swr: 'latest', - }, }, ({ next }) => { beforeAll(async () => { @@ -93,7 +90,6 @@ if (!(globalThis as any).isNextStart) { '/dashboard/hello', '/dashboard/project/123', '/catch-all/first', - '/gsp', ]) { const res = await fetchViaHTTP(appPort, testPath) expect(res.status).toBe(200)