Skip to content

Commit

Permalink
fix(pwa): avoid crashing when SW is not available [LIBS-499] (#807)
Browse files Browse the repository at this point in the history
* fix(pwa): avoid crashing when SW is not available

* fix: prevent connection status errors in no-SW conditions
  • Loading branch information
KaiVandivier committed May 3, 2023
1 parent 0adae00 commit b681022
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pwa/src/offline-interface/offline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class OfflineInterface {
}

if (!testSWAvailable()) {
// Make this value available for ServerVersionProvider
this.ready = Promise.resolve()
// Must be connected if we can't use a SW for offline features
this.latestIsConnected = true
return
}

Expand Down Expand Up @@ -220,6 +224,10 @@ export class OfflineInterface {
* @returns {Function} - An unsubscribe function
*/
subscribeToDhis2ConnectionStatus({ onUpdate }) {
if (!testSWAvailable()) {
return () => undefined
}

this.offlineEvents.on(swMsgs.dhis2ConnectionStatusUpdate, onUpdate)
return () =>
this.offlineEvents.off(swMsgs.dhis2ConnectionStatusUpdate, onUpdate)
Expand Down

0 comments on commit b681022

Please sign in to comment.