Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pwa): avoid crashing when SW is not available [LIBS-499] #807

Merged
merged 2 commits into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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