Hydration error when settings attribute to <html> tag
Answered
Nile Crocodile posted this in #help-forum
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
Do i just ignore it or is there any way to fix this more elegantly?
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 warningExtra attributes from the server: data-countly-useragentDo 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.3 Replies
@Nile Crocodile 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?
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.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