UNPKG

@tanstack/react-router

Version:

Modern and scalable routing for React applications

1 lines • 2.39 kB
{"version":3,"file":"HeadContent.dev.cjs","names":["useTags","useRouter","useHydrated","DEV_STYLES_ATTR","_Fragment","Asset"],"sources":["../../src/HeadContent.dev.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { DEV_STYLES_ATTR } from '@tanstack/router-core'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport { useTags } from './headContentUtils'\nimport type { HeadContentProps } from './HeadContent'\n\n/**\n * Render route-managed head tags (title, meta, links, styles, head scripts).\n * Place inside the document head of your app shell.\n *\n * Development version: filters out dev styles link after hydration and\n * includes a fallback cleanup effect for hydration mismatch cases.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management\n */\nexport function HeadContent(props: HeadContentProps) {\n const tags = useTags(props.assetCrossOrigin)\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n const hydrated = useHydrated()\n\n // Fallback cleanup for hydration mismatch cases\n // Runs when hydration completes to remove any orphaned dev styles links from DOM\n React.useEffect(() => {\n if (hydrated) {\n document\n .querySelectorAll(`link[${DEV_STYLES_ATTR}]`)\n .forEach((el) => el.remove())\n }\n }, [hydrated])\n\n // Filter out dev styles after hydration\n const filteredTags = hydrated\n ? tags.filter(\n (tag) => tag.tag !== 'link' || tag.attrs?.[DEV_STYLES_ATTR] !== true,\n )\n : tags\n\n return (\n <>\n {filteredTags.map((tag) => (\n <Asset {...tag} key={`tsr-meta-${JSON.stringify(tag)}`} nonce={nonce} />\n ))}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,YAAY,OAAyB;CACnD,MAAM,OAAOA,yBAAAA,QAAQ,MAAM,gBAAgB;CAE3C,MAAM,QADSC,kBAAAA,UACD,CAAA,CAAO,QAAQ,KAAK;CAClC,MAAM,WAAWC,mBAAAA,YAAY;CAI7B,MAAM,gBAAgB;EACpB,IAAI,UACF,SACG,iBAAiB,QAAQC,sBAAAA,gBAAgB,EAAE,CAAC,CAC5C,SAAS,OAAO,GAAG,OAAO,CAAC;CAElC,GAAG,CAAC,QAAQ,CAAC;CAGb,MAAM,eAAe,WACjB,KAAK,QACF,QAAQ,IAAI,QAAQ,UAAU,IAAI,QAAQA,sBAAAA,qBAAqB,IAClE,IACA;CAEJ,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAAC,kBAAAA,UAAA,EAAA,UACG,aAAa,KAAK,QACjB,iBAAA,GAAA,MAAA,cAAA,CAACC,cAAAA,OAAD;EAAO,GAAI;EAAK,KAAK,YAAY,KAAK,UAAU,GAAG;EAAY;CAAQ,CAAA,CACxE,EACD,CAAA;AAEN"}