Skip to content

Commit f4610c3

Browse files
DuCanhGHijjk
andauthored
Fix outputting un-necessary trace files for edge functions (vercel#43304)
<!-- 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 - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) 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`](https://github.com/vercel/next.js/blob/canary/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) fixes vercel#39275 and related issues like vercel#39858 and hopefully vercel#41395 (can't test because `pnpm next-with-deps build ./dev-app` keeps crashing on `Collecting page data...` - `useContext` seems to be null, and even without the changes it still crashes). This works by checking if the file is an edge function in Next.js's Webpack plugin `TraceEntryPointsPlugin`, if true then output the nft file to the output path, if not move up a folder like previously. I tried changing Webpack config's output.path from `path: !dev && isNodeServer ? path.join(outputPath, 'chunks') : outputPath` to `path: !dev && (isNodeServer || isEdgeServer) ? path.join(outputPath, 'chunks') : outputPath`, but it just causes the build script to crash because files like middleware-manifest.json are output to outputPath/chunks instead of the expected outputPath. So I find this to be the better solution. Co-authored-by: JJ Kasper <[email protected]>
1 parent 2eaa3ae commit f4610c3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/next/build/webpack-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ export default async function getBaseWebpackConfig(
20022002
}),
20032003
(isClient || isEdgeServer) && new DropClientPage(),
20042004
config.outputFileTracing &&
2005-
(isNodeServer || isEdgeServer) &&
2005+
isNodeServer &&
20062006
!dev &&
20072007
new (require('./webpack/plugins/next-trace-entrypoints-plugin')
20082008
.TraceEntryPointsPlugin as typeof import('./webpack/plugins/next-trace-entrypoints-plugin').TraceEntryPointsPlugin)(

test/e2e/edge-render-getserversideprops/index.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { fetchViaHTTP, normalizeRegEx, renderViaHTTP } from 'next-test-utils'
44
import cheerio from 'cheerio'
55
import { join } from 'path'
66
import escapeStringRegexp from 'escape-string-regexp'
7+
import fs from 'fs-extra'
78

89
describe('edge-render-getserversideprops', () => {
910
let next: NextInstance
@@ -16,6 +17,28 @@ describe('edge-render-getserversideprops', () => {
1617
})
1718
afterAll(() => next.destroy())
1819

20+
if ((global as any).isNextStart) {
21+
it('should not output trace files for edge routes', async () => {
22+
expect(await fs.pathExists(join(next.testDir, '.next/pages'))).toBe(false)
23+
expect(
24+
await fs.pathExists(join(next.testDir, '.next/server/pages/[id].js'))
25+
).toBe(true)
26+
expect(
27+
await fs.pathExists(
28+
join(next.testDir, '.next/server/pages/[id].js.nft.json')
29+
)
30+
).toBe(false)
31+
expect(
32+
await fs.pathExists(join(next.testDir, '.next/server/pages/index.js'))
33+
).toBe(true)
34+
expect(
35+
await fs.pathExists(
36+
join(next.testDir, '.next/server/pages/index.js.nft.json')
37+
)
38+
).toBe(false)
39+
})
40+
}
41+
1942
it('should have correct query/params on index', async () => {
2043
const html = await renderViaHTTP(next.url, '/')
2144
const $ = cheerio.load(html)

0 commit comments

Comments
 (0)