diff --git a/.changeset/tame-bananas-work.md b/.changeset/tame-bananas-work.md new file mode 100644 index 0000000000..60c33b05c3 --- /dev/null +++ b/.changeset/tame-bananas-work.md @@ -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. diff --git a/contributors.yml b/contributors.yml index daa45d0f08..9ed3480469 100644 --- a/contributors.yml +++ b/contributors.yml @@ -474,3 +474,4 @@ - zeromask1337 - zheng-chuang - zxTomw +- Ammar123890 \ No newline at end of file diff --git a/packages/react-router/lib/dom/ssr/components.tsx b/packages/react-router/lib/dom/ssr/components.tsx index 2e0f101511..0d66597e33 100644 --- a/packages/react-router/lib/dom/ssr/components.tsx +++ b/packages/react-router/lib/dom/ssr/components.tsx @@ -621,7 +621,7 @@ export function Meta(): React.JSX.Element { return ( <> - {meta.flat().map((metaProps) => { + {meta.flat().map((metaProps, index) => { if (!metaProps) { return null; } @@ -656,10 +656,13 @@ 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 (