diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index d09045e0662a6..6814053df9ed3 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -543,10 +543,10 @@ export class Driver implements Debuggable, UpdateSource { * Decide which version of the manifest to use for the event. */ private async assignVersion(event: FetchEvent): Promise { - // First, check whether the event has a client ID. If it does, the version may + // First, check whether the event has a (non empty) client ID. If it does, the version may // already be associated. const clientId = event.clientId; - if (clientId !== null) { + if (clientId) { // Check if there is an assigned client id. if (this.clientVersionMap.has(clientId)) { // There is an assignment for this client already. diff --git a/packages/service-worker/worker/test/happy_spec.ts b/packages/service-worker/worker/test/happy_spec.ts index 75275e91a0570..e444ca1502461 100644 --- a/packages/service-worker/worker/test/happy_spec.ts +++ b/packages/service-worker/worker/test/happy_spec.ts @@ -320,6 +320,27 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate)); expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo v2'); }); + async_it('handles empty client ID', async() => { + const navRequest = (url: string, clientId: string | null) => + makeRequest(scope, url, clientId, { + headers: {Accept: 'text/plain, text/html, text/css'}, + mode: 'navigate', + }); + + // Initialize the SW. + expect(await navRequest('/foo/file1', '')).toEqual('this is foo'); + expect(await navRequest('/bar/file2', null)).toEqual('this is foo'); + await driver.initialized; + + // Update to a new version. + scope.updateServerState(serverUpdate); + expect(await driver.checkForUpdate()).toEqual(true); + + // Correctly handle navigation requests, even if `clientId` is null/empty. + expect(await navRequest('/foo/file1', '')).toEqual('this is foo v2'); + expect(await navRequest('/bar/file2', null)).toEqual('this is foo v2'); + }); + async_it('checks for updates on restart', async() => { expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo'); await driver.initialized;