From 7507ed2e54b0d33aeec32e63126e3212dd2d911a Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 23 Jun 2021 15:27:50 +0300 Subject: [PATCH] fix(service-worker): use correct names when listing `CacheDatabase` tables (#42622) `CacheDatabase` uses the un-prefixed table names to interact with database tables. However, the `list()` method returns the raw, prefixed table names (which are not useful, since they cannot be used to open/delete a table). This commit fixes this by removing the prefix from the cache names returned by the `list()` method. NOTE: This method is currently not used anywhere, so this change does not affect the ServiceWorker behavior. PR Close #42622 --- packages/service-worker/worker/src/db-cache.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/service-worker/worker/src/db-cache.ts b/packages/service-worker/worker/src/db-cache.ts index ca21c267a9..613004fd04 100644 --- a/packages/service-worker/worker/src/db-cache.ts +++ b/packages/service-worker/worker/src/db-cache.ts @@ -31,7 +31,10 @@ export class CacheDatabase implements Database { const prefix = `${this.cacheNamePrefix}:`; const allCacheNames = await this.scope.caches.keys(); const dbCacheNames = allCacheNames.filter(name => name.startsWith(prefix)); - return dbCacheNames; + + // Return the un-prefixed table names, so they can be used with other `CacheDatabase` methods + // (for example, for opening/deleting a table). + return dbCacheNames.map(name => name.slice(prefix.length)); } async open(name: string, cacheQueryOptions?: CacheQueryOptions): Promise {