Skip to content

Commit a402c93

Browse files
Fix: race-network-and-fetch-handler now uses actual |raceResponse| (#1777)
This commit originates from the work proposed by @monica-ch and accepted a code change suggested by @domenic, but has been extensively reworked based on review feedback. This commit corrects response handling for race-network-and-fetch-handler. Primary Fix: The handler now correctly uses the actual fetch response for |raceResponse| instead of a generic [=network error=]. Minor Improvement: |timingInfo| is now included in the [=network error=], when returned by [=Create Fetch Event and Dispatch=], which simplifies the calling code.
1 parent 8374134 commit a402c93

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/index.bs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,11 +3265,10 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32653265
1. Let |raceResponse| be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
32663266
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
32673267
1. Set |raceFetchController| to the result of calling [=fetch=] given |request|, with [=fetch/processResponse=] set to the following steps given a [=/response=] |raceNetworkRequestResponse|:
3268+
1. Set |raceResponse|'s [=race response/value=] to |raceNetworkRequestResponse|.
32683269
1. If |raceNetworkRequestResponse|'s [=response/status=] is [=ok status=], then:
3269-
1. Set |raceResponse|'s [=race response/value=] to |raceNetworkRequestResponse|.
32703270
1. Let |raceNetworkResult| be a [=race result=] whose [=race result/routed response=] is |raceNetworkRequestResponse| and [=race result/used route=] is {{RouterSourceEnum/"network"}}.
32713271
1. [=queue/Enqueue=] |raceNetworkResult| to |queue|.
3272-
1. Otherwise, set |raceResponse|'s [=race response/value=] to a [=network error=].
32733272
1. [=If aborted=] and |raceFetchController| is not null, then:
32743273
1. [=fetch controller/Abort=] |raceFetchController|.
32753274
1. Set |raceResponse| to a [=race response=] whose [=race response/value=] is null.
@@ -3282,6 +3281,8 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
32823281
1. Wait until |queue| is not empty.
32833282
1. Let |result| be the result of [=dequeue=] |queue|.
32843283
1. Let |routedResponse| be |result|'s [=race result/routed response=].
3284+
1. If |routedResponse| is null:
3285+
1. Return |timingInfo|.
32853286
1. If |result|'s [=race result/used route=] is {{RouterSourceEnum/"network"}}, then:
32863287
1. Set |routedResponse|'s [=service worker timing info=] be set to |timingInfo|.
32873288
1. Set |routedResponse|'s [=service worker timing info=]'s [=service worker timing info/worker final router source=] be set to |result|'s [=race result/used route=].
@@ -3340,6 +3341,9 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
33403341
1. Let |eventHandled| be null.
33413342
1. Let |handleFetchFailed| be false.
33423343
1. Let |respondWithEntered| be false.
3344+
1. Let |networkError| be a [=network error=].
3345+
1. If |raceResponse| is not null:
3346+
1. Set |networkError|'s [=response/service worker timing info=] to |timingInfo|.
33433347
1. Let |shouldSoftUpdate| be true if any of the following are true, and false otherwise:
33443348
* |request| is a [=non-subresource request=].
33453349
* |request| is a [=subresource request=] and |registration| is [=stale=].
@@ -3399,15 +3403,15 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
33993403
1. If |respondWithEntered| is false, then:
34003404
1. If |eventCanceled| is true, then:
34013405
1. If |eventHandled| is not null, then [=reject=] |eventHandled| with a "{{NetworkError}}" {{DOMException}} in |workerRealm|.
3402-
2. Return a [=network error=].
3406+
2. Return |networkError|.
34033407
1. If |eventHandled| is not null, then [=resolve=] |eventHandled|.
3404-
1. If |raceResponse|'s [=race response/value=] is not null, then:
3408+
1. If |raceResponse| is not null, and |raceResponse|'s [=race response/value=] is not null, then:
34053409
1. Wait until |raceResponse|'s [=race response/value=] is not "<code>pending</code>".
34063410
1. If |raceResponse|'s [=race response/value=] is a [=/response=], return |raceResponse|'s [=race response/value=].
34073411
1. Return null.
34083412
1. If |handleFetchFailed| is true, then:
34093413
1. If |eventHandled| is not null, then [=reject=] |eventHandled| with a "{{NetworkError}}" {{DOMException}} in |workerRealm|.
3410-
2. Return a [=network error=].
3414+
2. Return |networkError|.
34113415
1. If |eventHandled| is not null, then [=resolve=] |eventHandled|.
34123416
1. Return |response|.
34133417
</section>

0 commit comments

Comments
 (0)