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

ScriptOnce.tsx

22 lines531 Bytes

1import { useRouter } from './useRouter'
2​
3/**
4 * Server-only helper to emit a script tag exactly once during SSR.
5 * Appends an internal marker to signal hydration completion.
6 */
7export function ScriptOnce({ children }: { children: string }) {
8 const router = useRouter()
9 if (!router.isServer) {
10 return null
11 }
12​
13 return (
14 <script
15 nonce={router.options.ssr?.nonce}
16 className="$tsr"
17 dangerouslySetInnerHTML={{
18 __html: [children].filter(Boolean).join('\n') + ';$_TSR.c()',
19 }}
20 />
21 )