@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
1 lines • 2.75 kB
Source Map (JSON)
{"version":3,"file":"HeadContent.dev.cjs","names":["MetaProvider","For","createEffect","createMemo","Asset","useHydrated","useTags","HeadContentProps","DEV_STYLES_ATTR","HeadContent","props","tags","assetCrossOrigin","hydrated","document","querySelectorAll","forEach","el","remove","filteredTags","filter","tag","attrs","_$createComponent","children","each"],"sources":["../../src/HeadContent.dev.tsx"],"sourcesContent":["import { MetaProvider } from '@solidjs/meta'\nimport { For, createEffect, createMemo } from 'solid-js'\nimport { Asset } from './Asset'\nimport { useHydrated } from './ClientOnly'\nimport { useTags } from './headContentUtils'\nimport type { HeadContentProps } from './HeadContent'\n\nconst DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'\n\n/**\n * @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.\n * When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`\n * to ensure it's part of the reactive tree and updates correctly during client-side navigation.\n * The component uses portals internally to render content into the `<head>` element.\n *\n * Development version: filters out dev styles link after hydration and\n * includes a fallback cleanup effect for hydration mismatch cases.\n */\nexport function HeadContent(props: HeadContentProps) {\n const tags = useTags(props.assetCrossOrigin)\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 createEffect(() => {\n if (hydrated()) {\n document\n .querySelectorAll(`link[${DEV_STYLES_ATTR}]`)\n .forEach((el) => el.remove())\n }\n })\n\n // Filter out dev styles after hydration\n const filteredTags = createMemo(() => {\n if (hydrated()) {\n return tags().filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])\n }\n return tags()\n })\n\n return (\n <MetaProvider>\n <For each={filteredTags()}>{(tag) => <Asset {...tag} />}</For>\n </MetaProvider>\n )\n}\n"],"mappings":";;;;;;;;AAOA,IAAMQ,kBAAkB;;;;;;;;;;AAWxB,SAAgBC,YAAYC,OAAyB;CACnD,MAAMC,OAAOL,yBAAAA,QAAQI,MAAME,iBAAiB;CAC5C,MAAMC,WAAWR,mBAAAA,aAAa;AAI9BH,EAAAA,GAAAA,SAAAA,oBAAmB;AACjB,MAAIW,UAAU,CACZC,UACGC,iBAAiB,QAAQP,gBAAe,GAAI,CAC5CQ,SAASC,OAAOA,GAAGC,QAAQ,CAAC;GAEjC;CAGF,MAAMC,gBAAAA,GAAAA,SAAAA,kBAAgC;AACpC,MAAIN,UAAU,CACZ,QAAOF,MAAM,CAACS,QAAQC,QAAQ,CAACA,IAAIC,QAAQd,iBAAiB;AAE9D,SAAOG,MAAM;GACb;AAEF,SAAA,GAAA,aAAA,iBACGX,cAAAA,cAAY,EAAA,IAAAwB,WAAA;AAAA,UAAA,GAAA,aAAA,iBACVvB,SAAAA,KAAG;GAAA,IAACwB,OAAI;AAAA,WAAEN,cAAc;;GAAAK,WAAIH,SAAAA,GAAAA,aAAAA,iBAASjB,cAAAA,OAAUiB,IAAG;GAAI,CAAA;IAAA,CAAA"}