Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/tame-bananas-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": minor
---

fix: prevent JSON-LD duplication and hydration mismatch in React 19 by using stable index-based keys and adding suppressHydrationWarning.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,4 @@
- zeromask1337
- zheng-chuang
- zxTomw
- Ammar123890
9 changes: 6 additions & 3 deletions packages/react-router/lib/dom/ssr/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ export function Meta(): React.JSX.Element {

return (
<>
{meta.flat().map((metaProps) => {
{meta.flat().map((metaProps, index) => {
if (!metaProps) {
return null;
}
Expand Down Expand Up @@ -656,18 +656,21 @@ export function Meta(): React.JSX.Element {
if ("script:ld+json" in metaProps) {
try {
let json = JSON.stringify(metaProps["script:ld+json"]);
let ldJsonKey = `script:ld+json:${index}`;

return (
<script
key={`script:ld+json:${json}`}
key={ldJsonKey}
type="application/ld+json"
suppressHydrationWarning
dangerouslySetInnerHTML={{ __html: escapeHtml(json) }}
/>
);
} catch (err) {
return null;
}
}
return <meta key={JSON.stringify(metaProps)} {...metaProps} />;
return <meta key={index} {...metaProps} />;
})}
</>
);
Expand Down