Skip to content

Commit 3a27057

Browse files
authored
Remove service worker logger (#2265)
* Remove service worker logger * Use async/await for togglePushSubscription * Remove commented out logger calls in service worker * Remove message channel between service worker and app The listener for messages from the service worker was removed in a previous commit. * Remove unused OS detection for service worker
1 parent 06df4b7 commit 3a27057

File tree

12 files changed

+34
-300
lines changed

12 files changed

+34
-300
lines changed

api/slack/index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

api/typeDefs/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default gql`
8686
8787
input SettingsInput {
8888
autoDropBolt11s: Boolean!
89-
diagnostics: Boolean!
89+
diagnostics: Boolean @deprecated
9090
noReferralLinks: Boolean!
9191
fiatCurrency: String!
9292
satsFilter: Int!
@@ -162,7 +162,7 @@ export default gql`
162162
mirrors SettingsInput
163163
"""
164164
autoDropBolt11s: Boolean!
165-
diagnostics: Boolean!
165+
diagnostics: Boolean @deprecated
166166
noReferralLinks: Boolean!
167167
fiatCurrency: String!
168168
satsFilter: Int!

components/error-boundary.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { StaticLayout } from './layout'
33
import styles from '@/styles/error.module.css'
44
import Image from 'react-bootstrap/Image'
55
import copy from 'clipboard-copy'
6-
import { LoggerContext } from './logger'
76
import Button from 'react-bootstrap/Button'
87
import { useToast } from './toast'
98
import { decodeMinifiedStackTrace } from '@/lib/stacktrace'
@@ -36,8 +35,6 @@ class ErrorBoundary extends Component {
3635
// You can use your own error logging service here
3736
console.log({ error, errorInfo })
3837
this.setState({ errorInfo })
39-
const logger = this.context
40-
logger?.error(this.getErrorDetails())
4138
}
4239

4340
render () {
@@ -59,8 +56,6 @@ class ErrorBoundary extends Component {
5956
}
6057
}
6158

62-
ErrorBoundary.contextType = LoggerContext
63-
6459
export default ErrorBoundary
6560

6661
// This button is a functional component so we can use `useToast` hook, which

components/logger.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

components/serviceworker.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react'
22
import { Workbox } from 'workbox-window'
33
import { gql, useMutation } from '@apollo/client'
4-
import { detectOS, useServiceWorkerLogger } from './logger'
54

65
const applicationServerKey = process.env.NEXT_PUBLIC_VAPID_PUBKEY
76

87
const ServiceWorkerContext = createContext()
98

109
// message types for communication between app and service worker
11-
export const MESSAGE_PORT = 'MESSAGE_PORT' // message to exchange message channel on which service worker will send messages back to app
1210
export const ACTION_PORT = 'ACTION_PORT' // message to exchange action channel on which service worker will send actions back to app
1311
export const SYNC_SUBSCRIPTION = 'SYNC_SUBSCRIPTION' // trigger onPushSubscriptionChange event in service worker manually
1412
export const RESUBSCRIBE = 'RESUBSCRIBE' // trigger resubscribing to push notifications (sw -> app)
1513
export const DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION' // delete subscription in IndexedDB (app -> sw)
1614
export const STORE_SUBSCRIPTION = 'STORE_SUBSCRIPTION' // store subscription in IndexedDB (app -> sw)
17-
export const STORE_OS = 'STORE_OS' // store OS in service worker
1815

1916
export const ServiceWorkerProvider = ({ children }) => {
2017
const [registration, setRegistration] = useState(null)
@@ -44,7 +41,6 @@ export const ServiceWorkerProvider = ({ children }) => {
4441
}
4542
}
4643
`)
47-
const logger = useServiceWorkerLogger()
4844

4945
// I am not entirely sure if this is needed since at least in Brave,
5046
// using `registration.pushManager.subscribe` also prompts the user.
@@ -77,7 +73,6 @@ export const ServiceWorkerProvider = ({ children }) => {
7773
// see https://stackoverflow.com/a/69624651
7874
let pushSubscription = await registration.pushManager.subscribe(subscribeOptions)
7975
const { endpoint } = pushSubscription
80-
logger.info('subscribed to push notifications', { endpoint })
8176
// convert keys from ArrayBuffer to string
8277
pushSubscription = JSON.parse(JSON.stringify(pushSubscription))
8378
// Send subscription to service worker to save it so we can use it later during `pushsubscriptionchange`
@@ -86,42 +81,35 @@ export const ServiceWorkerProvider = ({ children }) => {
8681
action: STORE_SUBSCRIPTION,
8782
subscription: pushSubscription
8883
})
89-
logger.info('sent STORE_SUBSCRIPTION to service worker', { endpoint })
9084
// send subscription to server
9185
const variables = {
9286
endpoint,
9387
p256dh: pushSubscription.keys.p256dh,
9488
auth: pushSubscription.keys.auth
9589
}
9690
await savePushSubscription({ variables })
97-
logger.info('sent push subscription to server', { endpoint })
9891
}
9992

10093
const unsubscribeFromPushNotifications = async (subscription) => {
10194
await subscription.unsubscribe()
10295
const { endpoint } = subscription
103-
logger.info('unsubscribed from push notifications', { endpoint })
10496
await deletePushSubscription({ variables: { endpoint } })
10597
// also delete push subscription in IndexedDB so we can tell if the user disabled push subscriptions
10698
// or we lost the push subscription due to a bug
10799
navigator.serviceWorker.controller.postMessage({ action: DELETE_SUBSCRIPTION })
108-
logger.info('deleted push subscription from server', { endpoint })
109100
}
110101

111102
const togglePushSubscription = useCallback(async () => {
112103
const pushSubscription = await registration.pushManager.getSubscription()
113104
if (pushSubscription) {
114-
return unsubscribeFromPushNotifications(pushSubscription)
105+
return await unsubscribeFromPushNotifications(pushSubscription)
106+
}
107+
await subscribeToPushNotifications()
108+
// request persistent storage: https://web.dev/learn/pwa/offline-data#data_persistence
109+
const persisted = await navigator?.storage?.persisted?.()
110+
if (!persisted && navigator?.storage?.persist) {
111+
return await navigator.storage.persist()
115112
}
116-
return subscribeToPushNotifications().then(async () => {
117-
// request persistent storage: https://web.dev/learn/pwa/offline-data#data_persistence
118-
const persisted = await navigator?.storage?.persisted?.()
119-
if (!persisted && navigator?.storage?.persist) {
120-
return navigator.storage.persist().then(persistent => {
121-
logger.info('persistent storage:', persistent)
122-
}).catch(logger.error)
123-
}
124-
})
125113
})
126114

127115
useEffect(() => {
@@ -133,13 +121,11 @@ export const ServiceWorkerProvider = ({ children }) => {
133121
setPermission({ notification: 'Notification' in window ? window.Notification.permission : 'denied' })
134122

135123
if (!('serviceWorker' in navigator)) {
136-
logger.info('device does not support service worker')
137124
return
138125
}
139126

140127
const wb = new Workbox('/sw.js', { scope: '/' })
141128
wb.register().then(registration => {
142-
logger.info('service worker registration successful')
143129
setRegistration(registration)
144130
})
145131
}, [])
@@ -158,10 +144,7 @@ export const ServiceWorkerProvider = ({ children }) => {
158144
// since (a lot of) browsers don't support the pushsubscriptionchange event,
159145
// we sync with server manually by checking on every page reload if the push subscription changed.
160146
// see https://medium.com/@madridserginho/how-to-handle-webpush-api-pushsubscriptionchange-event-in-modern-browsers-6e47840d756f
161-
navigator?.serviceWorker?.controller?.postMessage?.({ action: STORE_OS, os: detectOS() })
162-
logger.info('sent STORE_OS to service worker: ', detectOS())
163147
navigator?.serviceWorker?.controller?.postMessage?.({ action: SYNC_SUBSCRIPTION })
164-
logger.info('sent SYNC_SUBSCRIPTION to service worker')
165148
}, [registration, permission.notification])
166149

167150
const contextValue = useMemo(() => ({

fragments/users.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ ${STREAK_FIELDS}
2323
photoId
2424
privates {
2525
autoDropBolt11s
26-
diagnostics
2726
noReferralLinks
2827
fiatCurrency
2928
autoWithdrawMaxFeePercent
@@ -97,7 +96,6 @@ export const SETTINGS_FIELDS = gql`
9796
imgproxyOnly
9897
showImagesAndVideos
9998
hideWalletBalance
100-
diagnostics
10199
noReferralLinks
102100
nostrPubkey
103101
nostrCrossposting

lib/validate.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ export const settingsSchema = object().shape({
472472
hideNostr: boolean(),
473473
hideTwitter: boolean(),
474474
hideWalletBalance: boolean(),
475-
diagnostics: boolean(),
476475
noReferralLinks: boolean(),
477476
hideIsContributor: boolean(),
478477
disableFreebies: boolean().nullable(),

pages/_app.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { ServiceWorkerProvider } from '@/components/serviceworker'
1616
import { SSR } from '@/lib/constants'
1717
import NProgress from 'nprogress'
1818
import 'nprogress/nprogress.css'
19-
import { LoggerProvider } from '@/components/logger'
2019
import { ChainFeeProvider } from '@/components/chain-fee.js'
2120
import dynamic from 'next/dynamic'
2221
import { HasNewNotesProvider } from '@/components/use-has-new-notes'
@@ -114,28 +113,26 @@ export default function MyApp ({ Component, pageProps: { ...props } }) {
114113
<MeProvider me={me}>
115114
<WalletsProvider>
116115
<HasNewNotesProvider>
117-
<LoggerProvider>
118-
<WebLnProvider>
119-
<ServiceWorkerProvider>
120-
<PriceProvider price={price}>
121-
<FireworksProvider>
122-
<ToastProvider>
123-
<ShowModalProvider>
124-
<BlockHeightProvider blockHeight={blockHeight}>
125-
<ChainFeeProvider chainFee={chainFee}>
126-
<ErrorBoundary>
127-
<Component ssrData={ssrData} {...otherProps} />
128-
{!router?.query?.disablePrompt && <PWAPrompt copyBody='This website has app functionality. Add it to your home screen to use it in fullscreen and receive notifications. In Safari:' promptOnVisit={2} />}
129-
</ErrorBoundary>
130-
</ChainFeeProvider>
131-
</BlockHeightProvider>
132-
</ShowModalProvider>
133-
</ToastProvider>
134-
</FireworksProvider>
135-
</PriceProvider>
136-
</ServiceWorkerProvider>
137-
</WebLnProvider>
138-
</LoggerProvider>
116+
<WebLnProvider>
117+
<ServiceWorkerProvider>
118+
<PriceProvider price={price}>
119+
<FireworksProvider>
120+
<ToastProvider>
121+
<ShowModalProvider>
122+
<BlockHeightProvider blockHeight={blockHeight}>
123+
<ChainFeeProvider chainFee={chainFee}>
124+
<ErrorBoundary>
125+
<Component ssrData={ssrData} {...otherProps} />
126+
{!router?.query?.disablePrompt && <PWAPrompt copyBody='This website has app functionality. Add it to your home screen to use it in fullscreen and receive notifications. In Safari:' promptOnVisit={2} />}
127+
</ErrorBoundary>
128+
</ChainFeeProvider>
129+
</BlockHeightProvider>
130+
</ShowModalProvider>
131+
</ToastProvider>
132+
</FireworksProvider>
133+
</PriceProvider>
134+
</ServiceWorkerProvider>
135+
</WebLnProvider>
139136
</HasNewNotesProvider>
140137
</WalletsProvider>
141138
</MeProvider>

0 commit comments

Comments
 (0)