next.js/test/e2e/app-dir/instant-validation/app/suspense-in-root/runtime/valid-sync-io-in-static-parent/layout.tsx
layout.tsx32 lines870 B
import { cookies } from 'next/headers'
import { Suspense } from 'react'

// This layout does NOT have runtime prefetch — it's a static segment.
// The RuntimeContent component accesses cookies() then Date.now().
// In a static prefetch the render would never get past cookies() so the
// sync IO is unreachable. In a runtime prefetch, cookies() would resolve
// but this layout is not runtime-prefetchable — only the child page is.
// So the sync IO here should not error.

async function RuntimeContent() {
  await cookies()
  const now = Date.now()
  return <p>Static layout with sync IO after cookies: {now}</p>
}

export default function StaticLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <div>
      <Suspense fallback={<p>Loading...</p>}>
        <RuntimeContent />
      </Suspense>
      <hr />
      {children}
    </div>
  )
}
Quest for Codev2.0.0
/
SIGN IN