Skip to content

Commit e3b5a9a

Browse files
committed
synced main
1 parent affbbaa commit e3b5a9a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/App.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ export default function App() {
195195
}, 500)
196196
}
197197

198+
useEffect(() => {
199+
if (window.isSecureContext && navigator.serviceWorker) {
200+
// check for sw updates on page change
201+
navigator.serviceWorker.getRegistrations().then((regs) => regs.forEach((reg) => reg.update()))
202+
if (needRefresh) {
203+
update()
204+
} else if (toast.isActive(updateToastRef.current)) {
205+
toast.dismiss(updateToastRef.current)
206+
}
207+
}
208+
}, [location])
209+
198210
function onUpdate() {
199211
const updateToastBody = (
200212
<UpdateToast
@@ -213,16 +225,6 @@ export default function App() {
213225
}
214226
}
215227

216-
useEffect(() => {
217-
if (needRefresh) {
218-
update()
219-
} else {
220-
if (toast.isActive(updateToastRef.current)) {
221-
toast.dismiss(updateToastRef.current)
222-
}
223-
}
224-
}, [location])
225-
226228
useEffect(() => {
227229
if (needRefresh) {
228230
onUpdate()

0 commit comments

Comments
 (0)