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

Support import maps in workers #10858

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

Conversation

nicolo-ribaudo
Copy link
Contributor

@nicolo-ribaudo nicolo-ribaudo commented Dec 12, 2024

This patch started as a conversation with @guybedford. I tried writing some spec for one of the potential approaches discussed in WICG/import-maps#2.

This PR is not actually ready as I have not finished reading all the discussions about the topic and I haven't talked with any implementation, but it's better to leave it here as a draft in case somebody is interested than just keeping it hidden in a branch :)

There are two commits: one that allows workers to inherit the import map from their creator (which probably will be the most common use case?), and one that allows to explicitly pass an import map object. The two commits don't conceptually depend on each other, so it would also be ok to decide to only do one of them.

This patch does not support import maps for SharedWorker, but thanks to the work done in #10528 it would be possible to support them: when a page connects to an existing shared worker, the shared worker's import map can get "updated" with the new one. Generally import maps in multiple pages of a same application match in their intersection, so this would probably give a good behavior (the alternative is to throw when passing an import map that is different from the existing one).

This approach does not work for ServiceWorker, and they would likely need a completely different solution (such as the HTTP-header based ones that were suggested in WICG/import-maps#2).


  • At least two implementers are interested (and none opposed):
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
    • Deno (only for timers, structured clone, base64 utils, channel messaging, module resolution, web workers, and web storage): …
    • Node.js (only for timers, structured clone, base64 utils, channel messaging, and module resolution): …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs:
  • MDN issue is filed: …
  • The top of this comment includes a clear commit message to use.

(See WHATWG Working Mode: Changes for more details.)


/infrastructure.html ( diff )
/webappapis.html ( diff )
/workers.html ( diff )

This option adds an `importMap: "none" | "clone"` option to the `Worker`
constructor, which defaults to `"none"`. When this option is set to
`"clone"`, the `Worker` constructor will take a snapshot of the current
import map and use it as the import map inside the worker.

Passing the `importMap` option to `SharedWorker` is an error, to make it
possible to give it a meaning in the future.
This commit allows passing a JavaScript object to `Worker`'s `importMap`
option, which is validated and used as the worker's import map.

The existing validation of the JSON import map has been delegated to
WebIDL, so that it can be re-used for this option's value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant