Skip to content
Open
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions packages/react-router/src/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,19 @@ function Script({
}
}

// For inline scripts (children, no src), keep the element in the React tree after
// hydration so React doesn't unmount the SSR-rendered script from the DOM.
// The useEffect above detects the existing element via textContent match and skips
// re-injection, so the script won't execute a second time.
if (!attrs?.src && typeof children === 'string') {
return (
<script
{...attrs}
dangerouslySetInnerHTML={{ __html: children }}
suppressHydrationWarning
/>
)
}

return null
}
Loading