Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions packages/react-router/src/ScriptOnce.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,18 @@
export function ScriptOnce({
className,
children,
log,
...rest
}: { children: string; log?: boolean } & React.HTMLProps<HTMLScriptElement>) {
}: { children: string } & React.HTMLProps<HTMLScriptElement>) {
if (typeof document !== 'undefined') {
return null
}

return (
<script
{...rest}
className={`tsr-once ${className || ''}`}
className={['tsr-once', className].filter(Boolean).join(' ')}
dangerouslySetInnerHTML={{
__html: [
children,
(log ?? true) && process.env.NODE_ENV === 'development'
? `console.info(\`Injected From Server:
${children}\`)`
: '',
]
.filter(Boolean)
.join('\n'),
__html: [children].filter(Boolean).join('\n'),
}}
/>
)
Expand Down
9 changes: 2 additions & 7 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2558,15 +2558,10 @@ export class Router<
)

this.streamedKeys.add(key)
const children = `__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))}}`
const children = `__TSR__.streamedValues['${key}'] = { value: ${this.serializer?.(this.options.transformer.stringify(value))} }`

this.injectHtml(
`<script class='tsr-once'>${children}${
process.env.NODE_ENV === 'development'
? `; console.info(\`Injected From Server:
${children}\`)`
: ''
}; __TSR__.cleanScripts()</script>`,
`<script class='tsr-once'>${children}; __TSR__.cleanScripts()</script>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to remove the logging for this? Couldn't we just correctly escape the console.log statements instead?

)
}

Expand Down
1 change: 0 additions & 1 deletion packages/start/src/client/Meta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const useMetaElements = () => {
))}
<>
<ScriptOnce
log={false}
children={`
__TSR__ = {
matches: [],
Expand Down