Fix beforeunload memory leak
This commit is contained in:
parent
0007200b1d
commit
7afa2e6643
@ -277,9 +277,10 @@ export class WebsocketProvider extends Observable {
|
|||||||
broadcastMessage(this, encoding.toUint8Array(encoder))
|
broadcastMessage(this, encoding.toUint8Array(encoder))
|
||||||
}
|
}
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
window.addEventListener('beforeunload', () => {
|
this._beforeUnloadHandler = () => {
|
||||||
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
|
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
|
||||||
})
|
};
|
||||||
|
window.addEventListener('beforeunload', this._beforeUnloadHandler)
|
||||||
}
|
}
|
||||||
awareness.on('update', this._awarenessUpdateHandler)
|
awareness.on('update', this._awarenessUpdateHandler)
|
||||||
this._checkInterval = /** @type {any} */ (setInterval(() => {
|
this._checkInterval = /** @type {any} */ (setInterval(() => {
|
||||||
@ -315,6 +316,9 @@ export class WebsocketProvider extends Observable {
|
|||||||
}
|
}
|
||||||
clearInterval(this._checkInterval)
|
clearInterval(this._checkInterval)
|
||||||
this.disconnect()
|
this.disconnect()
|
||||||
|
if (this._beforeUnloadHandler) {
|
||||||
|
window.removeEventListener('beforeunload', this._beforeUnloadHandler)
|
||||||
|
}
|
||||||
this.awareness.off('update', this._awarenessUpdateHandler)
|
this.awareness.off('update', this._awarenessUpdateHandler)
|
||||||
this.doc.off('update', this._updateHandler)
|
this.doc.off('update', this._updateHandler)
|
||||||
super.destroy()
|
super.destroy()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user