Unverified Commit 4a95af80 authored by Josh Story's avatar Josh Story Committed by GitHub

Fix use cache prerender signal retention (#97476)

## Summary

After a fallback-shell cache prerender completes, snapshot whether its
timeout fired and then abort the existing timeout controller when it
participates in an `AbortSignal.any()` composite. This triggers the
composite so React removes its abort listener; no additional controller
or signal is needed. Cache prerenders without a dynamic-access source
keep their existing direct timeout signal.

Node retains non-empty composite abort signals while they have abort
listeners. React attaches such a listener during `prerender()` and
removes it when the signal aborts, so aborting the already-owned timeout
source releases the successful render. Snapshotting `didTimeout` first
keeps cleanup aborts distinct from real timeouts.

This preserves the early aborted-prerender guard from #96426, which
prevents a cache fill that starts after its outer prerender aborts from
caching an empty React stream.

Fixes #97363
Related #97464
Alternative to #97391

## Verification

- `pnpm --filter=next build`
- `pnpm test-start-turbo
test/e2e/app-dir/use-cache-after-uncached-io/use-cache-after-uncached-io.test.ts`
- `pnpm test-start-turbo
test/e2e/app-dir/use-cache-hanging/use-cache-hanging.test.ts`
- Actual vendored React `prerender()` GC probe on Node 20.19.5 and
22.20.0: valid preludes, no cleanup errors, and 0/100 composite signals
retained while their source controllers remained reachable.

<!-- NEXT_JS_LLM -->
parent b677feb0
...@@ -1412,8 +1412,13 @@ async function generateCacheEntryImpl( ...@@ -1412,8 +1412,13 @@ async function generateCacheEntryImpl(
) )
clearTimeout(timer) clearTimeout(timer)
const didTimeout = timeoutAbortController.signal.aborted
if (dynamicAccessAbortSignal) {
// Release React's listener from the composite signal.
timeoutAbortController.abort()
}
if (timeoutAbortController.signal.aborted) { if (didTimeout) {
// When the timeout is reached we always error the stream. Even for // When the timeout is reached we always error the stream. Even for
// fallback shell prerenders we don't want to return a hanging promise, // fallback shell prerenders we don't want to return a hanging promise,
// which would allow the function to become a dynamic hole. Because that // which would allow the function to become a dynamic hole. Because that
......
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