From d0832ba27d8b765ff644d093c677621fddfa623e Mon Sep 17 00:00:00 2001 From: Yoshisato Yanagisawa Date: Fri, 5 Sep 2025 02:08:14 +0000 Subject: [PATCH] Handle Fetch: Use correct storage key for subresource requests This change corrects the cache resolution logic within the Handle Fetch algorithm when the router source is RouterSourceEnum/"cache". The Problem: Previously, the algorithm always used reservedClient to resolve the storage key, regardless of the request type. However, reservedClient is only valid for top-level navigation requests and is not available for subresource requests. This could lead to accessing the incorrect cache storage during subresource fetches. The Fix: Logic has been added to differentiate between a non-subresource request and a subresource request. - For a non-subresource request: It continues to use reservedClient as before. - For a subresource request: It now uses the client associated with the request object. This ensures that the correct storage key, based on the requesting client, is used for subresource requests. Fixes: https://github.com/w3c/ServiceWorker/issues/1784 --- docs/index.bs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/index.bs b/docs/index.bs index 2fb44bdc..5a7fd11e 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -3241,7 +3241,12 @@ spec: storage; urlPrefix: https://storage.spec.whatwg.org/ 1. Else if |source| is {{RouterSourceEnum/"cache"}}, or |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=], then: 1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|. 1. Set |timingInfo|’s [=service worker timing info/worker cache lookup start=] to the [=coarsened shared current time=] given |useHighResPerformanceTimers|. - 1. Let |caches| be the result of running [=obtain a local storage bottle map=] with |reservedClient| and "caches". + 1. Let |environment| be null. + 1. If |request| is a non-subresource request, then: + 1. Set |environment| to |reservedClient|. + 1. Else: + 1. Set |environment| to |client|. + 1. Let |caches| be the result of running [=obtain a local storage bottle map=] with |environment| and "caches". 1. [=map/For each=] |cacheName| → |cache| of |caches|. 1. If |source|["{{RouterSourceDict/cacheName}}"] [=map/exists=] and |source|["{{RouterSourceDict/cacheName}}"] [=string/is=] not |cacheName|, [=continue=]. 1. Let |requestResponses| be the result of running [=Query Cache=] with |request|, a new {{CacheQueryOptions}}, and |cache|.