-
Notifications
You must be signed in to change notification settings - Fork 376
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
Workers and non-JavaScript modules #822
Comments
We should probably have been a little more careful here. Top-level JavaScript and Wasm make sense to me, others not that much. |
An analogous case: I'm comfortable with the current approach. It feels vaguely more consistent to me, as it helps us from refraining to specially call out the top-level module as a specific concept. |
If we provide a way to get a module from a |
@justinfagnani Is this idea under discussion somewhere? |
@littledan mostly casually. We talked about it at the spring web components face-to-face in the context of the HTML modules proposal. |
I do agree with @justinfagnani, we should have such getter, or any other form of referencing the module namespace object. |
I would be happy with taking a conservative approach and disallowing JSON/etc. for workers and script elements for now, and loosening that up later if we ever add a If we want to restrict it, we should decide sooner rather than later, because I can just imagine the kind of fun hacks people will start using this for. (E.g. precaching JSON files, or something weirder...) |
A related thing here is that we cannot support certain module types in a worker context (e.g., CSS and HTML) and perhaps also not in a worklet context. |
OK, sounds like treating script tags and workers as the same is a bit of an oversimplification. I can see the case for restricting JSON modules in workers while leaving them in place for script tags. |
Is there a major reason |
DOM implementations in browsers are not thread-safe and nobody is willing to put in the effort to make them so. (And to be clear, I don't think we've seen compelling enough use cases to justify the enormous amount of effort required.) |
I’m wondering about the expected behavior for non-JavaScript module types with regards to workers.
Consider this example:
Per the run a worker algorithm, this would Fetch a module worker script graph which, given that resource.json came with a JSON MIME type, would create a JSON module script. The JSON module script would be returned to the run a worker algorithm, which would call run a module script, which would call Evaluate() on the JSON Module Script’s Synthetic Module. Evaluate() won’t do anything except set the parsed JSON object as the default object of the module, which is essentially a no-op in this scenario as there is no importing module to observe it. So, this effectively becomes a Worker that just doesn’t do anything.
Is this by-design? It is a little odd but perhaps not harmful. An alternative would be to ban non-JavaScript MIME types for the top-level Worker module, perhaps in the custom perform the fetch steps passed to Fetch a module worker script graph by the worker processing model steps. On the other hand, it seems reasonable for descendants of the top-level Worker module to be non-JS, e.g. a Worker should be able to
import config from “./config.json”
.These questions will gain further relevance with the introduction of other module types. I think this will need to be a case-by-case thing where some module types make sense in a Worker context (JSON modules, WebAssembly, GetOriginals imports), where others do not (CSS modules, HTML modules).
@littledan, @domenic, @annevk, @travisleithead, any thoughts?
The text was updated successfully, but these errors were encountered: