-
Notifications
You must be signed in to change notification settings - Fork 72
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
Order/Priority of multiple import maps #114
Comments
Have you looked at this: https://github.com/WICG/import-maps/blob/master/spec.md#installation ? It doesn't directly answer your questions but I think most can be inferred. For 1) I would definitely expect |
Yes, I have read that section, but I don't actually see anything related to order or priority of import maps. What sentences are you referring to? All I see is this:
Which seems to indicate that "encountering" an import map is what kicks of the procedure, but it doesn't explain what that means. Is it an encounter during initial load? Is it in document order? What about dynamically injected import maps, do they take priority when they are "encountered" in the DOM? Does that respect document order? What if fetching one import map takes longer than another? The spec is quite unclear as far as I can tell, which is why I created this issue 😄 |
I believe this refers to script processing order. Where processing an
import maps means fetching and applying it, while processing a module
script means just starting the load operation as they are defer semantics.
…On Thu, 14 Mar 2019 at 19:03, Joel Denning ***@***.***> wrote:
Yes, I have read that section, but I don't actually see anything related
to order or priority import maps. What sentences are you referring to? All
I see is this:
Encountering a <script type="importmap"> while acquiring import maps is
true will kick off a procedure
Which seems to indicate that "encountering" an import map is what kicks of
the procedure, but it doesn't explain what that means.
And the spec definitely does not clarify Scenario 2 and Scenario 3, either.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAkiys9CBunZEsLb5D9cqnIs8-fUih5Sks5vWoDPgaJpZM4bwCn_>
.
|
@guybedford what is script processing order? When I say document order, I am referring to the definition here. I assume script processing order would be the same? Although maybe respecting the defer/async attributes? Also, how does that relate to Scenario 3? |
I’m not using an official term - I’m just referring to the way processing
progresses for script tags only executing each one after the other. Import
maps are just like this from an execution point of view (not defer).
There is absolutely no support for dynamically injecting import maps in the
spec so there aren’t any edge cases in those scenarios. I’d like these to
be specified in future based on interleaving work order though.
The only real edge case to handle given the static semantics is throwing
for import maps coming after module scripts in document order.
…On Thu, 14 Mar 2019 at 19:10, Joel Denning ***@***.***> wrote:
@guybedford <https://github.com/guybedford> what is script processing
order? When I say document order, I am referring to the definition here
<https://www.w3.org/TR/DOM-Level-2-Traversal-Range/glossary.html#dt-documentorder>.
I assume script processing order would be the same? Although maybe
respecting the defer/async attributes?
Also, how does that relate to Scenario 3?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAkiylSWUeG5vI6S84chsStc5WCvGNziks5vWoKRgaJpZM4bwCn_>
.
|
What about https://github.com/WICG/import-maps#dynamic-import-map-example, which shows how to do dynamic imports? Is the Readme out of date? |
I see, no I’m wrong then, dynamic injection is supported as long as no
module imports have been made.
But that doesn’t change the implementation feedback from what I’ve
described above. We could introduce mutation observers to capture dynamic
injection in due course though certainly.
…On Thu, 14 Mar 2019 at 19:25, Joel Denning ***@***.***> wrote:
There is absolutely no support for dynamically injecting import maps in
the spec so there aren’t any edge cases in those scenarios.
What about https://github.com/WICG/import-maps#dynamic-import-map-example,
which shows how to do dynamic imports? Is the Readme out of date?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAkiyqiQSy0JSNhpV-T7ZIinyAY487ufks5vWoX0gaJpZM4bwCn_>
.
|
I don't believe that mutation observers would be necessary to implement this in a userland polyfill, unless the polyfill wanted to implement the following part of the spec:
Supporting this ^ would require a MutationObserver, I think, but in the non-error case I think that you can get away without a MutationObserver. Instead, a Back to the original question, though, I'm still looking for answers on how to handle Scenarios 1, 2, and 3. |
I just want to say these are all good questions, and I don't have good answers yet. I'm hoping to write a more formal spec soon-ish, but until then I can only offer vague intuition, plus the offer to test with Chrome's experimental implementation to get some idea of what at least one implementer thought was possible and relatively easy to implement. Stay tuned! |
There isn't one that directly answers your question. I was just pointing out the link in case you hadn't seen it. The Merging import maps section gives a general idea of prioritization in that the "last one wins". My intuition is that this should behave the same as JavaScript scripts/modules. If we have 2 scripts that both define the global |
👍 thanks for the update. As someone attempting a polyfill implementation in SystemJS, I'll throw in my two cents on an approach the spec could take. I think it would make most sense for import maps to begin fetching as soon as possible, but that the priority of the import maps should be the document order of the An alternative approach would be to use document order for the initial page load but then just immediately apply dynamic imports as they get injected after the initial page load, regardless of their document order. I think that this is more confusing for the html/javascript developer, because the final merged import map cannot be reasoned about or reconstructed by looking at the document order in the DOM. |
Thanks for inputs! [1] order of fetch completionIn the initial spec draft #136, the priority of import maps is the order of fetch completion (external import maps) or insertion to DOM (inline import maps).
( [2] order of
|
(2) makes a ton of sense to me. It basically means the import maps get "evaluated" (i.e. parsed and merged into the realm's overall import map) like classic scripts are. |
I think that Option 2 is confusing for a js developer debugging what the final resolved URL is for a module. "Why did this import map outprioritize the other?" cannot be understood without mutation observer or stepping carefully through code. Additionally, Option 2 is much more difficult to polyfill (afaict, mutation observers would be required), although polyfillability might not be an overriding concern. One thing I like about Option 2 is that it isn't tied to the "acquiring import maps" boolean, which I think is great because that boolean seems unnecessarily limiting to the js developer and I don't see a technical constraint that calls for it. (That's a separate topic discussed in #92, though) Perhaps the debuggability concern I raised could be solved through a future API that exposes all the import maps, including their injection order and the final merged map. Option 2 sounds okay to me, I think my perspective has changed since my last post a few months ago 👍 |
I think this is the same as defer/module scripts, which are executed in the order of prepare-a-script, regardless of the final document order in the DOM. ("the same as existing scripting mechaism" doesn't necessarily mean that it is good though)
Do you mean that the priority of import maps doesn't depend on the timing when "acquiring import maps" boolean is cleared? Or any other specific aspects? (Still "acquiring import maps" boolean forbids new import maps once cleared) |
Good point. I'm wondering how strictly we should keep the interoperability between browsers/spec and polyfills. This complexity might be a side effect of specifying import maps as a part of |
Yep that's what I mean. Option 3 has to delay processing until the "acquiring import maps" boolean changes from true to false.
Agreed. And yeah I think a polyfill being slightly noncompliant with this part of the spec will be okay. My implementation within SystemJS has already landed, using document order to prioritize them. I doubt that many (or any) of systemjs users will notice or complain about the deviation.
Yeah I agree. Sticking to a complex, but well established, pattern for script loading sounds like a better thing to do. I'm fully onboard with Option 2 now. |
If it’s at all non compliant, it’s not a polyfill. Polyfillability doesn’t have to block a feature, but it should simply not be polyfilled (shimmed) if it can’t be done accurately (shammed). |
Haha well feel free to PR systemjs or create another polyfill 😄 Like @hiroshige-g said, polyfilling this would be pretty hard:
SystemJS is optimized to be the smallest js library it can be in terms of bytes, so mutation observers with nuanced behavior might be too much bloat for the project. @guybedford is the primary maintainer of systemjs so he'd be the one to decide. |
Agreed; I really appreciate the efforts of the SystemJS folks here, and I don't think gatekeeping on the definition of polyfill is a conducive way to move the ecosystem forward. |
Previously, import maps were processed when they are fetched, and therefore the priority of import maps and order of error events was nondeterministic. This commit introduces a mechanism to process import maps in the order of "prepare a script", and thus fixes #114. To do so, it expands the general integration of import maps with "prepare a script" to make them more symmetrical to module and classic scripts in that regard.
When there are multiple import maps present on a page, which one takes precedence? Is "document order" employed to determine the order?
Is the document order enforced at the moment when "acquiring import maps" is set to false? Or is document order enforced during initial loading of the page, and then dynamically injected import maps ignore document order and are applied in the order in which they are injected into the document?
Scenario 1 - Two fetched import maps during initial load/processing
If import-map1.json takes longer to fetch than import-map2.json, which import map takes precedence? Meaning if both define the same module, which import map wins?
Scenario 2 - No import maps during initial load, two dynamically injected in reverse document order
Import Map 2 is first in the DOM, but it was injected into the DOM second. Which one takes priority?
Scenario 3 - Dynamic import injected after initial page load
Very similar to Scenario 2, except accentuating the difference in timing of when these import maps get put into the DOM. Which import map will take priority?
The text was updated successfully, but these errors were encountered: