Skip to content

Commit a988237

Browse files
authored
Improve logout from worker (#30775)
A quick fix for #30756
1 parent 564102c commit a988237

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

web_src/js/features/notification.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import $ from 'jquery';
22
import {GET} from '../modules/fetch.js';
33
import {toggleElem} from '../utils/dom.js';
4+
import {logoutFromWorker} from '../modules/worker.js';
45

56
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
67
let notificationSequenceNumber = 0;
@@ -95,7 +96,7 @@ export function initNotificationCount() {
9596
type: 'close',
9697
});
9798
worker.port.close();
98-
window.location.href = `${appSubUrl}/`;
99+
logoutFromWorker();
99100
} else if (event.data.type === 'close') {
100101
worker.port.postMessage({
101102
type: 'close',

web_src/js/features/stopwatch.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {createTippy} from '../modules/tippy.js';
22
import {GET} from '../modules/fetch.js';
33
import {hideElem, showElem} from '../utils/dom.js';
4+
import {logoutFromWorker} from '../modules/worker.js';
45

56
const {appSubUrl, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config;
67

@@ -77,7 +78,7 @@ export function initStopwatch() {
7778
type: 'close',
7879
});
7980
worker.port.close();
80-
window.location.href = `${appSubUrl}/`;
81+
logoutFromWorker();
8182
} else if (event.data.type === 'close') {
8283
worker.port.postMessage({
8384
type: 'close',

web_src/js/modules/worker.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {sleep} from '../utils.js';
2+
3+
const {appSubUrl} = window.config;
4+
5+
export async function logoutFromWorker() {
6+
// wait for a while because other requests (eg: logout) may be in the flight
7+
await sleep(5000);
8+
window.location.href = `${appSubUrl}/`;
9+
}

0 commit comments

Comments
 (0)