diff --git a/packages/react-router/src/ScriptOnce.tsx b/packages/react-router/src/ScriptOnce.tsx index f4398deeeb..4a851a7e6a 100644 --- a/packages/react-router/src/ScriptOnce.tsx +++ b/packages/react-router/src/ScriptOnce.tsx @@ -1,14 +1,40 @@ +import jsesc from 'jsesc' import { useRouter } from './useRouter' export function ScriptOnce({ children, log, + sync, }: { children: string log?: boolean + sync?: boolean }) { const router = useRouter() + if (typeof document !== 'undefined') { + return null + } - router.injectScript(children, { logScript: log }) - return null + if (!sync) { + router.injectScript(children, { logScript: log }) + return null + } + + return ( +