Unverified Commit 5136f8ec authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

[dynamicIO] Avoid timeout errors with dynamic params in `"use cache"` (#78882)

parent 6440778d
---
"next": patch
---
[dynamicIO] Avoid timeout errors with dynamic params in `"use cache"`
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
// singleton modules should always use "*.external" instead of "*-instance" // singleton modules should always use "*.external" instead of "*-instance"
"packages/next/src/server/app-render/action-async-storage-instance.ts", "packages/next/src/server/app-render/action-async-storage-instance.ts",
"packages/next/src/server/app-render/after-task-async-storage-instance.ts", "packages/next/src/server/app-render/after-task-async-storage-instance.ts",
"packages/next/src/server/app-render/dynamic-access-async-storage-instance.ts",
"packages/next/src/server/app-render/work-async-storage-instance.ts", "packages/next/src/server/app-render/work-async-storage-instance.ts",
"packages/next/src/server/app-render/work-unit-async-storage-instance.ts", "packages/next/src/server/app-render/work-unit-async-storage-instance.ts",
"packages/next/src/client/components/segment-cache-impl/*" "packages/next/src/client/components/segment-cache-impl/*"
......
...@@ -682,5 +682,7 @@ ...@@ -682,5 +682,7 @@
"681": "Dynamic imports should not be instrumented in the edge runtime, because `dynamicIO` doesn't support it", "681": "Dynamic imports should not be instrumented in the edge runtime, because `dynamicIO` doesn't support it",
"682": "\\`experimental.ppr\\` can not be \\`%s\\` when \\`experimental.dynamicIO\\` is \\`true\\`. PPR is implicitly enabled when Dynamic IO is enabled.", "682": "\\`experimental.ppr\\` can not be \\`%s\\` when \\`experimental.dynamicIO\\` is \\`true\\`. PPR is implicitly enabled when Dynamic IO is enabled.",
"683": "The \\`compiler.define\\` option is configured to replace the \\`%s\\` variable. This variable is either part of a Next.js built-in or is already configured.", "683": "The \\`compiler.define\\` option is configured to replace the \\`%s\\` variable. This variable is either part of a Next.js built-in or is already configured.",
"684": "The \\`compiler.defineServer\\` option is configured to replace the \\`%s\\` variable. This variable is either part of a Next.js built-in or is already configured." "684": "The \\`compiler.defineServer\\` option is configured to replace the \\`%s\\` variable. This variable is either part of a Next.js built-in or is already configured.",
"685": "Accessed fallback \\`params\\` during prerendering.",
"686": "Expected clientReferenceManifest to be defined."
} }
...@@ -2683,8 +2683,7 @@ export default async function build( ...@@ -2683,8 +2683,7 @@ export default async function build(
_isDynamicError: isDynamicError, _isDynamicError: isDynamicError,
_isAppDir: true, _isAppDir: true,
_isRoutePPREnabled: isRoutePPREnabled, _isRoutePPREnabled: isRoutePPREnabled,
_doNotThrowOnEmptyStaticShell: _allowEmptyStaticShell: !route.throwOnEmptyStaticShell,
!route.throwOnEmptyStaticShell,
} }
}) })
}) })
......
...@@ -133,7 +133,7 @@ const browserNonTranspileModules = [ ...@@ -133,7 +133,7 @@ const browserNonTranspileModules = [
const precompileRegex = /[\\/]next[\\/]dist[\\/]compiled[\\/]/ const precompileRegex = /[\\/]next[\\/]dist[\\/]compiled[\\/]/
const asyncStoragesRegex = const asyncStoragesRegex =
/next[\\/]dist[\\/](esm[\\/])?server[\\/]app-render[\\/](work-async-storage|action-async-storage|work-unit-async-storage)/ /next[\\/]dist[\\/](esm[\\/])?server[\\/]app-render[\\/](work-async-storage|action-async-storage|dynamic-access-async-storage|work-unit-async-storage)/
// Support for NODE_PATH // Support for NODE_PATH
const nodePathList = (process.env.NODE_PATH || '') const nodePathList = (process.env.NODE_PATH || '')
......
...@@ -104,9 +104,9 @@ async function exportPageImpl( ...@@ -104,9 +104,9 @@ async function exportPageImpl(
// the renderOpts. // the renderOpts.
_isRoutePPREnabled: isRoutePPREnabled, _isRoutePPREnabled: isRoutePPREnabled,
// Configure the rendering of the page not to throw if an empty static shell // Configure the rendering of the page to allow that an empty static shell
// is generated while rendering using PPR. // is generated while rendering using PPR and Dynamic IO.
_doNotThrowOnEmptyStaticShell: doNotThrowOnEmptyStaticShell = false, _allowEmptyStaticShell: allowEmptyStaticShell = false,
// Pull the original query out. // Pull the original query out.
query: originalQuery = {}, query: originalQuery = {},
...@@ -266,7 +266,7 @@ async function exportPageImpl( ...@@ -266,7 +266,7 @@ async function exportPageImpl(
// If it's static, then it won't affect anything. // If it's static, then it won't affect anything.
// If it's dynamic, then it can be handled when request hits the route. // If it's dynamic, then it can be handled when request hits the route.
serveStreamingMetadata: true, serveStreamingMetadata: true,
doNotThrowOnEmptyStaticShell, allowEmptyStaticShell,
experimental: { experimental: {
...input.renderOpts.experimental, ...input.renderOpts.experimental,
isRoutePPREnabled, isRoutePPREnabled,
......
...@@ -21,7 +21,10 @@ import type { LoadingModuleData } from '../../shared/lib/app-router-context.shar ...@@ -21,7 +21,10 @@ import type { LoadingModuleData } from '../../shared/lib/app-router-context.shar
import type { Params } from '../request/params' import type { Params } from '../request/params'
import { workUnitAsyncStorage } from './work-unit-async-storage.external' import { workUnitAsyncStorage } from './work-unit-async-storage.external'
import { OUTLET_BOUNDARY_NAME } from '../../lib/metadata/metadata-constants' import { OUTLET_BOUNDARY_NAME } from '../../lib/metadata/metadata-constants'
import type { UseCachePageComponentProps } from '../use-cache/use-cache-wrapper' import type {
UseCacheLayoutComponentProps,
UseCachePageComponentProps,
} from '../use-cache/use-cache-wrapper'
/** /**
* Use the provided loader tree to create the React Component tree. * Use the provided loader tree to create the React Component tree.
...@@ -677,16 +680,21 @@ async function createComponentTreeInternal({ ...@@ -677,16 +680,21 @@ async function createComponentTreeInternal({
workStore workStore
) )
// TODO(useCache): Should we use this trick also if dynamicIO is enabled, // If we are passing searchParams to a server component Page we need to
// instead of relying on the searchParams being a hanging promise? // track their usage in case the current render mode tracks dynamic API
if (!experimental.dynamicIO && isUseCacheFunction(PageComponent)) { // usage.
let searchParams = createServerSearchParamsForServerPage(query, workStore)
if (isUseCacheFunction(PageComponent)) {
const UseCachePageComponent: React.ComponentType<UseCachePageComponentProps> = const UseCachePageComponent: React.ComponentType<UseCachePageComponentProps> =
PageComponent PageComponent
// The "use cache" wrapper takes care of converting this into an if (!experimental.dynamicIO) {
// erroring search params promise when passing it to the original // The "use cache" wrapper takes care of converting this into an
// function. // erroring search params promise when passing it to the original
const searchParams = Promise.resolve({}) // function.
searchParams = Promise.resolve({})
}
pageElement = ( pageElement = (
<UseCachePageComponent <UseCachePageComponent
...@@ -696,14 +704,6 @@ async function createComponentTreeInternal({ ...@@ -696,14 +704,6 @@ async function createComponentTreeInternal({
/> />
) )
} else { } else {
// If we are passing searchParams to a server component Page we need to
// track their usage in case the current render mode tracks dynamic API
// usage.
const searchParams = createServerSearchParamsForServerPage(
query,
workStore
)
pageElement = ( pageElement = (
<PageComponent params={params} searchParams={searchParams} /> <PageComponent params={params} searchParams={searchParams} />
) )
...@@ -845,9 +845,24 @@ async function createComponentTreeInternal({ ...@@ -845,9 +845,24 @@ async function createComponentTreeInternal({
workStore workStore
) )
let serverSegment = ( let serverSegment: React.ReactNode
<SegmentComponent {...parallelRouteProps} params={params} />
) if (isUseCacheFunction(SegmentComponent)) {
const UseCacheLayoutComponent: React.ComponentType<UseCacheLayoutComponentProps> =
SegmentComponent
serverSegment = (
<UseCacheLayoutComponent
{...parallelRouteProps}
params={params}
$$isLayoutComponent
/>
)
} else {
serverSegment = (
<SegmentComponent {...parallelRouteProps} params={params} />
)
}
if (isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot) { if (isRootLayoutWithChildrenSlotAndAtLeastOneMoreSlot) {
// TODO-APP: This is a hack to support unmatched parallel routes, which will throw `notFound()`. // TODO-APP: This is a hack to support unmatched parallel routes, which will throw `notFound()`.
......
import { createAsyncLocalStorage } from './async-local-storage'
import type { DynamicAccessStorage } from './dynamic-access-async-storage.external'
export const dynamicAccessAsyncStorageInstance: DynamicAccessStorage =
createAsyncLocalStorage()
import type { AsyncLocalStorage } from 'async_hooks'
// Share the instance module in the next-shared layer
import { dynamicAccessAsyncStorageInstance } from './dynamic-access-async-storage-instance' with { 'turbopack-transition': 'next-shared' }
export interface DynamicAccessAsyncStore {
readonly abortController: AbortController
}
export type DynamicAccessStorage = AsyncLocalStorage<DynamicAccessAsyncStore>
export { dynamicAccessAsyncStorageInstance as dynamicAccessAsyncStorage }
...@@ -269,11 +269,12 @@ export interface RenderOptsPartial { ...@@ -269,11 +269,12 @@ export interface RenderOptsPartial {
isStaticGeneration?: boolean isStaticGeneration?: boolean
/** /**
* When true, the page will be rendered using the static rendering to detect * When true, the page is prerendered as a fallback shell, while allowing any
* any dynamic API's that would have stopped the page from being fully * dynamic accesses to result in an empty shell. This is the case when there
* statically generated. * are also routes prerendered with a more complete set of params.
* Prerendering those routes would catch any invalid dynamic accesses.
*/ */
doNotThrowOnEmptyStaticShell?: boolean allowEmptyStaticShell?: boolean
/** /**
* next config experimental.devtoolSegmentExplorer * next config experimental.devtoolSegmentExplorer
......
...@@ -163,6 +163,11 @@ export interface CommonCacheStore ...@@ -163,6 +163,11 @@ export interface CommonCacheStore
* from which implicit tags could be inherited. * from which implicit tags could be inherited.
*/ */
readonly implicitTags: ImplicitTags | undefined readonly implicitTags: ImplicitTags | undefined
/**
* Draft mode is only available if the outer work unit store is a request
* store and draft mode is enabled.
*/
readonly draftMode: DraftModeProvider | undefined
} }
export interface UseCacheStore extends CommonCacheStore { export interface UseCacheStore extends CommonCacheStore {
...@@ -179,21 +184,20 @@ export interface UseCacheStore extends CommonCacheStore { ...@@ -179,21 +184,20 @@ export interface UseCacheStore extends CommonCacheStore {
readonly isHmrRefresh: boolean readonly isHmrRefresh: boolean
readonly serverComponentsHmrCache: ServerComponentsHmrCache | undefined readonly serverComponentsHmrCache: ServerComponentsHmrCache | undefined
readonly forceRevalidate: boolean readonly forceRevalidate: boolean
// Draft mode is only available if the outer work unit store is a request
// store and draft mode is enabled.
readonly draftMode: DraftModeProvider | undefined
} }
export interface UnstableCacheStore extends CommonCacheStore { export interface UnstableCacheStore extends CommonCacheStore {
type: 'unstable-cache' type: 'unstable-cache'
// Draft mode is only available if the outer work unit store is a request
// store and draft mode is enabled.
readonly draftMode: DraftModeProvider | undefined
} }
/** /**
* The Cache store is for tracking information inside a "use cache" or unstable_cache context. * The Cache store is for tracking information inside a "use cache" or
* Inside this context we should never expose any request or page specific information. * unstable_cache context. A cache store shadows an outer request store (if
* present) as a work unit, so that we never accidentally expose any request or
* page specific information to cache functions, unless it's explicitly desired.
* For those exceptions, the data is copied over from the request store to the
* cache store, instead of generally making the request store available to cache
* functions.
*/ */
export type CacheStore = UseCacheStore | UnstableCacheStore export type CacheStore = UseCacheStore | UnstableCacheStore
......
...@@ -41,7 +41,7 @@ const zExportMap: zod.ZodType<ExportPathMap> = z.record( ...@@ -41,7 +41,7 @@ const zExportMap: zod.ZodType<ExportPathMap> = z.record(
_isAppDir: z.boolean().optional(), _isAppDir: z.boolean().optional(),
_isDynamicError: z.boolean().optional(), _isDynamicError: z.boolean().optional(),
_isRoutePPREnabled: z.boolean().optional(), _isRoutePPREnabled: z.boolean().optional(),
_doNotThrowOnEmptyStaticShell: z.boolean().optional(), _allowEmptyStaticShell: z.boolean().optional(),
}) })
) )
......
...@@ -750,13 +750,15 @@ export type ExportPathMap = { ...@@ -750,13 +750,15 @@ export type ExportPathMap = {
_isRoutePPREnabled?: boolean _isRoutePPREnabled?: boolean
/** /**
* When true, it indicates that the diagnostic render for this page is * When true, the page is prerendered as a fallback shell, while allowing
* disabled. This is only used when the app has `experimental.ppr` and * any dynamic accesses to result in an empty shell. This is the case when
* `experimental.dynamicIO` enabled. * the app has `experimental.ppr` and `experimental.dynamicIO` enabled, and
* there are also routes prerendered with a more complete set of params.
* Prerendering those routes would catch any invalid dynamic accesses.
* *
* @internal * @internal
*/ */
_doNotThrowOnEmptyStaticShell?: boolean _allowEmptyStaticShell?: boolean
} }
} }
......
...@@ -24,6 +24,7 @@ import { ...@@ -24,6 +24,7 @@ import {
import { makeHangingPromise } from '../dynamic-rendering-utils' import { makeHangingPromise } from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger' import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger'
import { scheduleImmediate } from '../../lib/scheduler' import { scheduleImmediate } from '../../lib/scheduler'
import { dynamicAccessAsyncStorage } from '../app-render/dynamic-access-async-storage.external'
export type ParamValue = string | Array<string> | undefined export type ParamValue = string | Array<string> | undefined
export type Params = Record<string, ParamValue> export type Params = Record<string, ParamValue>
...@@ -198,6 +199,33 @@ function createRenderParams( ...@@ -198,6 +199,33 @@ function createRenderParams(
interface CacheLifetime {} interface CacheLifetime {}
const CachedParams = new WeakMap<CacheLifetime, Promise<Params>>() const CachedParams = new WeakMap<CacheLifetime, Promise<Params>>()
const fallbackParamsProxyHandler: ProxyHandler<Promise<Params>> = {
get: function get(target, prop, receiver) {
if (prop === 'then' || prop === 'catch' || prop === 'finally') {
const originalMethod = ReflectAdapter.get(target, prop, receiver)
return {
[prop]: (...args: unknown[]) => {
const store = dynamicAccessAsyncStorage.getStore()
if (store) {
store.abortController.abort(
new Error(`Accessed fallback \`params\` during prerendering.`)
)
}
return new Proxy(
originalMethod.apply(target, args),
fallbackParamsProxyHandler
)
},
}[prop]
}
return ReflectAdapter.get(target, prop, receiver)
},
}
function makeAbortingExoticParams( function makeAbortingExoticParams(
underlyingParams: Params, underlyingParams: Params,
route: string, route: string,
...@@ -208,10 +236,11 @@ function makeAbortingExoticParams( ...@@ -208,10 +236,11 @@ function makeAbortingExoticParams(
return cachedParams return cachedParams
} }
const promise = makeHangingPromise<Params>( const promise = new Proxy(
prerenderStore.renderSignal, makeHangingPromise<Params>(prerenderStore.renderSignal, '`params`'),
'`params`' fallbackParamsProxyHandler
) )
CachedParams.set(underlyingParams, promise) CachedParams.set(underlyingParams, promise)
Object.keys(underlyingParams).forEach((prop) => { Object.keys(underlyingParams).forEach((prop) => {
......
export async function LastModified({ params }) {
const { slug } = await params
return (
<p data-testid={`page-${slug}`}>
Page /{slug} last modified: {new Date().toISOString()}
</p>
)
}
export async function CachedLastModified({ params }) {
'use cache'
return <LastModified params={params} />
}
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
export function getSentinelValue() {
return process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD
? 'buildtime'
: 'runtime'
}
'use cache'
import { Suspense } from 'react'
import { getSentinelValue } from '../sentinel'
export default async function Layout({ children }) {
return (
<html>
<body>
<div data-testid={`layout-${getSentinelValue()}`}>
Layout: {new Date().toISOString()}
</div>
<Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
</body>
</html>
)
}
'use cache'
import { LastModified } from '../../../last-modified'
export default async function Page({ params }) {
return <LastModified params={params} />
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
import { CachedLastModified } from '../../../last-modified'
export default async function Page({ params }) {
return <CachedLastModified params={params} />
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
import { CachedLastModified } from '../../../last-modified'
export default async function Page({ params }) {
return (
<>
<CachedLastModified params={params.then((p) => ({ slug: p.slug }))} />
<CachedLastModified params={params.catch(() => {})} />
<CachedLastModified params={params.finally(() => {})} />
<CachedLastModified params={params.finally().catch()} />
</>
)
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
'use cache'
import { getSentinelValue } from '../sentinel'
export default async function Layout({ children }) {
return (
<html>
<body>
<div data-testid={`layout-${getSentinelValue()}`}>
Layout: {new Date().toISOString()}
</div>
{children}
</body>
</html>
)
}
'use cache'
import { LastModified } from '../../../last-modified'
export default async function Page({ params }) {
return <LastModified params={params} />
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
import { CachedLastModified } from '../../../last-modified'
export default async function Page({ params }) {
return <CachedLastModified params={params} />
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
import { CachedLastModified } from '../../../last-modified'
export default async function Page({ params }) {
return (
<>
<CachedLastModified params={params.then((p) => ({ slug: p.slug }))} />
<CachedLastModified params={params.catch(() => {})} />
<CachedLastModified params={params.finally(() => {})} />
<CachedLastModified params={params.finally().catch()} />
</>
)
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('empty-fallback-shells', () => { describe('empty-fallback-shells', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next, isNextDev, isNextDeploy, isNextStart } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should start and not postpone the response', async () => { describe('without IO', () => {
const res = await next.fetch('/world') it('should start and not postpone the response', async () => {
const html = await res.text() const res = await next.fetch('/without-io/world')
expect(html).toContain('hello-world') const html = await res.text()
expect(html).toContain('hello-world')
if (isNextDeploy) { if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe('/[slug]') expect(res.headers.get('x-matched-path')).toBe('/without-io/[slug]')
} }
// If we didn't use the fallback shell, then we didn't postpone the response // If we didn't use the fallback shell, then we didn't postpone the
// and therefore shouldn't have sent the postponed header. // response and therefore shouldn't have sent the postponed header.
expect(res.headers.get('x-nextjs-postponed')).not.toBe('1') expect(res.headers.get('x-nextjs-postponed')).not.toBe('1')
})
}) })
describe('with cached IO', () => {
describe('and the page wrapped in Suspense', () => {
describe('and the params accessed in the cached page', () => {
it('resumes a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/with-suspense/params-in-page/bar'
)
const html = await res.text()
expect(html).toContain('page-bar')
if (isNextDev) {
expect(html).toContain('layout-runtime')
} else {
expect(html).toContain('layout-buildtime')
}
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/with-suspense/params-in-page/[slug]'
)
} else if (isNextStart) {
expect(res.headers.get('x-nextjs-postponed')).toBe('1')
}
})
})
describe('and the params accessed in cached non-page function', () => {
it('resumes a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/with-suspense/params-not-in-page/bar'
)
const html = await res.text()
expect(html).toContain('page-bar')
if (isNextDev) {
expect(html).toContain('layout-runtime')
} else {
expect(html).toContain('layout-buildtime')
}
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/with-suspense/params-not-in-page/[slug]'
)
} else if (isNextStart) {
expect(res.headers.get('x-nextjs-postponed')).toBe('1')
}
})
})
describe('and params.then/catch/finally passed to a cached function', () => {
it('resumes a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/with-suspense/params-then-in-page/bar'
)
const html = await res.text()
expect(html).toIncludeRepeated('data-testid="page-bar"', 4)
if (isNextDev) {
expect(html).toContain('layout-runtime')
} else {
expect(html).toContain('layout-buildtime')
}
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/with-suspense/params-then-in-page/[slug]'
)
} else if (isNextStart) {
expect(res.headers.get('x-nextjs-postponed')).toBe('1')
}
})
})
})
describe('and the page not wrapped in Suspense', () => {
describe('and the params accessed in the cached page', () => {
it('does not resume a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/without-suspense/params-in-page/bar'
)
const html = await res.text()
expect(html).toContain('page-bar')
expect(html).toContain('layout-runtime')
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/without-suspense/params-in-page/[slug]'
)
} else {
expect(res.headers.get('x-nextjs-postponed')).not.toBe('1')
}
})
})
describe('and the params accessed in a cached non-page function', () => {
it('does not resume a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/without-suspense/params-not-in-page/bar'
)
const html = await res.text()
expect(html).toContain('page-bar')
expect(html).toContain('layout-runtime')
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/without-suspense/params-not-in-page/[slug]'
)
} else {
expect(res.headers.get('x-nextjs-postponed')).not.toBe('1')
}
})
})
describe('and params.then/catch/finally passed to a cached function', () => {
it('does not resume a postponed fallback shell', async () => {
const res = await next.fetch(
'/with-cached-io/without-suspense/params-then-in-page/bar'
)
const html = await res.text()
expect(html).toIncludeRepeated('data-testid="page-bar"', 4)
expect(html).toContain('layout-runtime')
if (isNextDeploy) {
expect(res.headers.get('x-matched-path')).toBe(
'/with-cached-io/without-suspense/params-then-in-page/[slug]'
)
} else {
expect(res.headers.get('x-nextjs-postponed')).not.toBe('1')
}
})
})
})
})
if (isNextStart) {
it('should not log a HANGING_PROMISE_REJECTION error', async () => {
expect(next.cliOutput).not.toContain('HANGING_PROMISE_REJECTION')
})
}
}) })
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
const nextConfig = { const nextConfig = {
experimental: { experimental: {
dynamicIO: true, dynamicIO: true,
prerenderEarlyExit: false,
}, },
} }
......
'use cache'
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <p>slug: {slug}</p>
}
// If generateStaticParams would be used here to define at least one set of
// complete params, we would not yield a timeout error.
async function LastModified({ params }) {
'use cache'
const { slug } = await params
return (
<p data-testid={`page-${slug}`}>
Page /{slug} last modified: {new Date().toISOString()}
</p>
)
}
async function transformParams(params) {
const { slug } = await params
return { slug }
}
export default async function Page({ params }) {
return <LastModified params={transformParams(params)} />
}
export async function generateStaticParams() {
return [{ slug: 'foo' }]
}
...@@ -335,15 +335,15 @@ describe('use-cache-hanging-inputs', () => { ...@@ -335,15 +335,15 @@ describe('use-cache-hanging-inputs', () => {
) )
expect(cliOutput).toInclude( expect(cliOutput).toInclude(
createExpectedBuildErrorMessage('/fallback-params/[slug]') createExpectedBuildErrorMessage('/search-params')
) )
expect(cliOutput).toInclude( expect(cliOutput).toInclude(
createExpectedBuildErrorMessage('/search-params') createExpectedBuildErrorMessage('/search-params-caught')
) )
expect(cliOutput).toInclude( expect(cliOutput).toInclude(
createExpectedBuildErrorMessage('/search-params-caught') createExpectedBuildErrorMessage('/transformed-params/[slug]')
) )
expect(cliOutput).toInclude( expect(cliOutput).toInclude(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment