Skip to content

Add response handling in pages handler #80189

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

Draft
wants to merge 1 commit 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
7 changes: 4 additions & 3 deletions packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@
"692": "Expected clientReferenceManifest to be defined.",
"693": "%s must not be used within a client component. Next.js should be preventing %s from being included in client components statically, but did not in this case.",
"694": "createPrerenderPathname was called inside a client component scope.",
"695": "Expected workUnitAsyncStorage to have a store.",
"696": "Next DevTools: Can't dispatch %s in this environment. This is a bug in Next.js",
"697": "Next DevTools: Can't render in this environment. This is a bug in Next.js"
"695": "Invariant: received non-pages cache entry in pages handler",
"696": "Expected workUnitAsyncStorage to have a store.",
"697": "Next DevTools: Can't render in this environment. This is a bug in Next.js",
"698": "Next DevTools: Can't dispatch %s in this environment. This is a bug in Next.js"
}
29 changes: 6 additions & 23 deletions packages/next/src/build/templates/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ import { createServerModuleMap } from '../../server/app-render/action-utils'
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
import { getIsPossibleServerAction } from '../../server/lib/server-action-request-meta'
import {
RouterServerContextSymbol,
routerServerGlobal,
} from '../../server/lib/router-utils/router-server-context'
import {
NEXT_ROUTER_PREFETCH_HEADER,
RSC_HEADER,
NEXT_ROUTER_PREFETCH_HEADER,
} from '../../client/components/app-router-headers'

// These are injected by the loader afterwards.
Expand Down Expand Up @@ -132,21 +128,17 @@ export async function handler(
pageIsDynamic,
buildManifest,
nextFontManifest,
serverFilesManifest,
reactLoadableManifest,
serverActionsManifest,
clientReferenceManifest,
subresourceIntegrityManifest,
prerenderManifest,
isDraftMode,
isOnDemandRevalidate,
routerServerContext,
nextConfig,
} = prepareResult

const routerServerContext =
routerServerGlobal[RouterServerContextSymbol]?.[
process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
]

const onInstrumentationRequestError =
routeModule.instrumentationOnRequestError.bind(routeModule)

Expand All @@ -172,9 +164,6 @@ export async function handler(
)
}

const nextConfig =
routerServerContext?.nextConfig || serverFilesManifest.config

const pathname = parsedUrl.pathname || '/'
const normalizedSrcPage = normalizeAppPath(srcPage)
let isIsr = Boolean(
Expand Down Expand Up @@ -311,11 +300,7 @@ export async function handler(
isRevalidate ||
// Otherwise we're checking the user agent to decide if we should
// serve streaming metadata.
shouldServeStreamingMetadata(
userAgent,
// @ts-expect-error update for readonly
nextConfig.htmlLimitedBots
)
shouldServeStreamingMetadata(userAgent, nextConfig.htmlLimitedBots)

if (isHtmlBot && isRoutePPREnabled) {
isIsr = false
Expand Down Expand Up @@ -360,22 +345,21 @@ export async function handler(
subresourceIntegrityManifest,
serverActionsManifest,
clientReferenceManifest,
isPossibleServerAction,
isOnDemandRevalidate,
setIsrStatus: routerServerContext?.setIsrStatus,

dir: routeModule.projectDir,
isDraftMode,
isRevalidate,
botType,
isOnDemandRevalidate,
isPossibleServerAction,
assetPrefix: nextConfig.assetPrefix,
nextConfigOutput: nextConfig.output,
crossOrigin: nextConfig.crossOrigin,
trailingSlash: nextConfig.trailingSlash,
previewProps: prerenderManifest.preview,
deploymentId: nextConfig.deploymentId,
enableTainting: nextConfig.experimental.taint,
// @ts-expect-error fix issue with readonly regex object type
htmlLimitedBots: nextConfig.htmlLimitedBots,
devtoolSegmentExplorer:
nextConfig.experimental.devtoolSegmentExplorer,
Expand All @@ -385,7 +369,6 @@ export async function handler(
incrementalCache: getRequestMeta(req, 'incrementalCache'),
cacheLifeProfiles: nextConfig.experimental.cacheLife,
basePath: nextConfig.basePath,
// @ts-expect-error fix issue with readonly regex object type
serverActions: nextConfig.experimental.serverActions,

...(isDebugStaticShell || isDebugDynamicAccesses
Expand Down
19 changes: 4 additions & 15 deletions packages/next/src/build/templates/app-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import {
} from '../../server/route-modules/app-route/module.compiled'
import { RouteKind } from '../../server/route-kind'
import { patchFetch as _patchFetch } from '../../server/lib/patch-fetch'

import * as userland from 'VAR_USERLAND'
import {
RouterServerContextSymbol,
routerServerGlobal,
} from '../../server/lib/router-utils/router-server-context'
import type { IncomingMessage, ServerResponse } from 'node:http'
import { getRequestMeta } from '../../server/request-meta'
import { getTracer, type Span, SpanKind } from '../../server/lib/trace/tracer'
Expand All @@ -31,6 +25,8 @@ import {
type ResponseCacheEntry,
} from '../../server/response-cache'

import * as userland from 'VAR_USERLAND'

// These are injected by the loader afterwards. This is injected as a variable
// instead of a replacement because this could also be `undefined` instead of
// an empty string.
Expand Down Expand Up @@ -112,16 +108,12 @@ export async function handler(
buildId,
params,
parsedUrl,
serverFilesManifest,
nextConfig,
prerenderManifest,
routerServerContext,
isOnDemandRevalidate,
} = prepareResult

const routerServerContext =
routerServerGlobal[RouterServerContextSymbol]?.[
process.env.__NEXT_RELATIVE_PROJECT_DIR || ''
]

const onInstrumentationRequestError =
routeModule.instrumentationOnRequestError.bind(routeModule)

Expand All @@ -147,9 +139,6 @@ export async function handler(
)
}

const nextConfig =
routerServerContext?.nextConfig || serverFilesManifest.config

const pathname = parsedUrl.pathname || '/'
const normalizedSrcPage = normalizeAppPath(srcPage)
let isIsr = Boolean(
Expand Down
Loading
Loading