Open History to see the last commit
1import jsesc from 'jsesc'
2β
3export function ScriptOnce({
4 children,
5 log,
6}: {
7 children: string
8 log?: boolean
9 sync?: boolean
10}) {
11 if (typeof document !== 'undefined') {
12 return null
13 }
14β
15 return (
16 <script
17 className="tsr-once"
18 dangerouslySetInnerHTML={{
19 __html: [
20 children,
21 (log ?? true) && process.env.NODE_ENV === 'development'
22 ? `console.info(\`Injected From Server:
23${jsesc(children.toString(), { quotes: 'backtick' })}\`)`
24 : '',
25 'if (typeof __TSR__ !== "undefined") __TSR__.cleanScripts()',
26 ]
27 .filter(Boolean)
28 .join('\n'),
29 }}
30 />
31 )
32}