mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
With `cacheComponents` + `partialPrefetching`, navigating to an already-prefetched route with a dynamic `generateMetadata` left `document.title` permanently empty until a hard reload. The prefetch cached the head as complete using the server's `isHeadPartial` flag, which is unreliable under Cache Components. Derive the head's partiality from `isResponsePartial` instead, as segment data already does, so a dynamic head is fetched and applied on navigation while a fully static head stays complete. Fixing the flag exposed a latent issue in the prefetch scheduler: during a speculative prefetch, the head was unconditionally runtime-prefetched, which previously went unnoticed because the head was mismarked as complete. The head is now runtime-prefetched only when a segment in the new part of the tree is a candidate for runtime prefetching — it rides along with that request rather than spawning a standalone one. If nothing in the new part of the tree is a runtime prefetch candidate, the head is fetched during the navigation instead. This makes the scheduler's metadata-only request path dead code, so it's removed. Fixes #95268. <!-- NEXT_JS_LLM_PR -->
34 lines
657 B
TypeScript
34 lines
657 B
TypeScript
'use client'
|
|
|
|
import Link, { type LinkProps } from 'next/link'
|
|
import { useState } from 'react'
|
|
|
|
export function LinkAccordion({
|
|
href,
|
|
children,
|
|
prefetch,
|
|
}: {
|
|
href: string
|
|
children: React.ReactNode
|
|
prefetch?: LinkProps['prefetch']
|
|
}) {
|
|
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)`
|
|
)}
|
|
</>
|
|
)
|
|
}
|