construct-stylesheets icon indicating copy to clipboard operation
construct-stylesheets copied to clipboard

Cloning StyleSheets

Open justinfagnani opened this issue 5 years ago • 4 comments

Once it's easier to construct (or import, see https://github.com/w3c/webcomponents/issues/759), they're more likely to be passed around to disparate parts of an application, which might try to independently mutate the stylesheet (say, to implement scoping via rewriting selectors).

Making it easy to clone a StyleSheet could help in code that wants to share/reuse StyleSheets safely. Clones could possibly be cheap if they allow for copy-on-write optimizations.

justinfagnani avatar Aug 09 '18 00:08 justinfagnani

If we do this, should we allow it only on constructed CSSStyleSheets, or also make it possible to CSSSStyleSheets from <style> or <link>?

rakina avatar Aug 28 '18 13:08 rakina

I don't see any reason to limit it to constructed-only. Seems reasonable to be able to clone any stylesheet.

tabatkins avatar Aug 28 '18 21:08 tabatkins

Yeah, I guess it makes sense. I was not sure how many parts of the source CSSStyleSheet should be kept (will it be just like making a CSSStyleSheetInit and text out of the source CSSStyleSheet and constructing with that, or are we keeping more), but looking again it seems there's only ownerNode and parentStyleSheet left (which should both be null, probably) so everything seems fine.

rakina avatar Aug 30 '18 08:08 rakina

Yup, exactly.

tabatkins avatar Aug 30 '18 18:08 tabatkins