Skip to content
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

How to handle non-type=”module” scripts in HTML Modules? #798

Open
travisleithead opened this issue Feb 27, 2019 · 6 comments
Open

How to handle non-type=”module” scripts in HTML Modules? #798

travisleithead opened this issue Feb 27, 2019 · 6 comments
Labels

Comments

@travisleithead
Copy link
Member

(Original OP by @dandclark)

The HTML Modules design discussed thus far forbids modules from containing non-module scripts. This allows for overall easier integration into ES modules (which would otherwise be difficult if parsing an HTML module could run script prior to module graph instantiation/evaluation), and prevents issues with parser-blocking scripts like those in HTML Imports.

However it’s not clear how this should best be achieved. Our original proposal suggested that non-module scripts in an HTML Module should be automatically converted to type=”module”. This is simple and saves the developer some typing, and is in a similar spirit as the JavaScript module behavior of silently enabling strict mode for all module scripts. The disadvantage is that it could be potentially confusing for a developer new to the feature. I first saw this concern raised here and here, and more recently on this blink-dev thread.

The alternative would be to treat a non-module script in an HTML Module as a parse error, resulting in a failure to instantiate the module. This is much more unambiguous, but devlopers might get a bit tired of needing to inlcude `type=”module” for every script element.

Since there has been discussion on this across a few different threads, I wanted to give a home to the topic here and see if some consensus can be reached.

Thoughts?

See also (#793)

@annevk
Copy link
Collaborator

annevk commented Feb 27, 2019

As long as there's a new MIME type, I think we should embrace all these kind of simplifications. I.e., we'll use the parser (with some overrides to enforce quirks mode and UTF-8) and the resulting objects, but the processing model on the resulting tree can be somewhat novel.

@matthewp
Copy link

At first I thought removing the type="module" would be confusing but the more I thought about it, it's similar to how JavaScript modules are different from classic scripts. I don't think people find it confusing that, for example, a JavaScript module's top-level variables aren't globally accessible. So I think similarly, HTML modules can remove some of the legacy defaults such as this and #797, and possibly more.

@ruphin
Copy link

ruphin commented Apr 22, 2019

A side-effect of removing the type="module" declarations from scripts in an html module file is that the html file itself may become invalid (when loaded directly as an HTML file, not as a module), because in this scenario the scripts will not be interpreted as module scripts. By going through with this, you are essentially creating two classes of *.html files; one that may be opened directly in a browser and one that may only be loaded as a module.

I'm not sure how much of a concern that is, but I think it is worth considering.

@annevk
Copy link
Collaborator

annevk commented Apr 23, 2019

That's going to happen either way, and that's also why there's #742.

@joeldenning
Copy link

joeldenning commented Aug 28, 2019

I just created a PR systemjs/systemjs#2011 that adds full support for polyfilling HTML modules.

In it, I had to take a stance on handling <script> elements that don't have a type="module". My current initial implementation throws an error.

Any update on this issue?

@dandclark
Copy link
Contributor

This question is still not 100% settled, so to be forward-compatible I think your initial decision to throw an error for non-module scripts is best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants