cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.06k stars 397 forks source link

Allow empty styles at runtime #617

Open kof opened 6 years ago

kof commented 6 years ago

For dynamic styles/rules we need to allow them render empty in order to be linked and so props can be defined later. Right now the logic allows empty rules only if link: true option is used, which works fine.

Though, a more straight forward way would be to always allow empty rules. We need to skip empty rules only when we do SSR or build-time extraction in order to remove unused CSS.

Empty rules could be generated when a function which returns styles, but, based on some condition, returns an empty value and user is unaware. In general it is a quite rare case and gave us headaches with dynamic cases where rules are generated by Observables and evtl. by functions in the future.

appsforartists commented 6 years ago

I like this solution way better than tagging styles with $isDynamic and having to chase that through the codebase.

kof commented 6 years ago

Definitely, that isDynamic thing was a harsh decision, which is already removed in https://github.com/cssinjs/jss/pull/615. This issue is about to remove further checks of the link option. It requires touching a number of plugins tests, thats why separate issue.