()
| 21 | * begin to be inserted. |
| 22 | */ |
| 23 | export 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 | |
| 65 | function renderScripts(scripts: Array<ScriptRenderAsset>) { |
| 66 | return ( |
nothing calls this directly
no test coverage detected