Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add edge entries when there are other edge entries #70910

Draft
wants to merge 2 commits into
base: canary
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/next/src/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,15 @@ export async function createEntrypoints(
onEdgeServer: () => {
let appDirLoader: string = ''
if (isInstrumentation) {
edgeServer[serverBundlePath.replace('src/', '')] =
getInstrumentationEntry({
absolutePagePath,
isEdgeServer: true,
isDev: false,
})
// Add instrumentation edge server entry when there's other edge server entries
if (Object.keys(edgeServer).length > 0) {
edgeServer[serverBundlePath.replace('src/', '')] =
getInstrumentationEntry({
absolutePagePath,
isEdgeServer: true,
isDev: false,
})
}
} else {
if (pagesType === 'app') {
const matchedAppPaths = appPathsPerRoute[normalizeAppPath(page)]
Expand Down Expand Up @@ -788,7 +791,8 @@ export async function createEntrypoints(

// Optimization: If there's only one instrumentation hook in edge compiler, which means there's no edge server entry.
// We remove the edge instrumentation entry from edge compiler as it can be pure server side.
if (edgeServer.instrumentation && Object.keys(edgeServer).length === 1) {
const edgeServerEntriesCount = Object.keys(edgeServer).length
if (edgeServer.instrumentation && edgeServerEntriesCount <= 1) {
delete edgeServer.instrumentation
}

Expand Down
25 changes: 14 additions & 11 deletions packages/next/src/server/dev/hot-reloader-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,20 @@ export default class HotReloaderWebpack implements NextJsHotReloaderInterface {

if (isInstrumentation) {
const normalizedBundlePath = bundlePath.replace('src/', '')
entrypoints[normalizedBundlePath] = finalizeEntrypoint({
compilerType: COMPILER_NAMES.edgeServer,
name: normalizedBundlePath,
value: getInstrumentationEntry({
absolutePagePath: entryData.absolutePagePath,
isEdgeServer: true,
isDev: true,
}),
isServerComponent: true,
hasAppDir,
})
// Add instrumentation edge server entry when there's other edge server entries
if (Object.keys(entrypoints).length > 0) {
entrypoints[normalizedBundlePath] = finalizeEntrypoint({
compilerType: COMPILER_NAMES.edgeServer,
name: normalizedBundlePath,
value: getInstrumentationEntry({
absolutePagePath: entryData.absolutePagePath,
isEdgeServer: true,
isDev: true,
}),
isServerComponent: true,
hasAppDir,
})
}
return
}
const appDirLoader = isAppPath
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/on-request-error/isr/isr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ describe('on-request-error - isr', () => {
}

if (isNextDev) {
it('should skip in development mode', () => {
// This ISR test is only applicable for production mode
it('should not have module not found error', async () => {
await next.fetch('/')
expect(next.cliOutput).not.toContain('Module not found')
})
return
}
Expand Down
Loading