-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
import.meta.url does not include fragments #5162
Comments
I think there might be a bug in the fetch spec at [3] above since @annevk landed a change to explicitly start allowing fragments: |
Yeah, the intention is to include the fragment. There is even a test for it. https://wpt.fyi/results/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-url.html?label=master&label=experimental&aligned&q=script This was previously discussed in #3622. I will assign to @annevk to update [3] since it seems like the processing model is generally correct and includes the fragment, it's just that the text in [3] is not updated. |
Thanks!
This makes sense :) |
@wanderview that commit is part of an open PR at whatwg/fetch#696 and an open issue at whatwg/fetch#505. I'm not really sure why that did not move forward. It might have happened because I moved countries, nobody else cared, and I forgot about it. (There's various test PRs linked that do not have review.) |
@Constellation, I wonder why you say:
If the network layer ignores fragments to fetch module files, then how can modules with different fragments be distinct? Is this a way to enable instantiating a module many times and the fragment serves as arguments to the module? |
Ok, so light has come to my mind... I checked and classical scripts can use Now, for module scripts, this capability is way more powerful, as these can export values. If no additional network fetches are really made, then... this is almost like AMD loader plugins... // consumer.js
import bundle from "./i18n.js#path=a/b/c"); // i18n.js
const args = new URL(import.meta.url).hash;
const path = ...;
const locale = ...;
const bundle = await fetch(...);
export bundle; I wonder if this was intended... Now, what puzzles me is why the example in https://html.spec.whatwg.org/multipage/webappapis.html#module-map says:
Why 3 separate fetches and not 2? The first two imports are the same "web resource", no? Isn't this example incorrect, in the spec? Now, if only import maps allowed bare names with fragments, this would really be useful: // consumer.js
import bundle from "@my/i18n#path=a/b/c"); For reference: |
Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information.
The Fetch PR landed and fragments are generally preserved now. |
Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information.
Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information.
…ragment, a=testonly Automatic update from web-platform-tests import.meta.url should include the URL fragment Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information. -- wpt-commits: 1c1e48b75ebf98fd3db4af8a330fcb6109942ce5 wpt-pr: 32704
Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information.
…ragment, a=testonly Automatic update from web-platform-tests import.meta.url should include the URL fragment Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information. -- wpt-commits: 1c1e48b75ebf98fd3db4af8a330fcb6109942ce5 wpt-pr: 32704
…ragment, a=testonly Automatic update from web-platform-tests import.meta.url should include the URL fragment Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information. -- wpt-commits: 1c1e48b75ebf98fd3db4af8a330fcb6109942ce5 wpt-pr: 32704
…ragment, a=testonly Automatic update from web-platform-tests import.meta.url should include the URL fragment Update workers/modules/shared-worker-import-meta.html to expect import.meta.url to include the URL fragment. This matches the behavior of both WebKit and Blink. See whatwg/html#5162 for more information. -- wpt-commits: 1c1e48b75ebf98fd3db4af8a330fcb6109942ce5 wpt-pr: 32704
While upgrading WebKit module loader, @youennf noticed that we are using response's url when creating module-script[1].
However, response's url does not include fragments[2,3]. This means,
import.meta.url
does not include fragments, and this behavior does not agree with what WPT is testing[4].Shouldn't we include fragments in
import.meta.url
? Or should we do that by fixing the current HTML spec? I'm thinking that we should expose fragments because each module w/ URL+different fragments is distinct. But this means we cannot use response's url forimport.meta.url
in the HTML spec though./cc @domenic
1: https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
2: https://fetch.spec.whatwg.org/#ref-for-response-url
3: https://fetch.spec.whatwg.org/#response-url
4: https://github.com/web-platform-tests/wpt/blob/master/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-url.html#L54-L57
The text was updated successfully, but these errors were encountered: