Unverified Commit 836ac16e authored by digasic's avatar digasic Committed by Hendrik Liebau

fix(app-render): end the cache-signal read when encryptActionBoundArgs hits the Resume Data Cache

`encryptActionBoundArgs` calls `startReadOnce()` before looking the
serialized bound args up in the Resume Data Cache and, on a hit, returned
the cached ciphertext without `endReadIfStarted()`. The request's
CacheSignal count then stayed at 1 forever. With `partialPrefetching` the
runtime-prefetch stream embedded in the RSC payload is only written and
closed after `cacheSignal.cacheReady()`, so the Flight stream never ended
and the HTML response of every partially prerendered page that renders an
inline Server Function with bound args never terminated in production.

End the read on the hit path, mirroring the miss and error paths, and add
an e2e test that fetches such a page and asserts the body ends with
`</html>`.
Co-Authored-By: 's avatarClaude Fable 5.1 <noreply@anthropic.com>
parent ba182aa1
...@@ -225,6 +225,7 @@ export const encryptActionBoundArgs = React.cache( ...@@ -225,6 +225,7 @@ export const encryptActionBoundArgs = React.cache(
const cachedEncrypted = resumeDataCache?.encryptedBoundArgs.get(cacheKey) const cachedEncrypted = resumeDataCache?.encryptedBoundArgs.get(cacheKey)
if (cachedEncrypted) { if (cachedEncrypted) {
endReadIfStarted()
return cachedEncrypted return cachedEncrypted
} }
......
import type { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { Suspense } from 'react'
import { cookies } from 'next/headers'
// A "use cache" entry makes the Resume Data Cache get persisted into the
// postponed state, together with the encrypted bound args of the inline Server
// Functions that were rendered during the prerender.
async function getGreeting() {
'use cache'
return 'Hello'
}
async function Greeting() {
return <h1>{await getGreeting()}</h1>
}
// An inline Server Function that closes over a prop is compiled to
// `action.bind(null, encryptActionBoundArgs(id, locale))`. At request time the
// encrypted bound args are found in the Resume Data Cache.
function SearchForm({ locale }: { locale: string }) {
async function onSubmit(formData: FormData) {
'use server'
console.log(locale, formData.get('q'))
}
return (
<form action={onSubmit}>
<input name="q" />
<button type="submit">Go</button>
</form>
)
}
// Request-time data inside Suspense: the page gets a static shell and is
// resumed per request.
async function DynamicContent() {
await cookies()
return <p id="dynamic-content">Dynamic content</p>
}
export default function Page() {
return (
<main>
<Greeting />
<SearchForm locale="en" />
<Suspense fallback={<p>Loading...</p>}>
<DynamicContent />
</Suspense>
</main>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
partialPrefetching: true,
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('partial prefetching with an inline server function', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('terminates the HTML response of a partially prerendered page', async () => {
// The page renders an inline Server Function with bound args whose
// encrypted value is served from the Resume Data Cache. Before the fix,
// `encryptActionBoundArgs` left the request's CacheSignal read open on that
// cache hit, so the runtime-prefetch stream embedded in the RSC payload was
// never closed and reading the body never resolved.
const res = await next.fetch('/')
expect(res.status).toBe(200)
const html = await res.text()
expect(html).toContain('Dynamic content')
expect(html.trimEnd().endsWith('</html>')).toBe(true)
})
})
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