Add "json" destination, for JSON modules#1691
Merged
annevk merged 4 commits intowhatwg:mainfrom Oct 29, 2023
Merged
Conversation
7 tasks
annevk
reviewed
Jul 25, 2023
Member
annevk
left a comment
There was a problem hiding this comment.
Looks great modulo some nits.
I think we can count Chromium and WebKit as supportive based on statements in whatwg/html#7233, but I'll tag some people here just in case.
81b9d07 to
450893f
Compare
Member
|
@nicolo-ribaudo are you planning to write tests for this and implementation bugs? |
This was referenced Oct 10, 2023
|
cc/ @domenic |
Contributor
Author
|
Tests have been merged! |
annevk
pushed a commit
to whatwg/html
that referenced
this pull request
Oct 29, 2023
Builds on whatwg/fetch#1691. Tests: web-platform-tests/wpt#41665. Fixes #7233.
aarongable
pushed a commit
to chromium/chromium
that referenced
this pull request
Jan 19, 2024
The "Import Attributes" ECMAScript proposal has been updated to allow attributes to affect how modules are fetched, so that HTML can use them to set the proper destination when fetching CSS and JSON modules [1]. This has two major effects: - the `Accept` HTTP header is now specific to the module type, rather than simply being `*/*` - we use the relevant CSP policy rather than always script-src. This patch only implements this change for CSS modules. The change for JSON modules will come in a later patch, as it's more complex because it requires introducing a new fetch destination [2]. It passes the relevant wpt tests [3] when using --js-flags="--harmony_import_attributes. [1]: whatwg/html#9486 [2]: whatwg/fetch#1691 [3]: web-platform-tests/wpt#41665 Bug: 1491336 Change-Id: I4abf09dd828e5ded2b685be6da231c3fca90e19f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4949956 Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org> Reviewed-by: Stephen Chenney <schenney@chromium.org> Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Commit-Queue: Nicolò Ribaudo <nribaudo@igalia.com> Cr-Commit-Position: refs/heads/main@{#1249592}
aarongable
pushed a commit
to chromium/chromium
that referenced
this pull request
Jan 20, 2024
This patch adds a new `json` fetch destination [fetch-spec-pr], that has
the following characteristics:
- it implies the `Accept: application/json,*/*;q=0.5` HTTP header;
- it uses the `connect-src` CSP directive [csp-spec-pr].
This new destination is used when fetching JSON module scripts, using
`import ... from "/data" with { type: "json" }` [html-spec-pr].
https://crrev.com/c/4949956 implements a similar change for CSS module
scripts, but their implementation is simpler because the `style`
destination already exists.
This patch passes all the relevant WPT tests [wpt-pr] (when using
--js-flags="--harmony_import_attributes), although I had to run them
manually because they have not been merged yet.
This patch does not add support for `<link rel="preload" as="json">`,
which is also introduced by the linked fetch and HTML spec changes.
[fetch-spec-pr]: whatwg/fetch#1691
[csp-spec-pr]: w3c/webappsec-csp#611
[html-spec-pr]: whatwg/html#9486
[wpt-pr]: web-platform-tests/wpt#41665
Bug: 1491336
Change-Id: I6661ddc9be04935e2ee760eb78d1060ae0192a55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4955077
Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: Xinghui Lu <xinghuilu@chromium.org>
Commit-Queue: Nicolò Ribaudo <nribaudo@igalia.com>
Cr-Commit-Position: refs/heads/main@{#1249822}
lozy219
pushed a commit
to lozy219/html
that referenced
this pull request
Mar 10, 2025
Builds on whatwg/fetch#1691. Tests: web-platform-tests/wpt#41665. Fixes whatwg#7233.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The import attributes TC39 proposal has been updated so that HTML can use the expected type (unspecified,
json,css) to affect the fetch request. This PR introduces the"json"destination, that will be used to fetchimport "..." with { type: "json" }.Ref whatwg/html#9486 (comment), whatwg/html#7233
Acceptheader for JSON modules with network imports denoland/deno#20866Acceptheader for JSON modules with network imports nodejs/node#50116jsonto possible fetch destinations mdn/content#29573(See WHATWG Working Mode: Changes for more details.)
Preview | Diff