Skip to content

Commit

Permalink
Replace deprecated unload event with pagehide event (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
jul13579 authored May 23, 2024
1 parent 2dd3871 commit 194f43e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/provider/src/HocuspocusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class HocuspocusProvider extends EventEmitter {

boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)

boundPageUnload = this.pageUnload.bind(this)
boundPageHide = this.pageHide.bind(this)

boundOnOpen = this.onOpen.bind(this)

Expand Down Expand Up @@ -299,9 +299,9 @@ export class HocuspocusProvider extends EventEmitter {
this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
}

pageUnload() {
pageHide() {
if (this.awareness) {
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
removeAwarenessStates(this.awareness, [this.document.clientID], 'page hide')
}
}

Expand All @@ -310,7 +310,7 @@ export class HocuspocusProvider extends EventEmitter {
return
}

window.addEventListener('unload', this.boundPageUnload)
window.addEventListener('pagehide', this.boundPageHide)
}

sendStateless(payload: string) {
Expand Down Expand Up @@ -510,7 +510,7 @@ export class HocuspocusProvider extends EventEmitter {
return
}

window.removeEventListener('unload', this.boundPageUnload)
window.removeEventListener('pagehide', this.boundPageHide)
}

permissionDeniedHandler(reason: string) {
Expand Down

0 comments on commit 194f43e

Please sign in to comment.