mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
This change adds infrastructure for a planned client-side optimization where the router can infer route structure from previously prefetched routes, avoiding redundant route tree requests. When the client prefetches /blog/post-1 and learns the route structure is /blog/[slug], it could potentially reuse that knowledge for /blog/post-2 without another server roundtrip. However, if a static route like /blog/featured exists at the same level, the client needs to know NOT to apply the dynamic template for that URL. staticSiblings provides this information. When a dynamic segment like [slug] has static siblings (e.g., "featured", "archive"), the server includes them in the prefetch response. The client can then check whether an incoming URL matches a known static sibling, and if so, recognize that the previously learned route structure does not apply.
34 lines
625 B
TypeScript
34 lines
625 B
TypeScript
'use client'
|
|
|
|
import Link from 'next/link'
|
|
import { useState } from 'react'
|
|
|
|
export function LinkAccordion({
|
|
href,
|
|
children,
|
|
prefetch,
|
|
}: {
|
|
href: string
|
|
children: React.ReactNode
|
|
prefetch?: boolean
|
|
}) {
|
|
const [isVisible, setIsVisible] = useState(false)
|
|
return (
|
|
<>
|
|
<input
|
|
type="checkbox"
|
|
checked={isVisible}
|
|
onChange={() => setIsVisible(!isVisible)}
|
|
data-link-accordion={href}
|
|
/>
|
|
{isVisible ? (
|
|
<Link href={href} prefetch={prefetch}>
|
|
{children}
|
|
</Link>
|
|
) : (
|
|
<>{children} (link is hidden)</>
|
|
)}
|
|
</>
|
|
)
|
|
}
|