Files
SnowLuma/.pnpm-store/v11/files/95/e5510fb7aea7aa54aa4c4beb1a2bfe716458f8154937cb3bdfc8ca1e6d2154fc1abc989cec779bc570b05fc225c1def315aa70cb9c1bafdaefb2db7e7eee50
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

50 lines
1.5 KiB
Plaintext

'use client'
import * as React from 'react'
import { Asset } from './Asset'
import { useRouter } from './useRouter'
import { useHydrated } from './ClientOnly'
import { useTags } from './headContentUtils'
import type { HeadContentProps } from './HeadContent'
const DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'
/**
* Render route-managed head tags (title, meta, links, styles, head scripts).
* Place inside the document head of your app shell.
*
* Development version: filters out dev styles link after hydration and
* includes a fallback cleanup effect for hydration mismatch cases.
*
* @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management
*/
export function HeadContent(props: HeadContentProps) {
const tags = useTags(props.assetCrossOrigin)
const router = useRouter()
const nonce = router.options.ssr?.nonce
const hydrated = useHydrated()
// Fallback cleanup for hydration mismatch cases
// Runs when hydration completes to remove any orphaned dev styles links from DOM
React.useEffect(() => {
if (hydrated) {
document
.querySelectorAll(`link[${DEV_STYLES_ATTR}]`)
.forEach((el) => el.remove())
}
}, [hydrated])
// Filter out dev styles after hydration
const filteredTags = hydrated
? tags.filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])
: tags
return (
<>
{filteredTags.map((tag) => (
<Asset {...tag} key={`tsr-meta-${JSON.stringify(tag)}`} nonce={nonce} />
))}
</>
)
}