Tailwindcss: The pseudo class ":first-child" is potentially unsafe when doing server-side rendering

Created on 29 Oct 2020  路  4Comments  路  Source: tailwindlabs/tailwindcss

The problem:

I am working a small project with React and it generates this error:
The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type".

Tailwind config:

margin: ['responsive', 'first']


You have to change the: first-child to: first-of-type

Most helpful comment

It's "unsafe" because server-rendered components could have a <style> element as the first child. In that case, :first-child would be applied to the wrong element.

All 4 comments

How is it "unsafe"?

How is it "unsafe"?

It is an error that generates react in development. I am not clear why it says it is unsafe.

It's "unsafe" because server-rendered components could have a <style> element as the first child. In that case, :first-child would be applied to the wrong element.

This doesn't sound like any sort of Tailwind issue to me, everything I am finding points to this being something in Emotion?

https://github.com/emotion-js/emotion/issues/1105

Either way, even if this is the case there's no reason to remove this from Tailwind I don't think, just like there's no reason to remove it from CSS.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benface picture benface  路  3Comments

Tjoosten picture Tjoosten  路  3Comments

jbardnz picture jbardnz  路  3Comments

chasegiunta picture chasegiunta  路  3Comments

divdax picture divdax  路  3Comments