Skip to content

Fix: race-network-and-fetch-handler now uses actual |raceResponse| #1777

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

Merged
merged 11 commits into from
Jun 13, 2025
14 changes: 14 additions & 0 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3263,16 +3263,21 @@ 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 |networkFetchResult| be null.
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 |networkFetchResult| to |raceNetworkRequestResponse|.
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.
1. Set |networkFetchCompleted| to true.
1. Resolve |preloadResponse| with undefined.
1. Run the following substeps [=in parallel=]:
1. Let |fetchHandlerResponse| be the result of [=Create Fetch Event and Dispatch=] with |request|, |registration|, |useHighResPerformanceTimers|, |timingInfo|, |workerRealm|, |reservedClient|, |preloadResponse|, and |raceResponse|.
Expand All @@ -3282,6 +3287,15 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/
1. Wait until |queue| is not empty.
1. Let |result| be the result of [=dequeue=] |queue|.
1. Let |routedResponse| be |result|'s [=race result/routed response=].
1. If |routedResponse| is null or a [=network error=], then:

Note: the [=Create Fetch Event and Dispatch=] return value is queued regardless of its value. Failure response means the raced fetch handler failed.

1. Wait until |networkFetchCompleted| is true.
1. If |networkFetchResult| is null:
1. Return |timingInfo|.
1. Set |networkFetchResult|'s [=service worker timing info=] to |timingInfo|.
1. Return |networkFetchResult|.
1. If |result|'s [=race result/used route=] is {{RouterSourceEnum/"network"}}, then:
1. Set |routedResponse|'s [=service worker timing info=] be set to |timingInfo|.
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=].
Expand Down