Open History to see the last commit
1import { isServer } from '@tanstack/router-core/isServer'
2import { useRouter } from './useRouter'
3β
4/**
5 * Server-only helper to emit a script tag exactly once during SSR.
6 */
7export function ScriptOnce({ children }: { children: string }) {
8 const router = useRouter()
9 if (!(isServer ?? router.isServer)) {
10 return null
11 }
12β
13 return (
14 <script
15 nonce={router.options.ssr?.nonce}
16 dangerouslySetInnerHTML={{
17 __html: children + ';document.currentScript.remove()',
18 }}
19 />
20 )
21}