Conversation
Adds support for the `{ type: 'text' }` import attribute,
which enables importing text content as a JavaScript string.
|
Looks good. I do wonder whether there ought to be a required MIME type, especially given that the other types all have one. If Alternatively there could be a requirement not to have certain MIME types, e.g. to disallow importing JavaScript as text. I think I am personally inclined not to impose such requirements, but I could see the argument either way. |
|
Would this make available the same content that is already available via |
|
Good question. Looks like For clarity it might be good to rename the destination to Anyway, yes, this ends up letting you get the exact same content as |
|
Do we actually want a |
|
|
|
It's specific in that we can ask the server for JSON with Given that the destination is exposed these days through |
|
Oh, nice, I didn't realize that it got exposed there and wasn't just editorial. In that case I agree |
|
The TC39 / ECMA-262 part of this proposal has now advanced to Stage 3. |
noamr
left a comment
There was a problem hiding this comment.
I think this needs to be rebased, and properly support modulepreload like CSS/JSON.
|
Do the tests cover module preload? The spec text seemed good AFAICT! |
noamr
left a comment
There was a problem hiding this comment.
Unofficial LGTM % tests for modulepreload
@noamr They do now (I just updated the WPT PR). |
annevk
left a comment
There was a problem hiding this comment.
This looks good to me. It would be great if @nicolo-ribaudo could also do a quick skim.
|
MDN and browser bugs should be completed for this as well before landing. |
Done. |
|
@eemeli can you detail how this PR addresses the concerns you've linked to in tc39/proposal-import-text#8? The PR description says they should be addressed in this PR. Maybe they are? It would be good to flesh it out. |
|
@noamr The concerns raised in tc39/proposal-import-text#8 lead to tc39/proposal-import-text#10, which added a non-normative qualifier that the String representing the imported module "should represent textual data". This recalls the pre-existing spec description of Strings as "generally used to represent textual data". As you note, this proposal has imported text modules always being parsed as UTF-8, as required by the Encoding standard. And so if the imported bytes do not in fact represent text, we end up with an unusable string full of lossy � replacements, and not e.g. a base64 representation of it, or some other reversible binary-as-text mapping. Once a text module has been imported, we can (and should) presume that it'll be used for something; either presented directly to the user, or parsed for some further meaning. In either case, a UTF-8 parsing of binary data will be readily apparent as not fulfilling whatever need is put to it, and the error can be addressed by the developer. However, this assertion of "readily apparent" is rather dependent on having some idea of the expected shape of the textual data, which we don't know for the general case: Maybe it's prose that's been incorrectly encoded and decoded resulting in a smattering of replacement characters; maybe it's an XML document; maybe it's base122 encoded data. And so if we do want to identify the errors caused by parsing binary data as text a bit earlier, and in a way that would make those errors non-recoverable (you can't try-catch an import statement), I agree that filtering on the MIME type is perhaps the only available recourse. That does leave us with the problem of identifying "textual" MIME types, for which I'm not aware of a pre-existing registry or heuristic -- or is there one I've missed? Relying on the IANA registry's "Encoding Considerations" section is not really appropriate: as noted in its application form,
Relying on such a registry would also introduce unnecessary points of divergence between implementations. For example, To summarize, I think the concerns that have been raised are addressed as well as they can be by this proposal, and that introducing additional filtering, sniffing, or heuristics is not warranted, given the real-world limitations we need to contend with, and the negative consequences of doing so. |
|
Thanks for the detailed response, @eemeli. This is resolved as far as I'm concerned. |
This is the HTML counterpart for the newly-introduced TC39 Import Text Stage 2 proposal; this has been previously discussed here in #9444, and is closely related (but not blocking on) PR #11657, which correspondingly adds byte imports.
The
type: 'text'import attribute is introduced here without any MIME type requirement, and without any validity or well-formedness checks on the returned string value. @sffc has raised some concerns about additional validation steps being desirable for text content, which would be appropriate for consideration in this spec, rather than the JS spec.The implementer support noted below is based on feedback from delegates at the 2025 November TC39 meeting.
/acknowledgements.html ( diff )
/infrastructure.html ( diff )
/links.html ( diff )
/references.html ( diff )
/webappapis.html ( diff )