Skip to content

Commit

Permalink
🐛 Fix error modal not showing when in non-secure context (#4499)
Browse files Browse the repository at this point in the history
* init when not ssl

* bringing it all back

* huh

* race conditions....

* release notes

* remove unneeded console log
  • Loading branch information
MikesGlitch authored Mar 3, 2025
1 parent b74175e commit 17c4d16
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
36 changes: 29 additions & 7 deletions packages/desktop-client/src/browser-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,28 @@ const importScriptsWithRetry = async (script, { maxRetries = 5 } = {}) => {
}
};

const RECONNECT_INTERVAL_MS = 200;
const MAX_RECONNECT_ATTEMPTS = 500;
let reconnectAttempts = 0;

const postMessageWithRetry = message => {
const reconnectToClientInterval = setInterval(() => {
self.postMessage(message);

reconnectAttempts++;
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
clearInterval(reconnectToClientInterval);
}
}, RECONNECT_INTERVAL_MS);

return reconnectToClientInterval;
};

let appInitFailureInterval;
self.addEventListener('message', async event => {
try {
const msg = event.data;
if (!hasInitialized) {
const msg = event.data;

if (msg.type === 'init') {
hasInitialized = true;
const isDev = !!msg.isDev;
Expand All @@ -51,10 +68,11 @@ self.addEventListener('message', async event => {
!self.SharedArrayBuffer &&
!msg.isSharedArrayBufferOverrideEnabled
) {
self.postMessage({
appInitFailureInterval = postMessageWithRetry({
type: 'app-init-failure',
SharedArrayBufferMissing: true,
});

return;
}

Expand All @@ -65,19 +83,23 @@ self.addEventListener('message', async event => {

backend.initApp(isDev, self).catch(err => {
console.log(err);
const msg = {
appInitFailureInterval = postMessageWithRetry({
type: 'app-init-failure',
IDBFailure: err.message.includes('indexeddb-failure'),
};
self.postMessage(msg);
});

throw err;
});
}
}

if (msg.name === '__app-init-failure-acknowledged') {
// Clear the interval if the client has acknowledged the failure, otherwise keep retrying
clearInterval(appInitFailureInterval);
}
} catch (error) {
console.log('Failed initializing backend:', error);
self.postMessage({
appInitFailureInterval = postMessageWithRetry({
type: 'app-init-failure',
BackendInitFailure: true,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ function AppInner() {
}

initAll().catch(showErrorBoundary);
// Removed cloudFileId from dependencies to prevent hard crash when closing budget in Electron
// Removed cloudFileId & t from dependencies to prevent hard crash when closing budget in Electron
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, showErrorBoundary, t]);
}, [dispatch, showErrorBoundary]);

useEffect(() => {
global.Actual.updateAppMenu(budgetId);
Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/platform/client/fetch/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ function connectWorker(worker, onOpen, onError) {
});
onOpen();
} else if (msg.type === 'app-init-failure') {
globalWorker.postMessage({
name: '__app-init-failure-acknowledged',
});
onError(msg);
} else if (msg.type === 'capture-exception') {
captureException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const init: T.Init = function (serverChn, handlers) {
let reconnectAttempts = 0;

const reconnectToClientInterval = setInterval(() => {
console.info('Backend: Atempting to connect to client');
console.info('Backend: Trying to connect to client');
serverChannel.postMessage({ type: 'connect' });
reconnectAttempts++;
if (reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4499.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MikesGlitch]
---

Fixed error modal not showing when using non-secure context

0 comments on commit 17c4d16

Please sign in to comment.