Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from Sarabadu/feat/allow-registration-opts
Browse files Browse the repository at this point in the history
feat(loader): allow registration all opts
  • Loading branch information
ShafSpecs authored Aug 12, 2023
2 parents 9f174f5 + 5b4bae5 commit 709bb77
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/react/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ declare global {
}
}

export type LoadServiceWorkerOptions = {
scope?: string;
export type LoadServiceWorkerOptions = RegistrationOptions & {
serviceWorkerUrl?: string;
};


/**
* Load service worker in `entry.client` when the client gets hydrated.
*
* All parameters are optional.
*
* @param {string} LoadServiceWorkerOptions.scope - Scope of the service worker.
* @param {string} LoadServiceWorkerOptions.serviceWorkerUrl - URL of the service worker.
*
* @param options - Options for loading the service worker.
* @param options.serviceWorkerUrl='/entry.worker.js' - URL of the service worker.
* @param ...options.registrationOptions - Options for the service worker registration.
* @returns
* ```ts
* loadServiceWorker({
* scope: "/",
Expand All @@ -30,7 +31,7 @@ export type LoadServiceWorkerOptions = {
* ```
*/
export function loadServiceWorker(
options: LoadServiceWorkerOptions = {
{serviceWorkerUrl, ...options}: LoadServiceWorkerOptions = {
scope: '/',
serviceWorkerUrl: '/entry.worker.js'
}
Expand All @@ -40,9 +41,7 @@ export function loadServiceWorker(
try {
await navigator.serviceWorker
//@ts-ignore
.register(options.serviceWorkerUrl, {
scope: options.scope
})
.register(serviceWorkerUrl, options)
.then(() => navigator.serviceWorker.ready)
.then(() => {
logger.debug('Syncing manifest...');
Expand Down Expand Up @@ -78,4 +77,4 @@ export function loadServiceWorker(
window.addEventListener('load', register);
}
}
}
}

0 comments on commit 709bb77

Please sign in to comment.