Next.js Discord

Discord Forum

Hydration error when settings attribute to <html> tag

Answered
Nile Crocodile posted this in #help-forum
Open in Discord
Nile CrocodileOP
I'm using an analytics library that sets an attribute to <html> tag when initialized.

At first it was throwing an error because it uses window object for it and since ssr doesn't have access to window object it would throw undefined.

To bypass that I wrapped the initialization part in if (typeof window !== undefined) but now im getting a warning

Extra attributes from the server: data-countly-useragent

Do i just ignore it or is there any way to fix this more elegantly?
Answered by joulev
Hmm just add suppressHydrationWarning to the <html> tag. Seems like in this case since it’s related to a non-React third party library there is no better way than this.
View full answer

3 Replies

Answer
Nile CrocodileOP
yeah i did that, wanted to know if there was a better way
That third party lib has to ensure that it doesn’t add the attribute until after hydration has finished, which… is impossible for a non-React lib