Skip to content

Commit 9eaa09e

Browse files
committed
Get @solidjs/meta working
1 parent 7ac5ef3 commit 9eaa09e

File tree

7 files changed

+67
-24
lines changed

7 files changed

+67
-24
lines changed

packages/solid-router/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"dependencies": {
7373
"@solid-devtools/logger": "^0.9.4",
7474
"@solid-primitives/refs": "^1.0.8",
75+
"@solidjs/meta": "^0.29.4",
7576
"@tanstack/history": "workspace:*",
7677
"@tanstack/router-core": "workspace:*",
7778
"@tanstack/solid-store": "^0.7.0",

packages/solid-router/src/Asset.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { Meta, Style, Title } from '@solidjs/meta'
12
import type { RouterManagedTag } from '@tanstack/router-core'
23

34
export function Asset({ tag, attrs, children }: RouterManagedTag): any {
45
switch (tag) {
56
case 'title':
6-
return <title {...attrs}>{children}</title>
7+
return <Title {...attrs}>{children}</Title>
78
case 'meta':
8-
return <meta {...attrs} />
9+
return <Meta {...attrs} />
910
case 'link':
1011
return <link {...attrs} />
1112
case 'style':
12-
return <style {...attrs} innerHTML={children} />
13+
return <Style {...attrs} innerHTML={children} />
1314
case 'script':
1415
if ((attrs as any) && (attrs as any).src) {
1516
return <script {...attrs} />

packages/solid-router/src/HeadContent.tsx

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Solid from 'solid-js'
22
import { useAssets } from 'solid-js/web'
3+
import { MetaProvider } from '@solidjs/meta'
34
import { Asset } from './Asset'
45
import { useRouter } from './useRouter'
56
import { useRouterState } from './useRouterState'
@@ -56,7 +57,7 @@ export const useTags = () => {
5657
resultMeta.reverse()
5758

5859
return resultMeta
59-
}, [routeMeta])
60+
})
6061

6162
const links = useRouterState({
6263
select: (state) =>
@@ -112,17 +113,18 @@ export const useTags = () => {
112113
})),
113114
})
114115

115-
return uniqBy(
116-
[
117-
...meta(),
118-
...preloadMeta(),
119-
...links(),
120-
...headScripts(),
121-
] as Array<RouterManagedTag>,
122-
(d) => {
123-
return JSON.stringify(d)
124-
},
125-
)
116+
return () =>
117+
uniqBy(
118+
[
119+
...meta(),
120+
...preloadMeta(),
121+
...links(),
122+
...headScripts(),
123+
] as Array<RouterManagedTag>,
124+
(d) => {
125+
return JSON.stringify(d)
126+
},
127+
)
126128
}
127129

128130
/**
@@ -131,12 +133,26 @@ export const useTags = () => {
131133
*/
132134
export function HeadContent() {
133135
const tags = useTags()
134-
return tags.map((tag) => <Asset {...tag} />)
136+
return (
137+
<MetaProvider>
138+
{tags().map((tag) => (
139+
<Asset {...tag} />
140+
))}
141+
</MetaProvider>
142+
)
135143
}
136144

137145
export function ServerHeadContent() {
138146
const tags = useTags()
139-
useAssets(() => tags.map((tag) => <Asset {...tag} />))
147+
useAssets(() => {
148+
return (
149+
<MetaProvider>
150+
{tags().map((tag) => (
151+
<Asset {...tag} />
152+
))}
153+
</MetaProvider>
154+
)
155+
})
140156
return null
141157
}
142158

packages/solid-start-client/src/StartClient.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Await, RouterProvider } from '@tanstack/solid-router'
1+
import { Await, HeadContent, RouterProvider } from '@tanstack/solid-router'
22
import { hydrate } from './ssr-client'
33
import type { AnyRouter } from '@tanstack/solid-router'
44
import type { JSXElement } from 'solid-js'
@@ -25,7 +25,10 @@ export function StartClient(props: { router: AnyRouter }) {
2525
router={props.router}
2626
InnerWrap={(props) => (
2727
<Dummy>
28-
<Dummy>{props.children}</Dummy>
28+
<Dummy>
29+
<HeadContent />
30+
{props.children}
31+
</Dummy>
2932
<Dummy />
3033
</Dummy>
3134
)}

packages/solid-start-server/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"node": ">=12"
6363
},
6464
"dependencies": {
65+
"@solidjs/meta": "^0.29.4",
6566
"@tanstack/history": "workspace:^",
6667
"@tanstack/router-core": "workspace:^",
6768
"@tanstack/solid-router": "workspace:^",
@@ -73,11 +74,11 @@
7374
"unctx": "^2.4.1"
7475
},
7576
"devDependencies": {
76-
"vite-plugin-solid": "^2.11.2",
7777
"@types/jsesc": "^3.0.3",
7878
"esbuild": "^0.25.0",
7979
"solid-js": "^1.0.0",
80-
"typescript": "^5.7.2"
80+
"typescript": "^5.7.2",
81+
"vite-plugin-solid": "^2.11.2"
8182
},
8283
"peerDependencies": {
8384
"solid-js": "^1.0.0"

packages/solid-start-server/src/StartServer.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@tanstack/solid-router'
66
import { Hydration, HydrationScript, NoHydration, ssr } from 'solid-js/web'
77
import type { AnyRouter } from '@tanstack/solid-router'
8+
import { MetaProvider, Title } from '@solidjs/meta'
89

910
const docType = ssr('<!DOCTYPE html>')
1011

@@ -24,9 +25,11 @@ export function StartServer<TRouter extends AnyRouter>(props: {
2425
router={props.router}
2526
InnerWrap={(props) => (
2627
<NoHydration>
27-
<ServerHeadContent />
28-
<Hydration>{props.children}</Hydration>
29-
<Scripts />
28+
<MetaProvider>
29+
<ServerHeadContent />
30+
<Hydration>{props.children}</Hydration>
31+
<Scripts />
32+
</MetaProvider>
3033
</NoHydration>
3134
)}
3235
/>

pnpm-lock.yaml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)