stackchain-dashboard/frontend/workspace-bootstrap.js
timmy 0fc152f623
Some checks failed
CI / lint (pull_request) Successful in 2m53s
CI / build-release (pull_request) Successful in 6s
CI / browser-journey (pull_request) Failing after 2m45s
CI / release-candidate (pull_request) Has been skipped
fix: recover deferred workspace reconnects
2026-08-17 02:16:48 +00:00

41 lines
1.4 KiB
JavaScript

async function loadWorkspace({ document, window = null, createLoader = createFeatureLoader }) {
let cameOnline = false;
let replayed = false;
const captureOnline = () => { cameOnline = true; };
window?.addEventListener('online', captureOnline);
const status = document.querySelector('#my-work-action-status');
const url = document.querySelector(
'meta[name="stackchain-feature-today-timer"]'
)?.content || '';
const loader = createLoader({
document,
urls: { 'today-timer': url },
});
if (status) status.textContent = 'Starting workspace…';
try {
await loader.load('today-timer');
if (status) status.textContent = '';
return {
replayOnline(callback) {
if (replayed) return;
replayed = true;
window?.removeEventListener('online', captureOnline);
if (cameOnline) callback();
},
};
} 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 = 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;
}
}
if (typeof module !== 'undefined' && module.exports) module.exports = loadWorkspace;