forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore and enhance error handling for hanging inputs in
"use cache"
(
vercel#74652) Uncached and forever hanging promises are currently not supported as input for `"use cache"` functions. One prominent example of this is the use of `searchParams` in a page with `"use cache"`. Until Next.js version 15.1.1, the usage of such inputs led to an error during build after a timeout of 50 seconds. This behaviour relied on a bug in `decodeReply` though, and was hence broken after React fixed the bug. A build will now fail early with `Error: Connection closed.`. With this PR, we are restoring the timeout error behaviour by switching to the new `decodeReplyFromAsyncIterable` API, which allows us to keep an open stream when decoding the cached function's arguments. In addition, in dev mode, we are now also propagating the error to the dev overlay.
- Loading branch information
1 parent
b6a4b0d
commit 338eb99
Showing
13 changed files
with
396 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const USE_CACHE_TIMEOUT_ERROR_CODE = 'USE_CACHE_TIMEOUT' | ||
|
||
export class UseCacheTimeoutError extends Error { | ||
digest: typeof USE_CACHE_TIMEOUT_ERROR_CODE = USE_CACHE_TIMEOUT_ERROR_CODE | ||
|
||
constructor() { | ||
super( | ||
'Filling a cache during prerender timed out, likely because request-specific arguments such as params, searchParams, cookies() or dynamic data were used inside "use cache".' | ||
) | ||
} | ||
} | ||
|
||
export function isUseCacheTimeoutError( | ||
err: unknown | ||
): err is UseCacheTimeoutError { | ||
if ( | ||
typeof err !== 'object' || | ||
err === null || | ||
!('digest' in err) || | ||
typeof err.digest !== 'string' | ||
) { | ||
return false | ||
} | ||
|
||
return err.digest === USE_CACHE_TIMEOUT_ERROR_CODE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use cache' | ||
|
||
export default async function Page() { | ||
throw new Error('kaputt!') | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/use-cache-hanging-inputs/app/search-params-unused/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use cache' | ||
|
||
export default async function Page({ | ||
searchParams, | ||
}: { | ||
searchParams: Promise<{ n: string }> | ||
}) { | ||
return <p>search params not used</p> | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/use-cache-hanging-inputs/app/search-params/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use cache' | ||
|
||
export default async function Page({ | ||
searchParams, | ||
}: { | ||
searchParams: Promise<{ n: string }> | ||
}) { | ||
const { n } = await searchParams | ||
|
||
return <p>search param: {n}</p> | ||
} |
Oops, something went wrong.