Emotion: [Question] Empty style[data-emotion] in production build

Created on 27 Feb 2019  路  6Comments  路  Source: emotion-js/emotion

  • emotion version: 9.2.12
  • react version: 16.6.3

screen shot 2019-02-27 at 4 23 51 pm

I want to see emotion styles on production, but I see only empty <style data-emotion></style>. How is it possible that there is no CSS code, but styles works?

question

Most helpful comment

@mrsum

[...document.querySelectorAll('[data-emotion]')].flatMap(({ sheet }) => [...sheet.cssRules].map(rules => rules.cssText)).join('\n')

All 6 comments

This is because emotion in production uses insertRule API which is faster than creating text nodes.

@Andarist thank you! is it possible to insert this style[data-emotion] tag into other than head location, I need it for shadow dom

Is it possible to get all css styles programatically at production build? I need styles for PDF generation.

@mrsum

[...document.querySelectorAll('[data-emotion]')].flatMap(({ sheet }) => [...sheet.cssRules].map(rules => rules.cssText)).join('\n')

While I'm here I'm going to close the issue since it has been answered already, I hope you guys don't mind.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aaron-Pool picture Aaron-Pool  路  3Comments

mitchellhamilton picture mitchellhamilton  路  3Comments

kentcdodds picture kentcdodds  路  3Comments

desmap picture desmap  路  3Comments

smlmrkhlms picture smlmrkhlms  路  3Comments