import Link from 'next/link';
import { Suspense } from 'react';
import { cookies } from 'next/headers';
export default function RuntimeDataSuspensePage() {
return (
← Back to Cache Lab
Runtime data + Suspense
This page reads cookies() at request time (runtime data),
then passes a value into a cached function. The runtime read is
wrapped in {''} so it is an explicit dynamic
boundary.
Loading runtime cookie…
}
>
Expected: changing the cookie changes the input to the
cached function, producing a different cache entry.
The cached function itself uses use cache, so for the
same cookie value, it should return a stable payload across reloads.
);
}
async function setCookie(value: string) {
'use server';
const store = await cookies();
store.set('cache_lab_session', value, { path: '/' });
}
async function setCookieUserA() {
'use server';
await setCookie('user-a');
}
async function setCookieUserB() {
'use server';
await setCookie('user-b');
}
async function RuntimeCookieBlock() {
const store = await cookies();
const sessionId = store.get('cache_lab_session')?.value || 'anonymous';
return (