Skip to content

Commit

Permalink
avoid creating multiple service worker instances (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
kommander authored Oct 29, 2020
1 parent 1558480 commit d369412
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/ServiceWorker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ export type ServiceWorkerProps = {
prefix?: string;
};

let client;

export const ServiceWorker = ({ swPath = "/sw.js", prefix = "react-plugin-clerk" }: ServiceWorkerProps) => {
useEffect(() => {
const client = createClient({
swPath,
prefix,
});
client.on("waiting", (updateNow) => updateNow());
client.registerServiceWorker();
if (!client) {
client = createClient({
swPath,
prefix,
});
client.on("waiting", (updateNow) => updateNow());
client.registerServiceWorker();
}
}, []);
return null;
};

0 comments on commit d369412

Please sign in to comment.