Re: [WICG/webcomponents] HTML Modules (#645)

justinfagnani left a comment (WICG/webcomponents#645)

@noamr I think that proposal may be conflating HTML Modules (and HTML Imports before them) a bit with HTML Includes, which is a problem we've had for a while.

Specifically, HTML Modules should act like a lot like JS, JSON, and CSS modules - they serve as containers for definitions and values, and their exports are shared among their importers. Their exports should _not_ be cloned when imported.

The first problem is that breaks the usual semantics of imports/export and modules. Exports are live, and just importing does not trigger any actions at all. A module cannot even tell that an export was imported somewhere. I think some side-effect upon import would be a very big departure for JS.

Secondly, if multiple modules import a template from an HTML module, they must get the same template instance. If you clone the template on import you can break template systems that rely on template identity for DOM stable updates.

The next issue I see is sanitization. Everything from an HTML module should be as trusted as developer-controlled script in JS modules. Like JS, CSS, and JSON, you _should not_ import untrusted resources. HTML Modules need to be able to run script, after all. Sanitization directly interferes with the primary use case of HTML Modules, which is to allow developer to put HTML in HTML files, rather than strings in JS files.

So, `{type: 'fragment'}`* might be it's useful own thing, but it's quite separate from HTML Modules as far as I can tell, and I think given the long history of confusion between the two concepts, that distinction should be clarified.

I'm also not sure about the use case for importing fragments directly into JS. The use case seems much more obvious in HTML, where HTML Includes are loudly requested, but from JS? I don't see that as much. If we had HTML modules, a developer could easily import and clone a template themselves. If the content is untrusted, I'm not sure they should be using the module system.

*fragment of what? I don't think that's obvious in a JS context. It should probably be `{type: 'html-fragment'}`.

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

Message ID: <WICG/webcomponents/issues/645/4212970280@github.com>

Received on Thursday, 9 April 2026 09:09:46 UTC