Re: [w3c/webcomponents] Rejecting CSS Modules in Workers (#854)

Just to clarify (and align words to the spec e.g. https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error):

1.

> The proposal is to add a flag,"allow_document_only_module_type" , to ModuleScriptFetcher::WasModuleLoadSuccessful. If WasModuleLoadSuccessful is called from a document, we will allow the CSS Modules to fetch, otherwise, throw a fetch error.

This is a fetch error approach (i.e. resolving with null module scripts, not a parse error that results in a non-null module script with a parse error).

2.

> Another approach is to perform a check on the execution context during ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript and throw a parsing error if we're attempting to load the CSS modules from a context other than a document.

This is a parse error approach.
ValueWrapperSyntheticModuleScript::CreateCSSWrapperSyntheticModuleScript() is called when parsing and creating a module script, and exceptions there result in [parse error](https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error).

---

> The parse error approach could be preferable architecturally speaking if the fetch() steps don't have to know about the module map's settings object.

+1. I prefer parse error approach (2.) for this reason. Fetch spec, fetch errors should preferrably depend only on fetch client's settings object.
Also, in terms of implementation, this would remove an extra flag passed across module loading layers.

> The advantage of failing the fetch() based on MIME type might be that it would be clearer to the developer. The error message would be similar to the one you already get if you try to 'import' something that doesn't have a JS MIME type.

The viewpoint of error messages sounds reasonable (I've missed it, thanks!).

In 2. (parse error approach), we could also argue that the error behavior is consistent.
For example, on workers,

- `import sheet from "./example.css" as css;`: fetch completes without fetch errors, and a parse error is thrown, no scripts are evaluated.
- `import sheet from "./example.js";` where its content is `const sheet = new CSSStyleSheet(...);` (a kind of polyfill of CSS modules): fetch completes without fetch errors, scripts are evaluated, and an evaluation error is thrown.

There are still a difference between parse and eval errors, but the fetch behavior is the same for both cases.

I feel these two cases above is conceptually similar (trying importing on CSS Modules or constructing CSSStyleSheet on wrong global scopes), more than to MIME type errors.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/854#issuecomment-555235074

Received on Monday, 18 November 2019 22:17:41 UTC