-
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
Shall we disallow @import in constructed stylesheets? #25
Comments
I guess I fail to see how and why this would need to be different than doing the following: const sheet = document.createElement('style');
sheet.innerHTML = `
@import "/path/to/style.css";
* { color: tomato; }
`;
// some action that would actually add the sheet to to a `StyleSheetList` I think @rniwa's concern was coming up with how things are parsed. Is there any particular reason they would need to be parsed differently than the action above? If the sheet is constructed it seems reasonable to assume that there is an intent to use it so resource fetching could happen the same as if you were to use an |
If allow Honestly, it's fine if you wanted to spend defining those things now that we've found a workaround to use WICG/webcomponents#468 without defining constructible stylesheets (use styleElement's sheet). It just means that this feature (constructible stylesheet) would be further delayed because spec'ing all those details would take time. |
I think this makes sense as an |
If we do allow
|
From internal discussion within Google, we would like to start implementation disallowing (ignoring) |
Have you spoken to the CSSWG? You can't just create you own "CSS" syntax willy-nilly and call it "CSS". |
I was not familiar with the formal CSS process, but will definitely talk to. |
As someone interested in using this feature, I think it would be a mistake to disallow/ignore Without this the feature loses a lot of impact when it comes to properly modularizing constructed stylesheets. |
Note that I'm no longer of the opinion that e.g. we may want to add a static function like |
Thanks for the feedback, I'm happy to see @rniwa is not against having Maybe we can close this as "we have |
@rniwa @TakayoshiKochi How would |
It would return a |
Note that in my current proposal-sketch for a generic TypedOM-based CSS parser, all the "large" parsing functions (in particular, This applies just the same here, and suggests we should only have a parsing factory function that returns a Promise, and not have a constructor. Is there a good reason we have to allow synchronous creation, particularly sync creation that's easier to type than the preferred async method? |
@bzbarsky, I get that, it just feels redundant. I actually like the idea of only having an async function in general, but worry what that might mean for the default stylesheets proposal unless that's capable of taking a promise object, too (waiting for the stylesheet to resolve before defining a custom element might have some weird side effects): const defineElement = async () => {
const style = await StyleSheet.createFromString(`/* blah blah blah */`);
customElements.define('my-el', class extends HTMLElement { /* stuff */ }, { style });
}
defineElement(); If Would that be any different than using a constructed object |
Yes, from what your code looks like.
The answer depends on how we define when the promise is considered resolved, i.e. if (1) it resolves when parsing is done or (2) it resolves when all dependent loading is done (which is the timing that At this moment I think we assume the constructor returns when parsing of the given string is done, and the resulting stylesheet can be fed to a custom element definition, but |
I think we need to resolve the promise when the dependent loads are done. Waiting just for the parsing to be finished will be quite useless in terms of determining when it's ready to use a stylesheet. |
@rniwa, would that necessarily block the definition and potential upgrade of custom elements? Also, is it your belief that the constructor should disallow Would the style attribute on the custom element config object be able to accept one of these |
I don't think we're gonna allow constructor at all from what I'm hearing since CSSWG doesn't want to use a synchronous API for anything that involves parsing. That makes sense because in theory we could be parsing CSS in a separate thread. One problem of accepting this stylesheet promise when defining a custom element is it becomes unclear what happens to the upgraded custom elements between the time such a custom element is defined, and it's used. Does it have |
@rniwa Thanks for that explanation. I guess my concern here would be that the developer experience wouldn't be great as far as syntax is concerned unless some tools were built to abstract the definition process. Assume there are 10 different stylesheets that need to be defined for custom elements, that's 10 different async functions. A follow up question is what happens when an |
@calebdwilliams I am naively assuming that when you have 10+ different stylesheets for each different custom element, you can put those promises in an array and use For the latter let's have a separate issue. |
@TakayoshiKochi, @rniwa, @tabatkins |
I think that's up for a debate. Someone has to come up with a concrete proposal about how |
The draft spec is recently updated with how Anything else we should add? |
I think we can close this bug now. |
The original comment from @rniwa:
WICG/webcomponents#468 (comment)
This decision affects many other issues, so we'd like to get this resolved.
The text was updated successfully, but these errors were encountered: