-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider adding StyleSheet.createFromString()
which returns Promise<StyleSheet>
#2
Comments
Firefox does (will?) parse style sheets in different threads, so it would be nice if the main thread won't be blocked by waiting the parsing to finish. JavaScript constructor is just a function, so it is free to return any type, but as this is an interface usually defined in .idl file for rendering engines, their binding generators have to take care of that. As far as I researched there is no precedent example of a constructor returning a promise (e.g. |
All 5 inline issues are migrated to GitHub. WICG#2 Shall we allow asynchronous style sheet parsing? WICG#3 moreStyleSheets needs better name WICG#4 Shall we include added stylesheets in `document.styleSheets`? WICG#5 StyleSheetList will need to define a constructor, accepting a `sequence<StyleSheet>`. WICG#18 Define how origin is determined for a constructed stylesheet
StyleSheet.createFromString()
which returns Promise<StyleSheet>
Let's repurpose this for |
IDL contructors, unfortunately, can't return Promises. (I've opened whatwg/webidl#563 just in case.) So yeah, Do we want to disallow synchronous parsing entirely, so the constructor can synchronously produce an empty stylesheet only? |
@tabatkins we can only expose |
Well, no they can't; there's no way to synchronously await a promise. |
I think still having a constructor for an empty stylesheet would be advantageous (for certain use cases), especially if there could eventually be an instance method to append rules from a string: const sheet = new CSSStyleSheet();
sheet.addRulesFromString(` :host { color: tomato; }) `)
.then(sheet => console.log('success', sheet))
.catch(console.error); So the sheet would still be usable before parsing is completed, but would have the same |
That was my thought - allow the constructor to work, but don't accept any content. The suggestion to append to the stylesheet async makes good sense! |
@tabatkins @TakayoshiKochi |
I think we can resolve the final entrypoints of this feature as new CSSStyleSheet() to create empty CSSStyleSheet synchronously, and Promise<CSSStyleSheet> CSSStyleSheet.createFromString(string) to parse and create CSSStyleSheet asynchronously. The details have to be fleshed out elsewhere, but let's close this if no one objects in a few days. |
Firefox will have to continue support synchronous parsing due to |
We previously implemented constructable CSSStyleSheet synchronously, but discussions in WICG/construct-stylesheets#2 have gravitated away from that and we are now interested in asynchronous creation of CSSStyleSheet, but also provide synchronous constructor that only result in an empty sheet. This CL changed the constructors to not accept CSS text. This also changes part of the constructor where we process passed MediaList data to copy the given MediaList instead of using the same instance to avoid introducing the concept of mutable MediaLists. See: WICG/construct-stylesheets#13 CL for promise-based API: crrev.com/c/1126754 Bug: 807560 Change-Id: I0aeb052b63e45d81fc46cde3052f3d134afa16fa Reviewed-on: https://chromium-review.googlesource.com/1126898 Reviewed-by: Fergal Daly <fergal@chromium.org> Reviewed-by: Hayato Ito <hayato@chromium.org> Reviewed-by: Takayoshi Kochi <kochi@chromium.org> Commit-Queue: Rakina Zata Amni <rakina@chromium.org> Cr-Commit-Position: refs/heads/master@{#573233}
We previously implemented constructable CSSStyleSheet synchronously, but discussions in WICG/construct-stylesheets#2 have gravitated away from that and we are now interested in asynchronous creation of CSSStyleSheet. This CL added Document.createCSSStyleSheet that returns a Promise<CSSStyleSheet>, while also removing the exposed CSSStyleSheet that was previously exposed. Note that because CSS parsing is still done on the main thread, this function is actually still blocking. The previously implemented CSSStyleSheet is changed to only produce empty CSSStyleSheets in this CL: crrev.com/c/1126898 Bug: 807560 Change-Id: I9f9d17ae04829ff399ae384f8b3a6d97a3b0613b Reviewed-on: https://chromium-review.googlesource.com/1126754 Commit-Queue: Rakina Zata Amni <rakina@chromium.org> Reviewed-by: Hayato Ito <hayato@chromium.org> Reviewed-by: Takayoshi Kochi <kochi@chromium.org> Reviewed-by: Fergal Daly <fergal@chromium.org> Cr-Commit-Position: refs/heads/master@{#575600}
The original proposal defines the constructor running in a synchronous manner, but can it return
Promise<CSSStyleSheet>
instead, allowing the implementation to do lazy CSS parsing of the given text?The text was updated successfully, but these errors were encountered: