Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix error modal not showing when in non-secure context #4499

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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