Skip to content
12 changes: 11 additions & 1 deletion docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3263,13 +3263,16 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. Let |queue| be an empty [=queue=] of [=race result=].
1. Let |raceFetchController| be null.
1. Let |raceResponse| be a [=race response=] whose [=race response/value=] is "<code>pending</code>".
1. Let |networkFetchCompleted| be false.
1. Let |fetchHandlerCompleted| be false.
1. Run the following substeps [=in parallel=], but [=abort when=] |fetchController|'s [=fetch controller/state=] is "<code>terminated</code>" or "<code>aborted</code>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing setup seems a bit fragile to me. The definition of abort when only operates between steps, and there are only two steps nested under "If aborted"... In fact there is only one step before this PR.

Probably there should be a check on fetchController's state inside the processResponse callback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not confident but I tried to address that with #1779.
Is it what you meant?

1. Set |raceFetchController| to the result of calling [=fetch=] given |request|, with [=fetch/processResponse=] set to the following steps given a [=/response=] |raceNetworkRequestResponse|:
1. If |raceNetworkRequestResponse|'s [=response/status=] is [=ok status=], then:
1. Set |raceResponse|'s [=race response/value=] to |raceNetworkRequestResponse|.
1. Let |raceNetworkResult| be a [=race result=] whose [=race result/routed response=] is |raceNetworkRequestResponse| and [=race result/used route=] is {{RouterSourceEnum/"network"}}.
1. [=queue/Enqueue=] |raceNetworkResult| to |queue|.
1. Otherwise, set |raceResponse|'s [=race response/value=] to a [=network error=].
1. Set |networkFetchCompleted| to true.
1. [=If aborted=] and |raceFetchController| is not null, then:
1. [=fetch controller/Abort=] |raceFetchController|.
1. Set |raceResponse| to a [=race response=] whose [=race response/value=] is null.
Expand All @@ -3279,7 +3282,14 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. If |fetchHandlerResponse| is not null and not a [=network error=], and |raceFetchController| is not null, [=fetch controller/abort=] |raceFetchController|.
1. Let |raceFetchHandlerResult| be a [=race result=] whose [=race result/routed response=] is |fetchHandlerResponse| and [=race result/used route=] is {{RouterSourceEnum/"fetch-event"}}.
1. [=queue/Enqueue=] |raceFetchHandlerResult| to |queue|.
1. Wait until |queue| is not empty.
1. Set |fetchHandlerCompleted| to true.
1. Wait until any of the following are true:
1. |queue| is not empty.
1. Both |networkFetchCompleted| and |cacheLookupCompleted| are true.
1. If |queue| is empty, then:
1. If |raceResponse|'s [=race response/value=] is a [=/response=], return |raceResponse|'s [=race response/value=].
1. If |raceResponse|'s [=race response/value=] is a [=network error=], return a [=network error=].
1. Return null.
1. Let |result| be the result of [=dequeue=] |queue|.
1. Let |routedResponse| be |result|'s [=race result/routed response=].
1. If |result|'s [=race result/used route=] is {{RouterSourceEnum/"network"}}, then:
Expand Down