[Next.js 15 App Router] JSON-LD schema inside <Script> ends up in hydration — how to insert SSR-only? #80088
Unanswered
alexabbykiv
asked this question in
App Router
Replies: 1 comment 4 replies
-
Would you mind trying this way out? There's a super hacky thing you can do, switch to
I've never used this hack myself, but as far as I understand, React will encounter the different innerHTML, try to warn, but be supressed, and the move on, skipping hydration, and skipping manipulating the DOM contained within. 'use client'
export default function Home() {
return (
<script
suppressHydrationWarning
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: typeof window !== 'undefined' ? " " : '{"foo": "bar"}')
}} />
);
} Something like that, it is silly, and hacky, but does it help you? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone!
I'm working with Next.js 15 and the App Router. I need to inject dynamic JSON-LD schema (type="application/ld+json") into the — on the server only, and without it being included in hydration or the JS bundle.
I initially tried this:
But this leads to the <script type="application/ld+json"> being hydrated, I have large dynamic JSON-LD data that bloats the hydration payload and ruins performance — how can I inject it server-side only without hydration in Next.js 15 App Router?
Beta Was this translation helpful? Give feedback.
All reactions