MCPcopy Create free account
hub / github.com/TanStack/router / Scripts

Function Scripts

packages/react-router/src/Scripts.tsx:23–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 * begin to be inserted.
22 */
23export const Scripts = () => {
24 const router = useRouter()
25 const nonce = router.options.ssr?.nonce
26
27 const getParts = (matches: Array<any>) => {
28 const parts = getSsrBodyScriptParts(
29 matches,
30 router.ssr?.manifest,
31 nonce,
32 routeScriptAttrs,
33 )
34 for (const script of parts[1]) {
35 if (typeof script.attrs?.src === 'string') {
36 const scriptWithHoist = script as ScriptRenderAsset
37 scriptWithHoist.preventScriptHoist = true
38 }
39 }
40 return parts
41 }
42
43 const getScripts = (matches: Array<any>) => {
44 return composeSsrBodyScripts(getParts(matches))
45 }
46
47 if (isServer ?? router.isServer) {
48 const activeMatches = router.stores.matches.get()
49 return renderScripts(
50 composeSsrBodyScripts(
51 getParts(activeMatches),
52 router.serverSsr?.takeInitialHydrationScriptTags(),
53 ),
54 )
55 }
56
57 // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static
58 const scripts = useSelector(router.stores.matches, getScripts, {
59 compare: deepEqual,
60 })
61
62 return renderScripts(scripts)
63}
64
65function renderScripts(scripts: Array<ScriptRenderAsset>) {
66 return (

Callers

nothing calls this directly

Calls 6

useRouterFunction · 0.90
composeSsrBodyScriptsFunction · 0.90
getPartsFunction · 0.85
renderScriptsFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected