WICG / construct-stylesheets

API for constructing CSS stylesheet objects
Other
137 stars 25 forks source link

Cloning StyleSheets #32

Open justinfagnani opened 6 years ago

justinfagnani commented 6 years ago

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.

rakina commented 6 years ago

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

tabatkins commented 6 years ago

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

rakina commented 5 years ago

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.

tabatkins commented 5 years ago

Yup, exactly.