Khan / aphrodite

Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
5.34k stars 188 forks source link

Expose `injectStyleOnce` #344

Open majapw opened 5 years ago

majapw commented 5 years ago

I have a need to inject some global CSS at the root separate from the component-based pipeline. Right now, I'm duplicating a lot of the code in injectStyleOnce (https://www.github.com/Khan/aphrodite/blob/master/src/inject.js#L181-197), but it'd be nice to support this usecase out of the box and export the function with the built package, a la flushToStyleTag.

See https://github.com/Khan/aphrodite/blob/master/dist/aphrodite.umd.js#L2072-L2079 for the current exports.

Thanks!

jlfwong commented 5 years ago

I'm no longer a maintainer of this codebase, so please don't take my opinion with too much weight.

I have a strong belief that keeping a minimum API surface area is valuable because of the ability it affords library authors to change implementation details. So if I were still a maintainer of this codebase, I'd be hesitant to increase the API surface by exposing an implementation detail for other use.

An alternative strategy for doing this kind of thing that imposes a different kind of burden would be to create a library which exposes this, have aphrodite depend upon it, and have your project depend upon the inject-style package (or whatever it was called). That would allow aphrodite to switch away from this strategy without breaking API compatibility.

majapw commented 5 years ago

I think a minimal API surface area makes sense, but I think that it also may make sense to expose injectStyleOnce as part of that. If I am using Aphrodite, chances are likely that any global styles I want to introduce should use the Aphrodite styling interface (inject into the data-aphrodite blob for instance) and to accomplish this while supporting server-rendering and creating the tag if it's not there and so forth requires a ton of code duplication of Aphrodite's internals. I think it would make sense to expose this method for this usecase (but I'm open to other suggestions).

to: @lencioni