Next.js Discord

Discord Forum

Hydratation error

Answered
Irish Terrier posted this in #help-forum
Open in Discord
Avatar
Irish TerrierOP
Before Next 15.x I've always used this "trick" to correctly initialyze viewport height to be used with css like this
<script
   dangerouslySetInnerHTML={{
      __html: `document.documentElement.style.setProperty('--root-height', window.innerHeight + "px");`,
   }}
/>

This script is added in the <head/> so basically is executed before any element is painted but soon enough to calculate the height of the viewport. Then I'll use

.element {
  height: var(--root-height)
}


So far so good, I can style fullscreen hero without using vh units in a completely safe and cross browsers way. Till next 15; now I get hydratation issues, because the html style tag doesn't match.

So as far as I understand, this can't be done anymore?
Answered by joulev
just add suppressHydrationWarning to the <html> tag
View full answer

3 Replies

Avatar
just add suppressHydrationWarning to the <html> tag
Answer
Avatar
Irish TerrierOP
Yes but this will disable all hydratation warnings for the whole app
Avatar
No it won’t. It will disable hydration warnings for the html tag and that html tag only, which is exactly what you need.