diff --git a/e2e/solid-start/server-routes/src/routes/__root.tsx b/e2e/solid-start/server-routes/src/routes/__root.tsx
index d12851644b..331541c1ec 100644
--- a/e2e/solid-start/server-routes/src/routes/__root.tsx
+++ b/e2e/solid-start/server-routes/src/routes/__root.tsx
@@ -35,9 +35,9 @@ function RootComponent() {
diff --git a/e2e/solid-start/spa-mode/src/routes/__root.tsx b/e2e/solid-start/spa-mode/src/routes/__root.tsx
index 02006e04e7..13b820d0cf 100644
--- a/e2e/solid-start/spa-mode/src/routes/__root.tsx
+++ b/e2e/solid-start/spa-mode/src/routes/__root.tsx
@@ -72,9 +72,9 @@ function RootDocument({ children }: { children: Solid.JSX.Element }) {
SPA Mode E2E Test
+
-
diff --git a/packages/solid-router/package.json b/packages/solid-router/package.json
index f667eb3665..dcd1997fbe 100644
--- a/packages/solid-router/package.json
+++ b/packages/solid-router/package.json
@@ -100,7 +100,6 @@
"dependencies": {
"@solid-devtools/logger": "^0.9.4",
"@solid-primitives/refs": "^1.0.8",
- "@solidjs/meta": "^0.29.4",
"@tanstack/history": "workspace:*",
"@tanstack/router-core": "workspace:*",
"@tanstack/solid-store": "0.7.0",
diff --git a/packages/solid-router/src/Asset.tsx b/packages/solid-router/src/Asset.tsx
index 7e7a758428..0ba92b4c1b 100644
--- a/packages/solid-router/src/Asset.tsx
+++ b/packages/solid-router/src/Asset.tsx
@@ -1,5 +1,4 @@
-import { Link, Meta, Style, Title } from '@solidjs/meta'
-import { onCleanup, onMount } from 'solid-js'
+import { onMount, onCleanup } from 'solid-js'
import { useRouter } from './useRouter'
import type { RouterManagedTag } from '@tanstack/router-core'
import type { JSX } from 'solid-js'
@@ -8,18 +7,19 @@ export function Asset({
tag,
attrs,
children,
-}: RouterManagedTag): JSX.Element | null {
+ nonce,
+}: RouterManagedTag & { nonce?: string }): JSX.Element | null {
switch (tag) {
case 'title':
- return
{children}
+ return
{children}
case 'meta':
- return
+ return
case 'link':
- return
+ return
case 'style':
- return
+ return
case 'script':
- return
+ return
default:
return null
}
@@ -28,17 +28,21 @@ export function Asset({
interface ScriptAttrs {
[key: string]: string | boolean | undefined
src?: string
+ nonce?: string
}
function Script({
attrs,
children,
+ nonce,
}: {
attrs?: ScriptAttrs
children?: string
+ nonce?: string
}): JSX.Element | null {
const router = useRouter()
+ // Use onMount for imperative script injection (client-only)
onMount(() => {
if (attrs?.src) {
const normSrc = (() => {
@@ -75,13 +79,14 @@ function Script({
script.parentNode.removeChild(script)
}
})
+
+ return
}
if (typeof children === 'string') {
const typeAttr =
typeof attrs?.type === 'string' ? attrs.type : 'text/javascript'
- const nonceAttr =
- typeof attrs?.nonce === 'string' ? attrs.nonce : undefined
+ const nonceAttr = nonce || (typeof attrs?.nonce === 'string' ? attrs.nonce : undefined)
const existingScript = Array.from(
document.querySelectorAll('script:not([src])'),
).find((el) => {
@@ -113,6 +118,10 @@ function Script({
}
}
+ if (nonceAttr) {
+ script.setAttribute('nonce', nonceAttr)
+ }
+
document.head.appendChild(script)
onCleanup(() => {
@@ -123,17 +132,17 @@ function Script({
}
})
- if (router && !router.isServer) {
- return null
+ // On server, render script tags for SSR
+ if (router.isServer) {
+ if (attrs?.src && typeof attrs.src === 'string') {
+ return
+ }
+
+ if (typeof children === 'string') {
+ return
+ }
}
- if (attrs?.src && typeof attrs.src === 'string') {
- return
- }
-
- if (typeof children === 'string') {
- return
- }
-
- return null
+ // On client, return empty fragment so createEffect runs
+ return <>>
}
diff --git a/packages/solid-router/src/HeadContent.tsx b/packages/solid-router/src/HeadContent.tsx
index 3487fb0c3e..48be4fdf71 100644
--- a/packages/solid-router/src/HeadContent.tsx
+++ b/packages/solid-router/src/HeadContent.tsx
@@ -1,5 +1,4 @@
import * as Solid from 'solid-js'
-import { MetaProvider } from '@solidjs/meta'
import { For } from 'solid-js'
import { Asset } from './Asset'
import { useRouter } from './useRouter'
@@ -183,17 +182,21 @@ export const useTags = () => {
/**
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
- * When using full document hydration (hydrating from ``), this component should be rendered in the ``
- * to ensure it's part of the reactive tree and updates correctly during client-side navigation.
- * The component uses portals internally to render content into the `` element.
+ * It should be rendered in the `` of your document.
+ */
+/**
+ * Render route-managed head tags (title, meta, links, styles, head scripts).
+ * Place inside the document head of your app shell.
+ * @link https://tanstack.com/router/latest/docs/framework/solid/guide/document-head-management
*/
export function HeadContent() {
const tags = useTags()
-
+ const router = useRouter()
+ const nonce = router.options.ssr?.nonce
return (
-
- {(tag) => }
-
+
+ {(tag) => }
+
)
}
diff --git a/packages/solid-router/src/ssr/RouterServer.tsx b/packages/solid-router/src/ssr/RouterServer.tsx
index 99b4e684bb..5004ac4405 100644
--- a/packages/solid-router/src/ssr/RouterServer.tsx
+++ b/packages/solid-router/src/ssr/RouterServer.tsx
@@ -1,60 +1,8 @@
-import {
- Hydration,
- HydrationScript,
- NoHydration,
- ssr,
- useAssets,
-} from 'solid-js/web'
-import { MetaProvider } from '@solidjs/meta'
-import { Asset } from '../Asset'
-import { useTags } from '../HeadContent'
import { RouterProvider } from '../RouterProvider'
-import { Scripts } from '../Scripts'
import type { AnyRouter } from '@tanstack/router-core'
-export function ServerHeadContent() {
- const tags = useTags()
- useAssets(() => {
- return (
-
- {tags().map((tag) => (
-
- ))}
-
- )
- })
- return null
-}
-
-const docType = ssr('')
-
export function RouterServer
(props: {
router: TRouter
}) {
- return (
-
- {docType as any}
-
-
-
-
-
-
- (
-
-
-
- {props.children}
-
-
-
- )}
- />
-
-
-
-
- )
+ return
}
diff --git a/packages/solid-start-server/package.json b/packages/solid-start-server/package.json
index 64c7cca8ad..70089c42d5 100644
--- a/packages/solid-start-server/package.json
+++ b/packages/solid-start-server/package.json
@@ -58,7 +58,6 @@
"node": ">=22.12.0"
},
"dependencies": {
- "@solidjs/meta": "^0.29.4",
"@tanstack/history": "workspace:*",
"@tanstack/router-core": "workspace:*",
"@tanstack/solid-router": "workspace:*",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e368064e9d..64e33b7a90 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -8118,9 +8118,6 @@ importers:
'@solid-primitives/refs':
specifier: ^1.0.8
version: 1.1.0(solid-js@1.9.9)
- '@solidjs/meta':
- specifier: ^0.29.4
- version: 0.29.4(solid-js@1.9.9)
'@tanstack/history':
specifier: workspace:*
version: link:../history
@@ -8273,9 +8270,6 @@ importers:
packages/solid-start-server:
dependencies:
- '@solidjs/meta':
- specifier: ^0.29.4
- version: 0.29.4(solid-js@1.9.9)
'@tanstack/history':
specifier: workspace:*
version: link:../history
@@ -12179,11 +12173,6 @@ packages:
peerDependencies:
solid-js: 1.9.9
- '@solidjs/meta@0.29.4':
- resolution: {integrity: sha512-zdIWBGpR9zGx1p1bzIPqF5Gs+Ks/BH8R6fWhmUa/dcK1L2rUC8BAcZJzNRYBQv74kScf1TSOs0EY//Vd/I0V8g==}
- peerDependencies:
- solid-js: 1.9.9
-
'@solidjs/testing-library@0.8.10':
resolution: {integrity: sha512-qdeuIerwyq7oQTIrrKvV0aL9aFeuwTd86VYD3afdq5HYEwoox1OBTJy4y8A3TFZr8oAR0nujYgCzY/8wgHGfeQ==}
engines: {node: '>= 14'}
@@ -22930,10 +22919,6 @@ snapshots:
dependencies:
solid-js: 1.9.9
- '@solidjs/meta@0.29.4(solid-js@1.9.9)':
- dependencies:
- solid-js: 1.9.9
-
'@solidjs/testing-library@0.8.10(solid-js@1.9.9)':
dependencies:
'@testing-library/dom': 10.4.1