Re: [w3ctag/design-reviews] Multiple import maps (Issue #980)

> * We see that you require the mapping to be stable while loading a module graph, but what about between different graphs?

Apologies! That part has changed as part of the PR review, and I failed to update the relevant part in the explainer.
After lengthy discussions, @hiroshige-g [convinced me](https://github.com/whatwg/html/pull/10528#issuecomment-2344316558) that a single global tree is better.

I agree that we can't get rid of non-determinism here entirely. As you say, async top-level modules where the import map is defined later may resolve their dependencies either before or after the map is processed. The same can be true for dynamic imports.

At the same time, I wouldn't expect this to be a problem in practice:
* Non-determinism already exists, and it doesn't seem to be a problem in practice (e.g. a dynamic import can invalidate an import map if it currently loads before it)
* I'd expect developers to define the import maps relevant to their modules and load them when needed. I'd wouldn't expect these maps to have a lot of conflicts in practice.
  - A real-life scenario we're seeing is that different parts of an app are handled by different teams/entities, each managing its own modules and their mapping. In this case I'd expect zero overlap.
  - Another real-life scenario this would enable is a large app that dynamically loads parts as they are needed, and injects the relevant mapping before the dynamic import is called. In these apps, any overlap between the maps is likely to be duplicate rules, and hence ignoring them won't change resolution.

> * If a mapping is used, but does not resolve successfully (perhaps because no mapping exists) is that a state that needs to persist?  Why is that safe?

Can you expand on this? I'm not following..

> * The discussion in [Sharing styles with Declarative Shadow DOM w3c/tpac2024-breakouts#31 (comment)](https://github.com/w3c/tpac2024-breakouts/issues/31#issuecomment-2387141476) seemed to indicate that server-rendered custom elements would want to add inlined CSS modules to the module map as they're sent to the client. Does that need support from this proposal, and if so does this proposal support it? cc/ @justinfagnani @rniwa

Injecting inline modules into the module map seems largely orthogonal to import maps. I played around with it a bit (as a [prototype](https://chromium-review.googlesource.com/c/chromium/src/+/5649434) for some interesting loading experiments that I need to get back to), and I think the main question there is "how do we determine the specifier?". Once we've answered that, I don't know that it makes sense to use import maps to translate that specifier to a URL, where there is no such URL in practice.

 

> I don't know if it needs support from this proposal directly, but I do think that the edge cases we talked about wrt inlined style modules that populate the module map are the same and should be handled consistently - probably by referring to common steps?
> 
> The main edge cases are race conditions between an import from a module in the module graph, and the handling of an inline module (or dynamic import map here), ie a fetch of a module is in-flight while an inline entry for the module is discovered. Assuming this proposal specifies what happens in those cases, it'll be a big help for the inline modules proposal.

While there are some similarities, relying on a specifier to be in the *module map* for resolution and defining specifier mapping in the *import map* seem like different problems, at least at first glance. For the latter, I think we can safely ignore rules which overlap with past import maps or past resolved modules. For the former, we'd need to decide what we do when the required modules are not (yet?) there at resolution time. 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/980#issuecomment-2415641921
You are receiving this because you are subscribed to this thread.

Message ID: <w3ctag/design-reviews/issues/980/2415641921@github.com>

Received on Wednesday, 16 October 2024 03:18:55 UTC