Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

ScriptOnce.tsx

20 lines439 Bytes

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