glamor icon indicating copy to clipboard operation
glamor copied to clipboard

Feature: Make `sheet.isBrowser` configurable or export memory only version of `sheet.js`

Open gingur opened this issue 9 years ago • 14 comments

Would be nice to be able to fallback to "server like" functionality of StyleSheet and store rules in memory instead of a new stylesheet. I can get the CSS rules from the instance using sheet.rules but every insert auto injects the new rule into the style appended by the sheet.inject. Example use case would be pre-rendering markup/css and injecting into an iframe client-side.

gingur avatar Feb 02 '17 21:02 gingur

related - #38.
will consider ater v3. thanks for the feedback!

threepointone avatar Feb 22 '17 07:02 threepointone

can you describe your usecase with more specifics, if you're still interested in this?

threepointone avatar Jul 19 '17 17:07 threepointone

use case is using a service worker to generate html/css and then injecting css into iframe(s). in other words, I want to take the css and manually inject where I see fit on the client side.

gingur avatar Jul 19 '17 18:07 gingur

qq - does window exist inside a service worker?

threepointone avatar Jul 20 '17 10:07 threepointone

I ask because glamor does a check on window's existence, and otherwise drops to the memory backed version, so it should already work as you require.

threepointone avatar Jul 20 '17 11:07 threepointone

I'm going to close this preemptively, but feel free to reopen if I'm wrong.

threepointone avatar Jul 20 '17 13:07 threepointone

@threepointone the primary request is to generate CSS as a string on the client-side. The request originated by the need to inject generated CSS into one or more iframes without applying the rules generated to the parent DOM. Currently I can use cssRules to extract the generated styles but then would need to immediately flush to remove CSS that was injected into a glamor stylesheet unintentionally.

I can make a PR if you'd prefer, just want to see what the consensus is on such a feature.

gingur avatar Jul 20 '17 15:07 gingur

Ah I see. What's the service worker about then? Reopening this, also related - #268

threepointone avatar Jul 20 '17 15:07 threepointone

Do you need just the sheet to do this, or all of glamor?

threepointone avatar Jul 20 '17 15:07 threepointone

Just sheet I believe, sorry about the confusion related to service workers. I've worked around the problem since I originally filed the feature in Feb, and was basing my comments off the current implementation rather the original problem.

gingur avatar Jul 20 '17 15:07 gingur

No need for a PR, if it's just the sheet, I'll do it myself. Should be done and released by the weekend.

threepointone avatar Jul 20 '17 16:07 threepointone

I'd like to hear more about your usecase if you don't mind. Why exactly are you building?

threepointone avatar Jul 20 '17 16:07 threepointone

Originally was using cxs, which uses glamor's sheet logic. Goal was to render dynamic content previews and injected into iframes. We ran into several issues however w/ media queries and css shorthand conflicts with longhand when trying to cache functional css classes.. but our revised version works pretty well thus far.

gingur avatar Jul 20 '17 23:07 gingur

I'll rephrase - can you describe the actual product to me? Please and thanks!

threepointone avatar Jul 21 '17 06:07 threepointone