mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Reland #54403 Also modifies the implementation of #55950 to not change the prefetch behavior when there is flight router state - we should only check the entire loader tree in the static prefetch case, otherwise we're inadvertently rendering the component tree for prefetches that match the current flight router state segment. ([slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1695862974745849)) This includes a few other misc fixes for static prefetch generation: - `next start` was not serving them (which also meant tests weren't catching a few small bugs) - the router cache key casing can differ between build and runtime, resulting in a bad cache lookup which results suspending indefinitely during navigation - We cannot generate static prefetches for pages that opt into `searchParams`, as the prefetch response won't have the right cache key in the RSC payload - Layouts that use headers/cookies shouldn't use a static prefetch because it can result in unexpected behavior (ie, being redirected to a login page, if the prefetch contains redirect logic for unauthed users) Closes NEXT-1665 Closes NEXT-1643
22 lines
502 B
JavaScript
22 lines
502 B
JavaScript
import { cookies } from 'next/headers'
|
|
import { Redirect } from './redirect'
|
|
|
|
async function isLoggedIn() {
|
|
// sleep for 1s
|
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
|
|
const cookieData = cookies()
|
|
const hasSession = !!cookieData.get('logged-in')
|
|
|
|
return hasSession
|
|
}
|
|
|
|
export default async function Layout({ children }) {
|
|
const loggedIn = await isLoggedIn()
|
|
console.log({ loggedIn })
|
|
|
|
if (!loggedIn) return <Redirect />
|
|
|
|
return <div>Protected Layout: {children}</div>
|
|
}
|