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

Cover multiple import maps #37739

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

yoavweiss
Copy link
Contributor

Description

This PR aims to cover the "multiple import maps" HTML change

Motivation

Current import map language is misleading, at least in ToT Chromium/WebKit.

Additional details

Related issues and pull requests

Fixes mdn/mdn#622

@yoavweiss yoavweiss requested a review from a team as a code owner January 21, 2025 13:40
@yoavweiss yoavweiss requested review from chrisdavidmills and removed request for a team January 21, 2025 13:40
@github-actions github-actions bot added Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed labels Jan 21, 2025
Copy link
Contributor

github-actions bot commented Jan 21, 2025

Preview URLs

Flaws (23)

URL: /en-US/docs/Web/HTML/Element/script/type/importmap
Title: <script type="importmap">
Flaw count: 23

  • macros:
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/HTML
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/Getting_started_with_the_web/HTML_basics
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/HTML/Introduction_to_HTML
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started
    • Wrong xref macro used (consider changing which macro you use). Error processing path /en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML
    • and 18 more flaws omitted
External URLs (1)

URL: /en-US/docs/Web/HTML/Element/script/type/importmap
Title: <script type="importmap">

(comment last updated: 2025-01-22 10:30:40)

Copy link
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoavweiss!

Thanks for the awesome work here in getting this documented. I have a few horrible nitpicky comments for you to consider (too much coffee, maybe), but I think this is going in the right direction.


<aside>This is supported is the latest versions of some browsers. In non-supporting browsers, a [polyfill](https://github.com/guybedford/es-module-shims) can be used to avoid issues related to module resolution.</aside>

Internally, browsers maintain a single global import map representation.
Copy link
Contributor

@chrisdavidmills chrisdavidmills Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no explanation here of how the browser handles multiple import maps. I can guess from the heading that they are merged in some way into the single global import map representation when you include them in a document, but it is not explicitly covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged (pun not intended) this sentence and the next to try and make that clearer. Let me know if more details are needed.


When an import map is registered, its contents are merged into the global import map.

Module specifiers in the registered map that were already resolved before are dropped. Future resolution of these specifiers will provide the same results as their previous resolution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last two sentences make sense, but I do have a few comments for you to consider:

  • "Future resolution of these specifiers will provide the same results as their previous resolution." seems to contradict the "are dropped" assertion — it sounds like "are dropped" might be saying that that they are ignored, whereas the first quoted sentence sounds like they are evaluated but provide the same result. It would be good to be clearer about what's going on.
  • "prevails" makes sense, but seems like a slightly weird word to use in a tech context. I had to read it a few times to figure out what you were saying, and I wonder how understandable it is to the majority of readers who have English as an additional language. You could say something like "previous mapping continues to take effect", or maybe even something simpler like "previous mapping wins"?
  • I think this stuff would be easier to understand if you described a scenario where you have a first import map that contains mappings A and B, then a second map containing mappings A and C. When the first one is evaluated, A and B are added to the global map. When the second one is evaluated, C is added, but A is ignored because it was already previously added, etc. At the moment, you can guess that you are talking about specifiers that were already included in previous import maps, but it would be helpful to make this explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a series of examples after the processing model in https://html.spec.whatwg.org/#merge-module-specifier-maps. Do you think it would make sense to bring in some of those here to make the behavior clearer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple import maps
2 participants