@tanstack/solid-router 1.147.0 → 1.147.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/HeadContent.cjs +5 -195
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/HeadContent.d.cts +1 -4
- package/dist/cjs/HeadContent.dev.cjs +36 -0
- package/dist/cjs/HeadContent.dev.cjs.map +1 -0
- package/dist/cjs/HeadContent.dev.d.cts +10 -0
- package/dist/cjs/headContentUtils.cjs +174 -0
- package/dist/cjs/headContentUtils.cjs.map +1 -0
- package/dist/cjs/headContentUtils.d.cts +7 -0
- package/dist/cjs/index.cjs +2 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/cjs/index.dev.cjs +259 -0
- package/dist/cjs/index.dev.cjs.map +1 -0
- package/dist/cjs/index.dev.d.cts +2 -0
- package/dist/cjs/ssr/RouterServer.cjs +2 -2
- package/dist/cjs/ssr/RouterServer.cjs.map +1 -1
- package/dist/esm/HeadContent.d.ts +1 -4
- package/dist/esm/HeadContent.dev.d.ts +10 -0
- package/dist/esm/HeadContent.dev.js +36 -0
- package/dist/esm/HeadContent.dev.js.map +1 -0
- package/dist/esm/HeadContent.js +6 -180
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/headContentUtils.d.ts +7 -0
- package/dist/esm/headContentUtils.js +157 -0
- package/dist/esm/headContentUtils.js.map +1 -0
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.dev.d.ts +2 -0
- package/dist/esm/index.dev.js +142 -0
- package/dist/esm/index.dev.js.map +1 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ssr/RouterServer.js +1 -1
- package/dist/esm/ssr/RouterServer.js.map +1 -1
- package/dist/source/HeadContent.d.ts +1 -4
- package/dist/source/HeadContent.dev.d.ts +10 -0
- package/dist/source/HeadContent.dev.jsx +39 -0
- package/dist/source/HeadContent.dev.jsx.map +1 -0
- package/dist/source/HeadContent.jsx +2 -202
- package/dist/source/HeadContent.jsx.map +1 -1
- package/dist/source/headContentUtils.d.ts +7 -0
- package/dist/source/headContentUtils.jsx +181 -0
- package/dist/source/headContentUtils.jsx.map +1 -0
- package/dist/source/index.d.ts +2 -1
- package/dist/source/index.dev.d.ts +2 -0
- package/dist/source/index.dev.jsx +6 -0
- package/dist/source/index.dev.jsx.map +1 -0
- package/dist/source/index.jsx +2 -1
- package/dist/source/index.jsx.map +1 -1
- package/dist/source/ssr/RouterServer.jsx +1 -1
- package/dist/source/ssr/RouterServer.jsx.map +1 -1
- package/package.json +5 -2
- package/src/HeadContent.dev.tsx +45 -0
- package/src/HeadContent.tsx +2 -236
- package/src/headContentUtils.tsx +209 -0
- package/src/index.dev.tsx +6 -0
- package/src/index.tsx +2 -1
- package/src/ssr/RouterServer.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeadContent.jsx","sourceRoot":"","sources":["../../src/HeadContent.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"HeadContent.jsx","sourceRoot":"","sources":["../../src/HeadContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,IAAI,GAAG,OAAO,EAAE,CAAA;IAEtB,OAAO,CACL,CAAC,YAAY,CACX;MAAA,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAG,CAAC,EAAE,GAAG,CACvD;IAAA,EAAE,YAAY,CAAC,CAChB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RouterManagedTag } from '@tanstack/router-core';
|
|
2
|
+
/**
|
|
3
|
+
* Build the list of head/link/meta/script tags to render for active matches.
|
|
4
|
+
* Used internally by `HeadContent`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useTags: () => () => RouterManagedTag[];
|
|
7
|
+
export declare function uniqBy<T>(arr: Array<T>, fn: (item: T) => string): T[];
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as Solid from 'solid-js';
|
|
2
|
+
import { escapeHtml } from '@tanstack/router-core';
|
|
3
|
+
import { useRouter } from './useRouter';
|
|
4
|
+
import { useRouterState } from './useRouterState';
|
|
5
|
+
/**
|
|
6
|
+
* Build the list of head/link/meta/script tags to render for active matches.
|
|
7
|
+
* Used internally by `HeadContent`.
|
|
8
|
+
*/
|
|
9
|
+
export const useTags = () => {
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const nonce = router.options.ssr?.nonce;
|
|
12
|
+
const routeMeta = useRouterState({
|
|
13
|
+
select: (state) => {
|
|
14
|
+
return state.matches.map((match) => match.meta).filter(Boolean);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const meta = Solid.createMemo(() => {
|
|
18
|
+
const resultMeta = [];
|
|
19
|
+
const metaByAttribute = {};
|
|
20
|
+
let title;
|
|
21
|
+
const routeMetasArray = routeMeta();
|
|
22
|
+
for (let i = routeMetasArray.length - 1; i >= 0; i--) {
|
|
23
|
+
const metas = routeMetasArray[i];
|
|
24
|
+
for (let j = metas.length - 1; j >= 0; j--) {
|
|
25
|
+
const m = metas[j];
|
|
26
|
+
if (!m)
|
|
27
|
+
continue;
|
|
28
|
+
if (m.title) {
|
|
29
|
+
if (!title) {
|
|
30
|
+
title = {
|
|
31
|
+
tag: 'title',
|
|
32
|
+
children: m.title,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if ('script:ld+json' in m) {
|
|
37
|
+
// Handle JSON-LD structured data
|
|
38
|
+
// Content is HTML-escaped to prevent XSS when injected via innerHTML
|
|
39
|
+
try {
|
|
40
|
+
const json = JSON.stringify(m['script:ld+json']);
|
|
41
|
+
resultMeta.push({
|
|
42
|
+
tag: 'script',
|
|
43
|
+
attrs: {
|
|
44
|
+
type: 'application/ld+json',
|
|
45
|
+
},
|
|
46
|
+
children: escapeHtml(json),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Skip invalid JSON-LD objects
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const attribute = m.name ?? m.property;
|
|
55
|
+
if (attribute) {
|
|
56
|
+
if (metaByAttribute[attribute]) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
metaByAttribute[attribute] = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
resultMeta.push({
|
|
64
|
+
tag: 'meta',
|
|
65
|
+
attrs: {
|
|
66
|
+
...m,
|
|
67
|
+
nonce,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (title) {
|
|
74
|
+
resultMeta.push(title);
|
|
75
|
+
}
|
|
76
|
+
if (router.options.ssr?.nonce) {
|
|
77
|
+
resultMeta.push({
|
|
78
|
+
tag: 'meta',
|
|
79
|
+
attrs: {
|
|
80
|
+
property: 'csp-nonce',
|
|
81
|
+
content: router.options.ssr.nonce,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
resultMeta.reverse();
|
|
86
|
+
return resultMeta;
|
|
87
|
+
});
|
|
88
|
+
const links = useRouterState({
|
|
89
|
+
select: (state) => {
|
|
90
|
+
const constructed = state.matches
|
|
91
|
+
.map((match) => match.links)
|
|
92
|
+
.filter(Boolean)
|
|
93
|
+
.flat(1)
|
|
94
|
+
.map((link) => ({
|
|
95
|
+
tag: 'link',
|
|
96
|
+
attrs: {
|
|
97
|
+
...link,
|
|
98
|
+
nonce,
|
|
99
|
+
},
|
|
100
|
+
}));
|
|
101
|
+
const manifest = router.ssr?.manifest;
|
|
102
|
+
const assets = state.matches
|
|
103
|
+
.map((match) => manifest?.routes[match.routeId]?.assets ?? [])
|
|
104
|
+
.filter(Boolean)
|
|
105
|
+
.flat(1)
|
|
106
|
+
.filter((asset) => asset.tag === 'link')
|
|
107
|
+
.map((asset) => ({
|
|
108
|
+
tag: 'link',
|
|
109
|
+
attrs: { ...asset.attrs, nonce },
|
|
110
|
+
}));
|
|
111
|
+
return [...constructed, ...assets];
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const preloadLinks = useRouterState({
|
|
115
|
+
select: (state) => {
|
|
116
|
+
const preloadLinks = [];
|
|
117
|
+
state.matches
|
|
118
|
+
.map((match) => router.looseRoutesById[match.routeId])
|
|
119
|
+
.forEach((route) => router.ssr?.manifest?.routes[route.id]?.preloads
|
|
120
|
+
?.filter(Boolean)
|
|
121
|
+
.forEach((preload) => {
|
|
122
|
+
preloadLinks.push({
|
|
123
|
+
tag: 'link',
|
|
124
|
+
attrs: {
|
|
125
|
+
rel: 'modulepreload',
|
|
126
|
+
href: preload,
|
|
127
|
+
nonce,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}));
|
|
131
|
+
return preloadLinks;
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const styles = useRouterState({
|
|
135
|
+
select: (state) => state.matches
|
|
136
|
+
.map((match) => match.styles)
|
|
137
|
+
.flat(1)
|
|
138
|
+
.filter(Boolean).map(({ children, ...style }) => ({
|
|
139
|
+
tag: 'style',
|
|
140
|
+
attrs: {
|
|
141
|
+
...style,
|
|
142
|
+
nonce,
|
|
143
|
+
},
|
|
144
|
+
children,
|
|
145
|
+
})),
|
|
146
|
+
});
|
|
147
|
+
const headScripts = useRouterState({
|
|
148
|
+
select: (state) => state.matches
|
|
149
|
+
.map((match) => match.headScripts)
|
|
150
|
+
.flat(1)
|
|
151
|
+
.filter(Boolean).map(({ children, ...script }) => ({
|
|
152
|
+
tag: 'script',
|
|
153
|
+
attrs: {
|
|
154
|
+
...script,
|
|
155
|
+
nonce,
|
|
156
|
+
},
|
|
157
|
+
children,
|
|
158
|
+
})),
|
|
159
|
+
});
|
|
160
|
+
return () => uniqBy([
|
|
161
|
+
...meta(),
|
|
162
|
+
...preloadLinks(),
|
|
163
|
+
...links(),
|
|
164
|
+
...styles(),
|
|
165
|
+
...headScripts(),
|
|
166
|
+
], (d) => {
|
|
167
|
+
return JSON.stringify(d);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
export function uniqBy(arr, fn) {
|
|
171
|
+
const seen = new Set();
|
|
172
|
+
return arr.filter((item) => {
|
|
173
|
+
const key = fn(item);
|
|
174
|
+
if (seen.has(key)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
seen.add(key);
|
|
178
|
+
return true;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=headContentUtils.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headContentUtils.jsx","sourceRoot":"","sources":["../../src/headContentUtils.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,EAAE;IAC1B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAA;IACvC,MAAM,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;SACT,CAAC,CAAC;KACN,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE,CACV,MAAM,CACJ;QACE,GAAG,IAAI,EAAE;QACT,GAAG,YAAY,EAAE;QACjB,GAAG,KAAK,EAAE;QACV,GAAG,MAAM,EAAE;QACX,GAAG,WAAW,EAAE;KACU,EAC5B,CAAC,CAAC,EAAE,EAAE;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC,CACF,CAAA;AACL,CAAC,CAAA;AAED,MAAM,UAAU,MAAM,CAAI,GAAa,EAAE,EAAuB;IAC9D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAA;IAC9B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QACpB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACb,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/source/index.d.ts
CHANGED
|
@@ -45,7 +45,8 @@ export type { ValidateLinkOptions, ValidateUseSearchOptions, ValidateUseParamsOp
|
|
|
45
45
|
export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, } from '@tanstack/router-core';
|
|
46
46
|
export { ScriptOnce } from './ScriptOnce';
|
|
47
47
|
export { Asset } from './Asset';
|
|
48
|
-
export { HeadContent
|
|
48
|
+
export { HeadContent } from './HeadContent';
|
|
49
|
+
export { useTags } from './headContentUtils';
|
|
49
50
|
export { Scripts } from './Scripts';
|
|
50
51
|
export { composeRewrites } from '@tanstack/router-core';
|
|
51
52
|
export type { LocationRewrite, LocationRewriteFunction, } from '@tanstack/router-core';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Development entry point - re-exports everything from index.tsx
|
|
2
|
+
// but overrides HeadContent with the dev version that handles
|
|
3
|
+
// dev styles cleanup after hydration
|
|
4
|
+
export * from './index';
|
|
5
|
+
export { HeadContent } from './HeadContent.dev';
|
|
6
|
+
//# sourceMappingURL=index.dev.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.dev.jsx","sourceRoot":"","sources":["../../src/index.dev.tsx"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,8DAA8D;AAC9D,qCAAqC;AAErC,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/source/index.jsx
CHANGED
|
@@ -35,7 +35,8 @@ export { CatchNotFound, DefaultGlobalNotFound } from './not-found';
|
|
|
35
35
|
export { notFound, isNotFound } from '@tanstack/router-core';
|
|
36
36
|
export { ScriptOnce } from './ScriptOnce';
|
|
37
37
|
export { Asset } from './Asset';
|
|
38
|
-
export { HeadContent
|
|
38
|
+
export { HeadContent } from './HeadContent';
|
|
39
|
+
export { useTags } from './headContentUtils';
|
|
39
40
|
export { Scripts } from './Scripts';
|
|
40
41
|
export { composeRewrites } from '@tanstack/router-core';
|
|
41
42
|
//# sourceMappingURL=index.jsx.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.jsx","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,mBA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E,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AA+B5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hydration, HydrationScript, NoHydration, ssr, useAssets, } from 'solid-js/web';
|
|
2
2
|
import { MetaProvider } from '@solidjs/meta';
|
|
3
3
|
import { Asset } from '../Asset';
|
|
4
|
-
import { useTags } from '../
|
|
4
|
+
import { useTags } from '../headContentUtils';
|
|
5
5
|
import { RouterProvider } from '../RouterProvider';
|
|
6
6
|
import { Scripts } from '../Scripts';
|
|
7
7
|
export function ServerHeadContent() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterServer.jsx","sourceRoot":"","sources":["../../../src/ssr/RouterServer.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,GAAG,EACH,SAAS,GACV,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"RouterServer.jsx","sourceRoot":"","sources":["../../../src/ssr/RouterServer.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,GAAG,EACH,SAAS,GACV,MAAM,cAAc,CAAA;AACrB,OAAO,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AAY,CAChB;gBAAA,EAAE,WAAW,CAAC,CACf,CAAC,EAEN;UAAA,EAAE,SAAS,CACb;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,IAAI,CACR;IAAA,EAAE,WAAW,CAAC,CACf,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-router",
|
|
3
|
-
"version": "1.147.
|
|
3
|
+
"version": "1.147.3",
|
|
4
4
|
"description": "Modern and scalable routing for Solid applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,14 +31,17 @@
|
|
|
31
31
|
".": {
|
|
32
32
|
"solid": {
|
|
33
33
|
"types": "./dist/source/index.d.ts",
|
|
34
|
+
"development": "./dist/source/index.dev.jsx",
|
|
34
35
|
"default": "./dist/source/index.jsx"
|
|
35
36
|
},
|
|
36
37
|
"import": {
|
|
37
38
|
"types": "./dist/esm/index.d.ts",
|
|
39
|
+
"development": "./dist/esm/index.dev.js",
|
|
38
40
|
"default": "./dist/esm/index.js"
|
|
39
41
|
},
|
|
40
42
|
"require": {
|
|
41
43
|
"types": "./dist/cjs/index.d.cts",
|
|
44
|
+
"development": "./dist/cjs/index.dev.cjs",
|
|
42
45
|
"default": "./dist/cjs/index.cjs"
|
|
43
46
|
}
|
|
44
47
|
},
|
|
@@ -89,7 +92,7 @@
|
|
|
89
92
|
"tiny-invariant": "^1.3.3",
|
|
90
93
|
"tiny-warning": "^1.0.3",
|
|
91
94
|
"@tanstack/history": "1.145.7",
|
|
92
|
-
"@tanstack/router-core": "1.
|
|
95
|
+
"@tanstack/router-core": "1.147.1"
|
|
93
96
|
},
|
|
94
97
|
"devDependencies": {
|
|
95
98
|
"@solidjs/testing-library": "^0.8.10",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MetaProvider } from '@solidjs/meta'
|
|
2
|
+
import { For, createEffect, createMemo } from 'solid-js'
|
|
3
|
+
import { Asset } from './Asset'
|
|
4
|
+
import { useHydrated } from './ClientOnly'
|
|
5
|
+
import { useTags } from './headContentUtils'
|
|
6
|
+
|
|
7
|
+
const DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
11
|
+
* When using full document hydration (hydrating from `<html>`), this component should be rendered in the `<body>`
|
|
12
|
+
* to ensure it's part of the reactive tree and updates correctly during client-side navigation.
|
|
13
|
+
* The component uses portals internally to render content into the `<head>` element.
|
|
14
|
+
*
|
|
15
|
+
* Development version: filters out dev styles link after hydration and
|
|
16
|
+
* includes a fallback cleanup effect for hydration mismatch cases.
|
|
17
|
+
*/
|
|
18
|
+
export function HeadContent() {
|
|
19
|
+
const tags = useTags()
|
|
20
|
+
const hydrated = useHydrated()
|
|
21
|
+
|
|
22
|
+
// Fallback cleanup for hydration mismatch cases
|
|
23
|
+
// Runs when hydration completes to remove any orphaned dev styles links from DOM
|
|
24
|
+
createEffect(() => {
|
|
25
|
+
if (hydrated()) {
|
|
26
|
+
document
|
|
27
|
+
.querySelectorAll(`link[${DEV_STYLES_ATTR}]`)
|
|
28
|
+
.forEach((el) => el.remove())
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Filter out dev styles after hydration
|
|
33
|
+
const filteredTags = createMemo(() => {
|
|
34
|
+
if (hydrated()) {
|
|
35
|
+
return tags().filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])
|
|
36
|
+
}
|
|
37
|
+
return tags()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<MetaProvider>
|
|
42
|
+
<For each={filteredTags()}>{(tag) => <Asset {...tag} />}</For>
|
|
43
|
+
</MetaProvider>
|
|
44
|
+
)
|
|
45
|
+
}
|
package/src/HeadContent.tsx
CHANGED
|
@@ -1,226 +1,7 @@
|
|
|
1
|
-
import * as Solid from 'solid-js'
|
|
2
1
|
import { MetaProvider } from '@solidjs/meta'
|
|
3
|
-
import { For
|
|
4
|
-
import { escapeHtml } from '@tanstack/router-core'
|
|
2
|
+
import { For } from 'solid-js'
|
|
5
3
|
import { Asset } from './Asset'
|
|
6
|
-
import {
|
|
7
|
-
import { useRouterState } from './useRouterState'
|
|
8
|
-
import type { RouterManagedTag } from '@tanstack/router-core'
|
|
9
|
-
|
|
10
|
-
export const useTags = () => {
|
|
11
|
-
const router = useRouter()
|
|
12
|
-
const nonce = router.options.ssr?.nonce
|
|
13
|
-
const routeMeta = useRouterState({
|
|
14
|
-
select: (state) => {
|
|
15
|
-
return state.matches.map((match) => match.meta!).filter(Boolean)
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const meta: Solid.Accessor<Array<RouterManagedTag>> = Solid.createMemo(() => {
|
|
20
|
-
const resultMeta: Array<RouterManagedTag> = []
|
|
21
|
-
const metaByAttribute: Record<string, true> = {}
|
|
22
|
-
let title: RouterManagedTag | undefined
|
|
23
|
-
const routeMetasArray = routeMeta()
|
|
24
|
-
for (let i = routeMetasArray.length - 1; i >= 0; i--) {
|
|
25
|
-
const metas = routeMetasArray[i]!
|
|
26
|
-
for (let j = metas.length - 1; j >= 0; j--) {
|
|
27
|
-
const m = metas[j]
|
|
28
|
-
if (!m) continue
|
|
29
|
-
|
|
30
|
-
if (m.title) {
|
|
31
|
-
if (!title) {
|
|
32
|
-
title = {
|
|
33
|
-
tag: 'title',
|
|
34
|
-
children: m.title,
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} else if ('script:ld+json' in m) {
|
|
38
|
-
// Handle JSON-LD structured data
|
|
39
|
-
// Content is HTML-escaped to prevent XSS when injected via innerHTML
|
|
40
|
-
try {
|
|
41
|
-
const json = JSON.stringify(m['script:ld+json'])
|
|
42
|
-
resultMeta.push({
|
|
43
|
-
tag: 'script',
|
|
44
|
-
attrs: {
|
|
45
|
-
type: 'application/ld+json',
|
|
46
|
-
},
|
|
47
|
-
children: escapeHtml(json),
|
|
48
|
-
})
|
|
49
|
-
} catch {
|
|
50
|
-
// Skip invalid JSON-LD objects
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
const attribute = m.name ?? m.property
|
|
54
|
-
if (attribute) {
|
|
55
|
-
if (metaByAttribute[attribute]) {
|
|
56
|
-
continue
|
|
57
|
-
} else {
|
|
58
|
-
metaByAttribute[attribute] = true
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
resultMeta.push({
|
|
63
|
-
tag: 'meta',
|
|
64
|
-
attrs: {
|
|
65
|
-
...m,
|
|
66
|
-
nonce,
|
|
67
|
-
},
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (title) {
|
|
74
|
-
resultMeta.push(title)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (router.options.ssr?.nonce) {
|
|
78
|
-
resultMeta.push({
|
|
79
|
-
tag: 'meta',
|
|
80
|
-
attrs: {
|
|
81
|
-
property: 'csp-nonce',
|
|
82
|
-
content: router.options.ssr.nonce,
|
|
83
|
-
},
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
resultMeta.reverse()
|
|
87
|
-
|
|
88
|
-
return resultMeta
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
const links = useRouterState({
|
|
92
|
-
select: (state) => {
|
|
93
|
-
const constructed = state.matches
|
|
94
|
-
.map((match) => match.links!)
|
|
95
|
-
.filter(Boolean)
|
|
96
|
-
.flat(1)
|
|
97
|
-
.map((link) => ({
|
|
98
|
-
tag: 'link',
|
|
99
|
-
attrs: {
|
|
100
|
-
...link,
|
|
101
|
-
nonce,
|
|
102
|
-
},
|
|
103
|
-
})) satisfies Array<RouterManagedTag>
|
|
104
|
-
|
|
105
|
-
const manifest = router.ssr?.manifest
|
|
106
|
-
|
|
107
|
-
// These are the assets extracted from the ViteManifest
|
|
108
|
-
// using the `startManifestPlugin`
|
|
109
|
-
const assets = state.matches
|
|
110
|
-
.map((match) => manifest?.routes[match.routeId]?.assets ?? [])
|
|
111
|
-
.filter(Boolean)
|
|
112
|
-
.flat(1)
|
|
113
|
-
.filter((asset) => asset.tag === 'link')
|
|
114
|
-
.map(
|
|
115
|
-
(asset) =>
|
|
116
|
-
({
|
|
117
|
-
tag: 'link',
|
|
118
|
-
attrs: { ...asset.attrs, nonce },
|
|
119
|
-
}) satisfies RouterManagedTag,
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
return [...constructed, ...assets]
|
|
123
|
-
},
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const preloadLinks = useRouterState({
|
|
127
|
-
select: (state) => {
|
|
128
|
-
const preloadLinks: Array<RouterManagedTag> = []
|
|
129
|
-
|
|
130
|
-
state.matches
|
|
131
|
-
.map((match) => router.looseRoutesById[match.routeId]!)
|
|
132
|
-
.forEach((route) =>
|
|
133
|
-
router.ssr?.manifest?.routes[route.id]?.preloads
|
|
134
|
-
?.filter(Boolean)
|
|
135
|
-
.forEach((preload) => {
|
|
136
|
-
preloadLinks.push({
|
|
137
|
-
tag: 'link',
|
|
138
|
-
attrs: {
|
|
139
|
-
rel: 'modulepreload',
|
|
140
|
-
href: preload,
|
|
141
|
-
nonce,
|
|
142
|
-
},
|
|
143
|
-
})
|
|
144
|
-
}),
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
return preloadLinks
|
|
148
|
-
},
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
const styles = useRouterState({
|
|
152
|
-
select: (state) =>
|
|
153
|
-
(
|
|
154
|
-
state.matches
|
|
155
|
-
.map((match) => match.styles!)
|
|
156
|
-
.flat(1)
|
|
157
|
-
.filter(Boolean) as Array<RouterManagedTag>
|
|
158
|
-
).map(({ children, ...style }) => ({
|
|
159
|
-
tag: 'style',
|
|
160
|
-
attrs: {
|
|
161
|
-
...style,
|
|
162
|
-
nonce,
|
|
163
|
-
},
|
|
164
|
-
children,
|
|
165
|
-
})),
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
const headScripts = useRouterState({
|
|
169
|
-
select: (state) =>
|
|
170
|
-
(
|
|
171
|
-
state.matches
|
|
172
|
-
.map((match) => match.headScripts!)
|
|
173
|
-
.flat(1)
|
|
174
|
-
.filter(Boolean) as Array<RouterManagedTag>
|
|
175
|
-
).map(({ children, ...script }) => ({
|
|
176
|
-
tag: 'script',
|
|
177
|
-
attrs: {
|
|
178
|
-
...script,
|
|
179
|
-
nonce,
|
|
180
|
-
},
|
|
181
|
-
children,
|
|
182
|
-
})),
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
return () =>
|
|
186
|
-
uniqBy(
|
|
187
|
-
[
|
|
188
|
-
...meta(),
|
|
189
|
-
...preloadLinks(),
|
|
190
|
-
...links(),
|
|
191
|
-
...styles(),
|
|
192
|
-
...headScripts(),
|
|
193
|
-
] as Array<RouterManagedTag>,
|
|
194
|
-
(d) => {
|
|
195
|
-
return JSON.stringify(d)
|
|
196
|
-
},
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Renders a stylesheet link for dev mode CSS collection.
|
|
202
|
-
* On the server, renders the full link with route-scoped CSS URL.
|
|
203
|
-
* On the client, renders the same link to avoid hydration mismatch,
|
|
204
|
-
* then removes it after hydration since Vite's HMR handles CSS updates.
|
|
205
|
-
*/
|
|
206
|
-
function DevStylesLink() {
|
|
207
|
-
const routeIds = useRouterState({
|
|
208
|
-
select: (state) => state.matches.map((match) => match.routeId),
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
onMount(() => {
|
|
212
|
-
// After hydration, remove the SSR-rendered dev styles link
|
|
213
|
-
document
|
|
214
|
-
.querySelectorAll('[data-tanstack-start-dev-styles]')
|
|
215
|
-
.forEach((el) => el.remove())
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
// Build the same href on both server and client for hydration match
|
|
219
|
-
const href = () =>
|
|
220
|
-
`/@tanstack-start/styles.css?routes=${encodeURIComponent(routeIds().join(','))}`
|
|
221
|
-
|
|
222
|
-
return <link rel="stylesheet" href={href()} data-tanstack-start-dev-styles />
|
|
223
|
-
}
|
|
4
|
+
import { useTags } from './headContentUtils'
|
|
224
5
|
|
|
225
6
|
/**
|
|
226
7
|
* @description The `HeadContent` component is used to render meta tags, links, and scripts for the current route.
|
|
@@ -233,22 +14,7 @@ export function HeadContent() {
|
|
|
233
14
|
|
|
234
15
|
return (
|
|
235
16
|
<MetaProvider>
|
|
236
|
-
<Show when={process.env.NODE_ENV !== 'production'}>
|
|
237
|
-
<DevStylesLink />
|
|
238
|
-
</Show>
|
|
239
17
|
<For each={tags()}>{(tag) => <Asset {...tag} />}</For>
|
|
240
18
|
</MetaProvider>
|
|
241
19
|
)
|
|
242
20
|
}
|
|
243
|
-
|
|
244
|
-
function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {
|
|
245
|
-
const seen = new Set<string>()
|
|
246
|
-
return arr.filter((item) => {
|
|
247
|
-
const key = fn(item)
|
|
248
|
-
if (seen.has(key)) {
|
|
249
|
-
return false
|
|
250
|
-
}
|
|
251
|
-
seen.add(key)
|
|
252
|
-
return true
|
|
253
|
-
})
|
|
254
|
-
}
|