Skip to content

Commit

Permalink
Fix loading service worker (#4588)
Browse files Browse the repository at this point in the history
* Fix loading service worker

* Fix loading service worker
  • Loading branch information
andrzejewsky committed Jan 12, 2024
1 parent 1637e12 commit 3018ed8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-ghosts-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix loading service worker
4 changes: 3 additions & 1 deletion src/hooks/useServiceWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { register } from "register-service-worker";

const SW_PATH = `${process.env.STATIC_URL || "/"}sw.js`;

export const useServiceWorker = (timeout: number) => {
const [updateAvailable, setUpdateAvailable] = useState<boolean>(false);
const registrationRef = useRef<ServiceWorkerRegistration>();
Expand Down Expand Up @@ -29,7 +31,7 @@ export const useServiceWorker = (timeout: number) => {
}, [updateAvailable]);

useEffect(() => {
register("/sw.js", {
register(SW_PATH, {
registered: onRegistered,
updated: onUpdate,
});
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default defineConfig(({ command, mode }) => {
DEMO_MODE,
CUSTOM_VERSION,
SENTRY_RELEASE,
STATIC_URL
},
},
build: {
Expand Down

0 comments on commit 3018ed8

Please sign in to comment.