Skip to content

Commit fba42bc

Browse files
committed
Move from unload to pagehide to avoid using deprecated API
1 parent a82db02 commit fba42bc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

client/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class Client {
291291

292292
this.onUnload = this.onUnload.bind(this)
293293
if (typeof window !== 'undefined' && window.addEventListener) {
294-
window.addEventListener('unload', this.onUnload)
294+
window.addEventListener('pagehide', this.onUnload)
295295
}
296296

297297
this.processing = {}
@@ -347,7 +347,7 @@ export class Client {
347347
this.node.destroy()
348348
clearInterval(this.pinging)
349349
if (typeof window !== 'undefined' && window.removeEventListener) {
350-
window.removeEventListener('unload', this.onUnload)
350+
window.removeEventListener('pagehide', this.onUnload)
351351
}
352352
}
353353

client/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ it('cleans own actions on unload', async () => {
383383
{ type: 'A' },
384384
{ reasons: ['tab' + client.tabId], tab: client.tabId }
385385
)
386-
window.dispatchEvent(new Event('unload'))
386+
window.dispatchEvent(new Event('pagehide'))
387387
await delay(10)
388388
expect(client.log.actions()).toHaveLength(0)
389389
expect(localStorage.getItem('test:tab:' + client.tabId)).toBeNull()

cross-tab-client/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class CrossTabClient extends Client {
7070

7171
if (typeof window !== 'undefined' && window.addEventListener) {
7272
window.addEventListener('storage', e => this.onStorage(e))
73-
window.addEventListener('unload', e => this.onUnload(e))
73+
window.addEventListener('pagehide', e => this.onUnload(e))
7474
}
7575

7676
if (this.isLocalStorage) {

0 commit comments

Comments
 (0)