Skip to content

Commit 7600b24

Browse files
Don't cache HTTP errors in the module map
Multiple parallel imports will still only fetch once, and if the fetch fails, will both error. A subsequent import (dynamic import, a dynamically inserted via `<script src="..." type="module">`, or a static import from either of these) to the same specifier will result in a re-fetch if the previous fetch failed. Tests: web-platform-tests/wpt#55505 Fixes #6768. Co-authored-by: Yoav Weiss <yoav.weiss@shopify.com>
1 parent 255188e commit 7600b24

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

source

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118847,17 +118847,16 @@ document.querySelector("button").addEventListener("click", bound);
118847118847
<li><p>Let <var>moduleMap</var> be <var>settingsObject</var>'s <span
118848118848
data-x="concept-settings-object-module-map">module map</span>.</p></li>
118849118849

118850-
<li><p>If <var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)] is
118851-
"<code data-x="">fetching</code>", wait <span>in parallel</span> until that entry's value
118852-
changes, then <span>queue a task</span> on the <span>networking task source</span> to proceed
118853-
with running the following steps.</p></li>
118850+
<li><p>If <var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)] is a
118851+
<span>module script</span> or null, run <var>onComplete</var> given
118852+
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)], and return.</p></li>
118854118853

118855-
<li><p>If <var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)] <span
118856-
data-x="map exists">exists</span>, run <var>onComplete</var> given
118854+
<li><p>If <var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)] is a <span>list</span>,
118855+
<span data-x="list append">append</span> <var>onComplete</var> to
118857118856
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)], and return.</p></li>
118858118857

118859118858
<li><p><span data-x="map set">Set</span> <var>moduleMap</var>[(<var>url</var>,
118860-
<var>moduleType</var>)] to "<code data-x="">fetching</code>".</p></li>
118859+
<var>moduleType</var>)] to « <var>onComplete</var> ».</p></li>
118861118860

118862118861
<li><p>Let <var>request</var> be a new <span data-x="concept-request">request</span> whose
118863118862
<span data-x="concept-request-url">URL</span> is <var>url</var>, <span
@@ -118911,9 +118910,20 @@ document.querySelector("button").addEventListener("click", bound);
118911118910
<span>ok status</span>,</p></li>
118912118911
</ul>
118913118912

118914-
<p>then <span data-x="map set">set</span> <var>moduleMap</var>[(<var>url</var>,
118915-
<var>moduleType</var>)] to null, run <var>onComplete</var> given null, and abort these
118916-
steps.</p>
118913+
<p>then:</p>
118914+
118915+
<ol>
118916+
<li><p>Let <var>callbacks</var> be
118917+
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)].</p></li>
118918+
118919+
<li><p><span data-x="map remove">Remove</span>
118920+
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)].</p></li>
118921+
118922+
<li><p><span data-x="list iterate">For each</span> <var>callback</var> of
118923+
<var>callbacks</var>: run <var>callback</var> given null.</p></li>
118924+
118925+
<li><p>Return.</p></li>
118926+
</ol>
118917118927
</li>
118918118928

118919118929
<li><p>Let <var>mimeType</var> be the result of <span data-x="extract a MIME type">extracting
@@ -118965,17 +118975,24 @@ document.querySelector("button").addEventListener("click", bound);
118965118975
</ol>
118966118976
</li>
118967118977

118978+
<li><p>Let <var>callbacks</var> be
118979+
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)].</p></li>
118980+
118968118981
<li>
118969-
<p><span data-x="map set">Set</span> <var>moduleMap</var>[(<var>url</var>,
118970-
<var>moduleType</var>)] to <var>moduleScript</var>, and run <var>onComplete</var> given
118971-
<var>moduleScript</var>.</p>
118982+
<p>If <var>moduleScript</var> is null, then <span data-x="map remove">remove</span>
118983+
<var>moduleMap</var>[(<var>url</var>, <var>moduleType</var>)]; otherwise
118984+
<span data-x="map set">set</span> <var>moduleMap</var>[(<var>url</var>,
118985+
<var>moduleType</var>)] to <var>moduleScript</var>.</p>
118972118986

118973118987
<p class="note">It is intentional that the <span>module map</span> is keyed by the <span
118974118988
data-x="concept-request-url">request URL</span>, whereas the <span
118975118989
data-x="concept-script-base-url">base URL</span> for the <span>module script</span> is
118976118990
set to the <span data-x="concept-response-url">response URL</span>. The former is used to
118977118991
deduplicate fetches, while the latter is used for URL resolution.</p>
118978118992
</li>
118993+
118994+
<li><p><span data-x="list iterate">For each</span> <var>callback</var> of
118995+
<var>callbacks</var>: run <var>callback</var> given <var>moduleScript</var>.</p></li>
118979118996
</ol>
118980118997
</li>
118981118998
</ol>
@@ -121933,11 +121950,12 @@ dictionary <dfn dictionary>PromiseRejectionEventInit</dfn> : <span>EventInit</sp
121933121950
data-x="tuple">tuples</span> consisting of a <span>URL record</span> and a <span>string</span>.
121934121951
The <span>URL record</span> is the <span data-x="concept-request-url">request URL</span> at which
121935121952
the module was fetched, and the <span>string</span> indicates the type of the module (e.g. "<code
121936-
data-x="">javascript-or-wasm</code>"). The <span>module map</span>'s values are either a
121937-
<span>module script</span>, null (used to represent failed fetches), or a placeholder value "<code
121938-
data-x="">fetching</code>". </span><span data-x="module map">Module maps</span> are used to ensure
121939-
that imported module scripts are only fetched, parsed, and evaluated once per
121940-
<code>Document</code> or <a href="#workers">worker</a>.</p>
121953+
data-x="">javascript-or-wasm</code>"). The <span>module map</span>'s values are either a <span>module
121954+
script</span>, null (used to represent a mismatched <span>MIME type</span>), or a
121955+
<span>list</span> of algorithms (that are waiting for the fetch to complete).</span> <span
121956+
data-x="module map">Module maps</span> are used to ensure that imported module scripts are only
121957+
fetched, parsed, and evaluated once per <code>Document</code> or <a
121958+
href="#workers">worker</a>.</p>
121941121959

121942121960
<div class="example">
121943121961
<p>Since <span data-x="module map">module maps</span> are keyed by (URL, module type), the
@@ -162005,6 +162023,7 @@ INSERT INTERFACES HERE
162005162023
Logan Moore,
162006162024
Lorenz Ackermann,
162007162025
Loune,
162026+
Luca Casonato,
162008162027
Lucas Gadani,
162009162028
&#x0141;ukasz Pilorz,
162010162029
Luke Kenneth Casson Leighton,

0 commit comments

Comments
 (0)