Skip to content
Closed

NAR-133 #79255

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
3 changes: 2 additions & 1 deletion packages/next/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -679,5 +679,6 @@
"678": "CacheSignal got more endRead() calls than beginRead() calls",
"679": "A CacheSignal cannot subscribe to itself",
"680": "Expected clientReferenceManifest to be defined.",
"681": "Accessed fallback \\`params\\` during prerendering."
"681": "Accessed fallback \\`params\\` during prerendering.",
"682": "\\`experimental.ppr\\` can not be \\`%s\\` when \\`experimental.dynamicIO\\` is \\`true\\`. PPR is implicitly enabled when Dynamic IO is enabled."
}
52 changes: 0 additions & 52 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ import {
} from '../server/lib/experimental/ppr'
import { FallbackMode, fallbackModeToFallbackField } from '../lib/fallback'
import { RenderingMode } from './rendering-mode'
import { getParamKeys } from '../server/request/fallback-params'
import { InvariantError } from '../shared/lib/invariant-error'
import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot'
import type { UseCacheTrackerKey } from './webpack/plugins/telemetry-plugin/use-cache-tracker-utils'
Expand Down Expand Up @@ -1613,10 +1612,6 @@ export default async function build(
const serverPropsPages = new Set<string>()
const additionalPaths = new Map<string, PrerenderedRoute[]>()
const staticPaths = new Map<string, PrerenderedRoute[]>()
const prospectiveRenders = new Map<
string,
{ page: string; originalAppPath: string }
>()
const appNormalizedPaths = new Map<string, string>()
const fallbackModes = new Map<string, FallbackMode>()
const appDefaultConfigs = new Map<string, AppSegmentConfig>()
Expand Down Expand Up @@ -1975,31 +1970,6 @@ export default async function build(

staticPaths.set(originalAppPath, [])
}
// As PPR isn't enabled for this route, if dynamic IO
// is enabled, and this is a dynamic route, we should
// complete a prospective render for the route so that
// we can use the fallback behavior. This lets us
// check that dynamic pages won't error when they
// enable PPR.
else if (config.experimental.dynamicIO && isDynamic) {
// If there's a page with a more specific render
// available, then we should skip the prospective
// render because it'll be done as a part of the
// that render to validate the dynamic state.
if (
// The existence of any prerendered routes when
// PPR is disabled means that the route has more
// specific prerendered routes that should be
// used for the diagnostic render anyways.
!workerResult.prerenderedRoutes ||
workerResult.prerenderedRoutes.length === 0
) {
prospectiveRenders.set(originalAppPath, {
page,
originalAppPath,
})
}
}

if (workerResult.prerenderedRoutes) {
staticPaths.set(
Expand Down Expand Up @@ -2717,28 +2687,6 @@ export default async function build(
})
})

// If the app does have dynamic IO enabled but does not have PPR
// enabled, then we need to perform a prospective render for all
// the dynamic pages to ensure that they won't error during
// rendering (due to a missing prelude).
for (const {
page,
originalAppPath,
} of prospectiveRenders.values()) {
defaultMap[page] = {
page: originalAppPath,
_ssgPath: page,
_fallbackRouteParams: getParamKeys(page),
// Prospective renders are only enabled for app pages.
_isAppDir: true,
// Prospective renders are only enabled when PPR is disabled.
_isRoutePPREnabled: false,
_isProspectiveRender: true,
// Dynamic IO does not currently support `dynamic === 'error'`.
_isDynamicError: false,
}
}

if (i18n) {
for (const page of [
...staticPages,
Expand Down
52 changes: 0 additions & 52 deletions packages/next/src/export/routes/app-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,6 @@ import type { RequestLifecycleOpts } from '../../server/base-server'
import type { AppSharedContext } from '../../server/app-render/app-render'
import type { MultiFileWriter } from '../../lib/multi-file-writer'

export async function prospectiveRenderAppPage(
req: MockedRequest,
res: MockedResponse,
page: string,
pathname: string,
query: NextParsedUrlQuery,
fallbackRouteParams: FallbackRouteParams | null,
partialRenderOpts: Omit<RenderOpts, keyof RequestLifecycleOpts>,
sharedContext: AppSharedContext
): Promise<undefined> {
const afterRunner = new AfterRunner()

// If the page is `/_not-found`, then we should update the page to be `/404`.
// UNDERSCORE_NOT_FOUND_ROUTE value used here, however we don't want to import it here as it causes constants to be inlined which we don't want here.
if (page === '/_not-found/page') {
pathname = '/404'
}

try {
await lazyRenderAppPage(
new NodeNextRequest(req),
new NodeNextResponse(res),
pathname,
query,
fallbackRouteParams,
{
...partialRenderOpts,
waitUntil: afterRunner.context.waitUntil,
onClose: afterRunner.context.onClose,
onAfterTaskError: afterRunner.context.onTaskError,
},
undefined,
false,
sharedContext
)

// TODO(after): if we abort a prerender because of an error in an after-callback
// we should probably communicate that better (and not log the error twice)
await afterRunner.executeAfter()
} catch (err) {
if (!isDynamicUsageError(err)) {
throw err
}

// We should fail rendering if a client side rendering bailout
// occurred at the page level.
if (isBailoutToCSRError(err)) {
throw err
}
}
}

/**
* Renders & exports a page associated with the /app directory
*/
Expand Down
21 changes: 1 addition & 20 deletions packages/next/src/export/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { createRequestResponseMocks } from '../server/lib/mock-request'
import { isAppRouteRoute } from '../lib/is-app-route-route'
import { hasNextSupport } from '../server/ci-info'
import { exportAppRoute } from './routes/app-route'
import { exportAppPage, prospectiveRenderAppPage } from './routes/app-page'
import { exportAppPage } from './routes/app-page'
import { exportPagesPage } from './routes/pages'
import { getParams } from './helpers/get-params'
import { createIncrementalCache } from './helpers/create-incremental-cache'
Expand Down Expand Up @@ -104,10 +104,6 @@ async function exportPageImpl(
// the renderOpts.
_isRoutePPREnabled: isRoutePPREnabled,

// If this is a prospective render, we don't actually want to persist the
// result, we just want to use it to error the build if there's a problem.
_isProspectiveRender: isProspectiveRender = false,

// Configure the rendering of the page to allow that an empty static shell
// is generated while rendering using PPR and Dynamic IO.
_allowEmptyStaticShell: allowEmptyStaticShell = false,
Expand Down Expand Up @@ -287,21 +283,6 @@ async function exportPageImpl(
buildId: input.buildId,
}

// If this is a prospective render, don't return any metrics or revalidate
// timings as we aren't persisting this render (it was only to error).
if (isProspectiveRender) {
return prospectiveRenderAppPage(
req,
res,
page,
pathname,
query,
fallbackRouteParams,
renderOpts,
sharedContext
)
}

return exportAppPage(
req,
res,
Expand Down
Loading