dan...@microsoft.com, sase...@microsoft.com, tra...@microsoft.com, pc...@microsoft.com
HTML Modules Proposed Spec Changes
We are proposing an extension of the ES6 Script Modules system to include HTML Modules. These will allow web developers to package and access declarative content from script in a way that allows for good componentization and reusability, and integrates well into the existing ES6 Modules infrastructure.
The introduction of ES6 Script Modules has provided several benefits for javascript developers including more componentized code and better dependency management. However, easy access to declarative content has been a consistent limitation with Script Modules. For example, if one wants to pack a custom element definition in a module, how should the HTML for the element's shadow tree be created? Current solutions would involve generating it dynamically (document.createElement or innerHTML), but it would be preferable to simply write HTML and include it with the module. With HTML Modules this will be possible.
There is clear demand for this functionality in the developer community -- see this thread where ideas pertaining to HTML Modules have resulted in a great deal of developer and browser implementer engagement.
HTML Imports were proposed (and implemented in Chromium) as a solution, but they were developed independently of ES6 Modules and have several limitations:
Integrating HTML Modules into the existing ES6 Module system, rather than creating it as a standalone component, will address these gaps.
Interoperability risk:
We plan to initially ship the feature behind a runtime flag so that developers can experiment with the concept while spec changes are still being finalized.
Other browser implementers have expressed their support of the concept and its exploration during a Web Platform WG meeting at TPAC 2018 (see meeting minutes here). Specifically:
Compatibility risk:
Same as Interoperability risk
HTML Modules are expected to be used in tandem with Script Modules. They will share the existing import/export syntax, and both types of modules can be imported from the other.
Performance will be pay-for-play. Performance of Script Modules that don't use HTML Modules will not be affected; the only added cost would be various "is this an HTML or a Script Module" checks. There will be no impact outside of the module infrastructure.
Developers already familiar with ES6 Script Modules should find HTML Modules easy to pick up, as they introduce no changes to the existing import/export changes and are a logical extension of the current system. Areas that may present some initial difficulty are the use of inline Script Modules to define the exports of an HTML Module, and the fact that non-module scripts are not allowed in an HTML Module. We will need to ensure that this behavior is well-documented and that the errors emitted by DevTools are clear and helpful. Beyond these basic concepts though there is nothing that introduces significant complexity beyond that of existing ES6 Module behavior.
The debugging experience will be similar to that of ES6 Script Modules as it is today. Developers will be able to view the source files for HTML Modules in the DevTools Sources tab, and will be inline script in these files will support the same level as debugging as inline script in normal files (setting breakpoints, stepping through and inspecting vars, etc).
HTML Module documents and the elements they contain will be dumpable in the DevTools console tab like normal DOM content.
Yes, this feature will be platform agnostic.
Not yet, but we are working on a full set of tests that will be upstreamed to the web-platform-tests-suite.
TBD
No
if (mime_type == "text/html") {
// Create HTMLModule
} else if (MIMETypeRegistry::IsSupportedJavaScriptMIMEType(mime_type)) {
// Create ScriptModule
} else {
// Emit CORS error and refuse to create a module.
}
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/MW2PR2101MB113022D6F7A6903E890E45E0C5820%40MW2PR2101MB1130.namprd21.prod.outlook.com.
Hi Yutaka,
Good catch, this is just a typo. This error should be about MIME-type checking rather than CORS. The comment should really be “Emit an error that the file failed strict MIME type checking; ‘text/html’ or a JavaScript MIME-type is required” or something along those lines.
I’ll correct the document.
Thanks!
-- Dan
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CABihn6HphW87nv7SiSmU6hbM1P%2Bnu8wXVZ82s91-uKEitJDtNg%40mail.gmail.com.
Hi Georg,
Thanks for your detailed feedback! I’ve made the following changes to the proposed spec changes doc in response to your comments:
I’ve also made some changes in response to feedback elsewhere:
There are still some questions around whether the bulk of HTML Module Record and its algorithms should actually be defined in the HTML5 spec. I expect this document to continue to evolve.
Regarding your other comments:
I agree that coercing non-module scripts to type=”module” in HTML Module documents could be confusing. We’ve gotten this feedback elsewhere as well. I’ve updated the docs to state that a non-module script in an HTML Module document will be treated as a parse error that causes the HTML Module Record to fail to be created.
This is just a micro-optimization in the proposed V8 implementation. It’s similar to how things are already being done with Script Modules in V8, where the resolve-callback is used only during module Instantiation and the results are stashed so that the resolve-callback is not used again during module Evaluation.
My statement here was just incorrect, I had a misunderstanding about HeapObject layout in V8. I’ve removed it from the doc.
Thank you for taking the time to review the documents!
-- Dan
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/e9f12fb7-e802-4eaf-9bbe-1ed685abc4b5%40chromium.org.
This needs a Chrome Status entry too. I've given you access. Login is at the bottom. After logging in, look for the "Add new feature" button at the top.If an API's not documented it doesn't exist.
On Thu, Aug 1, 2019 at 10:06 PM 'Arvind Murching' via blink-dev <blin...@chromium.org> wrote:
--Arvind
On Thursday, August 1, 2019 at 5:14:12 PM UTC-7, rek...@gmail.com wrote:Hello Microsoft, pardon the late reply:Is there any where to track this feature's implementation? I don't see any tickets linked in the original post. I would love to see something to track.If I don't hear back, I can open an issue. I did search the bug tracker but didn't find anything. At the moment I have to keep scanning the entire internet to see if I find anything like news on this topic, and having something concrete to look in at would be a great help. Thanks.
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blin...@chromium.org.