MCPcopy
hub / github.com/TanStack/router / Scripts

Function Scripts

packages/solid-router/src/Scripts.tsx:6–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import type { RouterManagedTag } from '@tanstack/router-core'
5
6export const Scripts = () => {
7 const router = useRouter()
8 const nonce = router.options.ssr?.nonce
9 const assetScripts = useRouterState({
10 select: (state) => {
11 const assetScripts: Array<RouterManagedTag> = []
12 const manifest = router.ssr?.manifest
13
14 if (!manifest) {
15 return []
16 }
17
18 state.matches
19 .map((match) => router.looseRoutesById[match.routeId]!)
20 .forEach((route) =>
21 manifest.routes[route.id]?.assets
22 ?.filter((d) => d.tag === 'script')
23 .forEach((asset) => {
24 assetScripts.push({
25 tag: 'script',
26 attrs: { ...asset.attrs, nonce },
27 children: asset.children,
28 } as any)
29 }),
30 )
31
32 return assetScripts
33 },
34 })
35
36 const scripts = useRouterState({
37 select: (state) => ({
38 scripts: (
39 state.matches
40 .map((match) => match.scripts!)
41 .flat(1)
42 .filter(Boolean) as Array<RouterManagedTag>
43 ).map(({ children, ...script }) => ({
44 tag: 'script',
45 attrs: {
46 ...script,
47 nonce,
48 },
49 children,
50 })),
51 }),
52 })
53
54 let serverBufferedScript: RouterManagedTag | undefined = undefined
55
56 if (router.serverSsr) {
57 serverBufferedScript = router.serverSsr.takeBufferedScripts()
58 }
59
60 const allScripts = [
61 ...scripts().scripts,
62 ...assetScripts(),
63 ] as Array<RouterManagedTag>

Callers

nothing calls this directly

Calls 3

useRouterFunction · 0.90
useRouterStateFunction · 0.90
filterMethod · 0.80

Tested by

no test coverage detected