fix: recover deferred workspace reconnects
This commit is contained in:
1 parent
377fd889c5
commit
0fc152f623
6 files changed
+128
-7
No files matched your search
@@ -7331,6 +7331,9 @@
|
||||
flushAuthored: flushAuthoredOutbox,
|
||||
flushNotificationReads: flushNotificationReadOutbox,
|
||||
});
|
||||
const reconnectAfterOnline = () => setTimeout(reconnectOutboxes, 500);
|
||||
window.addEventListener('online', reconnectAfterOnline);
|
||||
workspaceLifecycle.replayOnline(reconnectAfterOnline);
|
||||
async function setOfflineWorkEnabled(enabled) {
|
||||
keepWorkOffline.checked = enabled;
|
||||
offlineWorkStore.setEnabled(enabled);
|
||||
@@ -7388,9 +7391,6 @@
|
||||
updateDeliveryReceiptControls();
|
||||
if (!navigator.onLine) await showOfflineStatus();
|
||||
window.addEventListener('offline', showOfflineStatus);
|
||||
const reconnectAfterOnline = () => setTimeout(reconnectOutboxes, 500);
|
||||
window.addEventListener('online', reconnectAfterOnline);
|
||||
workspaceLifecycle.replayOnline(reconnectAfterOnline);
|
||||
|
||||
qs('#refresh').addEventListener('click', load);
|
||||
qs('#plan-today').addEventListener('click', event => openPlanToday(event.currentTarget));
|
||||
|
||||
@@ -5,7 +5,10 @@ function createReconnectOutboxes({
|
||||
flushAuthored,
|
||||
flushNotificationReads,
|
||||
}) {
|
||||
return async function reconnectOutboxes() {
|
||||
let activeReconnect = null;
|
||||
let followUpRequested = false;
|
||||
|
||||
async function reconnectOnce() {
|
||||
const snapshot = await refresh();
|
||||
const freshness = snapshot?.freshness?.sections?.context;
|
||||
const identityFresh = snapshot?.context && !snapshot.context.error &&
|
||||
@@ -19,6 +22,22 @@ function createReconnectOutboxes({
|
||||
flushNotificationReads(),
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return function reconnectOutboxes() {
|
||||
if (activeReconnect) {
|
||||
followUpRequested = true;
|
||||
return activeReconnect;
|
||||
}
|
||||
activeReconnect = (async () => {
|
||||
let result = false;
|
||||
do {
|
||||
followUpRequested = false;
|
||||
result = await reconnectOnce();
|
||||
} while (followUpRequested);
|
||||
return result;
|
||||
})().finally(() => { activeReconnect = null; });
|
||||
return activeReconnect;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,14 @@ async function loadWorkspace({ document, window = null, createLoader = createFea
|
||||
};
|
||||
} catch (error) {
|
||||
window?.removeEventListener('online', captureOnline);
|
||||
if (window?.location?.reload) {
|
||||
if (cameOnline) window.location.reload();
|
||||
else window.addEventListener('online', () => window.location.reload(), { once: true });
|
||||
}
|
||||
if (status) {
|
||||
status.textContent =
|
||||
'Workspace could not load. Check your connection, then reload to retry.';
|
||||
status.textContent = window
|
||||
? 'Workspace could not load. Reconnect to retry automatically, or reload now.'
|
||||
: 'Workspace could not load. Check your connection, then reload to retry.';
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user