Skip to content

Commit

Permalink
fix(setupWorker): perform worker update in the background (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Oct 10, 2024
1 parent 452686d commit 8e40724
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/browser/setupWorker/start/utils/getWorkerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ export const getWorkerInstance = async (
const [existingRegistration] = mockRegistrations

if (existingRegistration) {
// When the Service Worker is registered, update it and return the reference.
return existingRegistration.update().then(() => {
return [
getWorkerByRegistration(
existingRegistration,
absoluteWorkerUrl,
findWorker,
),
// Schedule the worker update in the background.
// Update ensures the existing worker is up-to-date.
existingRegistration.update()

// Return the worker reference immediately.
return [
getWorkerByRegistration(
existingRegistration,
]
})
absoluteWorkerUrl,
findWorker,
),
existingRegistration,
]
}

// When the Service Worker wasn't found, register it anew and return the reference.
Expand Down

0 comments on commit 8e40724

Please sign in to comment.