-
Notifications
You must be signed in to change notification settings - Fork 27
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
Define what a type is #16
Comments
Note, the definition of a JSON MIME type is also complex, see whatwg/mimesniff#112 for current discussion. |
Yeah, seems like each each module import img from "./my_resource" with type: "image"; import img from "./my_resource" with type: "json"; where the former yields a canvas/bitmap/whatever and the latter yields the corresponding JSON object. XML/SVG are a current example where a resource can be interpreted as multiple types. |
We could specify sensible defaults, like import img from "./my_resource" with type: "image", as: "json"; Moreover, bundlers usually have multiple loaders that can include an image; where some will do it as a json string, blob or an URL. The developer could clarify as well with the attribute: import img from "./my_resource" with type: "image", as: "raw"; |
There would need to be a separate mapping of all of the types to their associated mimes. Seems like a lot since this would need to live somewhere and who would be responsible for updating it? Wouldnt that cause us to have to version it so it doesnt break sites? Although it seems like a rare use case, is there any reason the author couldnt just use multiple mime types they would accept in the import statement? |
Some of these semantics get web-specific. I wrote up my thoughts on the interaction with the web at #24 . |
Is there value in making the type more generic? The user just says that they don't expect execution of code from this resource, making it something like this: import img from "./my_resource" with type: "data";
import img from data "./my_resource"; Otherwise it feels like it devolves into a very verbose duplication of information already provided elsewhere that could encourage people to not use this pattern, instead opting for shipping the data embedded in JS because it's "easier to use that way". |
It definitely seems to me like the only thing motivating this proposal is “does the user expect an import to execute in the JS env, or not” which sounds to me like a boolean condition instead of a silly complex type, or “any data”. |
We don't need a complex type, but there are cases more complex than "does the user expect an import to execute in the JS env, or not". Edit: we have data about ContentType vs file extension mistmatch https://github.com/littledan/proposal-module-attributes/blob/master/content-type-vs-file-extension.md. |
I would argue that it is way more likely that the server accidentally makes a schema change in the CSS or JSON data that breaks the importing module. And I wouldn't expect the module syntax to protect from that. If the server sends unexpected responses, the program will break in unexpected ways. I don't think any amount of syntax will prevent that. |
@xtuc I’m not sure why - if it works, it works; if it doesn’t, it doesn’t. Why should the consuming code pay a tax that tightly couples it to implementation details of a specifier? |
@jkrems That's definitely a possibility. In WICG/webcomponents#839 (comment) , @rniwa suggested that separating types further to avoid parser misuse would be preferable, but earlier in the thread, there are simpler |
Are custom types possible, and if not, would it require a breaking change to add support (future-proofing)? For example: import "Foo" form "foo" with type: "Mustache"
import "Bar" form "bar" with type: "ReactComponent" Background This proposal looks similar to "plugins" in RequireJS which allowed you to write loader plugins that can load different types of resources as dependencies. In RequireJS syntax was "!", and you could for example load JSON like this: require("foo!json", "bar!json", function(foo,bar) {
// foo and bar are json objects
}); Here is the list of the plugins that were at one point supported: The pluging's role was to parse the source text and return a type. A type could be a template (Jade, Handlebar, Mustache, etc) or even HTML. |
The host could allow to add custom types, because types are interpreted by the host. As you mentioned in another issue, if we want to ensure future proof types I guess it's not recommended. |
Is the ability to polyfill a concern? If the host doesn't allow custom types, an application would be unable to handle the absence of mustache support gracefully in a browser that doesn't ship it yet (using mustache as a placeholder for "future format"). |
I think, within build tools, it should be possible to define a custom type. On the web, as a native feature, this would require that some JavaScript code runs to set up the interpretation of these types before the modules load. This becomes more of a research problem, similar to ServiceWorker on first load. |
"ServiceWorker on first load" seems to be planning to ban TLA in SWs; i'm not convinced that direction will be a feasible solution in a general sense. |
@ljharb I don't understand the connection between these two things. Those are just two times ServiceWorker came up in TC39. |
In #3 (comment) , there is a suggestion that we could ask people to write MIME types rather than these more abstract types. This was my first intuition as well, but I think the current direction of higher-level types is good because:
|
Higher-level types could be based on MIME type groups, which defines the following groups
Perhaps new MIME type groups would be needed for |
One thing that is valuable is for personal/vendor specific types to be clearly defined. Using shortnames like mime groupings from WHATWG would give us a central registry to coordinate across environments, but doesn't really specify how to specify non-standard extensions. MIME types themselves have |
An idea could be to define two properties (e.g.
A drawback to having multiple properties is that this may be considered over engineered, confusing, or 'silly complex'. |
if we want the |
why should we specify the meaning of attributes instead of letting the host(Web, Node, etc...) decide it? The moduleSpecifier is a normal string and the platform can decide its module resolution, the module attribute should work in the same way. |
+1 to what @Jack-Works said. My impression was that tc39 would specify the mechanism, but similar to specifier strings it would be up to the host to decide semantics |
Given the years of confusion around specifier strings, to me that sounds like an argument for TC39 to have stronger opinions on the value of the attribute. |
You can see the current draft spec for a definition of
Does this resolve the issue? Do folks have concerns with these answers? The decisions here are pretty fundamental, so I'm tagging this issue as "Stage 2". |
I think that's a pretty complete definition that should answer the important questions. So for the purposes of this issue, this feels enough to close it. |
I think it is beneficial to have common semantics and interpretation across conforming host platforms; just like the current draft spec defines for I have no idea if this is a stage 2 concern or not; please accept my apologies if this suggestion is inappropriate at this stage. Note, this concern has been addressed, at least in my mind, by #63 (comment) |
Although, TC39 might not enforce interpretation, it might be a good idea to write up a table of expected possible types per host environment with possible expected semantics just to get a better idea of the scope of things and to get everyone on the same page. This might also allow to spot where the proposal is currently lacking something we might not have thought about. |
Currently the proposal seems to imply that the type strictly matches with a mimetype:
json
will check for theapplication/json
mimetype for intance.However, there are cases where it might be too specific:
BinAST has the mimetype
application/javascript-binast
while JavaScript hasapplication/javascript
. Some browser can support both depending what the server sends.For instance:
Should allow both a BinAST encoded and a JavaScript to be imported.
Similarly images; it's common for a web server to send different image format or quality depending on the client's request (based Accept header or similar).
For instance:
Should allow
image/jpeg
orimage/webp
in the response mimetype.The interpretation of
type
should be something like:image
, thenimage/jpeg
,image/webp
javascript
, thenapplication/javascript
,application/javascript-binast
The text was updated successfully, but these errors were encountered: