UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

1 lines 2.58 kB
{"version":3,"file":"HeadContent.dev.cjs","names":["MetaProvider","For","createEffect","createMemo","Asset","useHydrated","useTags","DEV_STYLES_ATTR","HeadContent","tags","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'\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() {\n const tags = useTags()\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":";;;;;;;;AAMA,IAAMO,kBAAkB;;;;;;;;;;AAWxB,SAAgBC,cAAc;CAC5B,MAAMC,OAAOH,yBAAAA,SAAS;CACtB,MAAMI,WAAWL,mBAAAA,aAAa;AAI9BH,EAAAA,GAAAA,SAAAA,oBAAmB;AACjB,MAAIQ,UAAU,CACZC,UACGC,iBAAiB,QAAQL,gBAAe,GAAI,CAC5CM,SAASC,OAAOA,GAAGC,QAAQ,CAAC;GAEjC;CAGF,MAAMC,gBAAAA,GAAAA,SAAAA,kBAAgC;AACpC,MAAIN,UAAU,CACZ,QAAOD,MAAM,CAACQ,QAAQC,QAAQ,CAACA,IAAIC,QAAQZ,iBAAiB;AAE9D,SAAOE,MAAM;GACb;AAEF,SAAA,GAAA,aAAA,iBACGT,cAAAA,cAAY,EAAA,IAAAqB,WAAA;AAAA,UAAA,GAAA,aAAA,iBACVpB,SAAAA,KAAG;GAAA,IAACqB,OAAI;AAAA,WAAEN,cAAc;;GAAAK,WAAIH,SAAAA,GAAAA,aAAAA,iBAASd,cAAAA,OAAUc,IAAG;GAAI,CAAA;IAAA,CAAA"}