Skip to content

Commit

Permalink
fix: remove awareness states on page unload instead of beforeunload (#…
Browse files Browse the repository at this point in the history
…658)

Co-authored-by: 范文华 <fanwh@yealink.com>
  • Loading branch information
iowxy and 范文华 authored Jul 29, 2023
1 parent db2bba3 commit e1bd3f1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/provider/src/HocuspocusProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class HocuspocusProvider extends EventEmitter {

boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)

boundBeforeUnload = this.beforeUnload.bind(this)
boundPageUnload = this.pageUnload.bind(this)

boundOnOpen = this.onOpen.bind(this)

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

beforeUnload() {
pageUnload() {
removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
}

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

window.addEventListener('beforeunload', this.boundBeforeUnload)
window.addEventListener('unload', this.boundPageUnload)
}

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

window.removeEventListener('beforeunload', this.boundBeforeUnload)
window.removeEventListener('unload', this.boundPageUnload)
}

permissionDeniedHandler(reason: string) {
Expand Down

0 comments on commit e1bd3f1

Please sign in to comment.