Skip to content

Commit

Permalink
Break connection loop
Browse files Browse the repository at this point in the history
Summary:
Whenever there was a connectivity error, we would show an error message and setup a retry mechanism as to refresh the page as to make it transparent for engineers to have a working workspace again.

The problem is that there are two different channels:
- HTTP server
- WS server

If the HTTP server is healthy but there is a WS error, it is not entirely correct to try to reload the page. If the error conditions for the WS remain, then we end up in a loop.

Reviewed By: passy, antonk52

Differential Revision: D49373335

fbshipit-source-id: 4e0a08fe2384860db0bf92a22edc87402d41651c
  • Loading branch information
lblasa authored and facebook-github-bot committed Sep 18, 2023
1 parent 9d6c0bd commit 342ef42
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
7 changes: 6 additions & 1 deletion desktop/flipper-ui-browser/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if (loadingContainer) {
let cachedFile: {name: string; data: string} | undefined;
let cachedDeepLinkURL: string | undefined;

let once: boolean = false;
async function start() {
// @ts-ignore
electronRequire = function (path: string) {
Expand Down Expand Up @@ -75,7 +76,11 @@ async function start() {
window.flipperShowMessage?.('Connecting to server...');
break;
case FlipperServerState.CONNECTED:
window?.flipperHideMessage?.();
if (once) {
return window.location.reload();
}
once = true;
window.flipperHideMessage?.();
break;
case FlipperServerState.DISCONNECTED:
window?.flipperShowNoConnection?.();
Expand Down
20 changes: 1 addition & 19 deletions desktop/static/index.web.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,30 +143,12 @@
window.location.reload();
});

// Check if the server is responding & reload the page if it is.
// This handles the case when the device is online, but the server
// is offline or misbehaving.
async function checkNetworkAndReload() {
try {
const response = await fetch('.');
if (response.status >= 200 && response.status < 500) {
window.location.reload();
return;
}
} catch {
// Unable to connect to the server, ignore.
}
window.setTimeout(checkNetworkAndReload, 2500);
}

function showNoConnection() {
function showNoConnection(reload) {
const root = document.getElementById('root');
root.remove();

const troubleshoot = document.getElementById('troubleshoot');
troubleshoot.style.display = 'flex';

checkNetworkAndReload();
}

const params = new URL(location.href).searchParams;
Expand Down
18 changes: 0 additions & 18 deletions desktop/static/index.web.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,12 @@
window.location.reload();
});

// Check if the server is responding & reload the page if it is.
// This handles the case when the device is online, but the server
// is offline or misbehaving.
async function checkNetworkAndReload() {
try {
const response = await fetch('.');
if (response.status >= 200 && response.status < 500) {
window.location.reload();
return;
}
} catch {
// Unable to connect to the server, ignore.
}
window.setTimeout(checkNetworkAndReload, 2500);
}

function showNoConnection() {
const root = document.getElementById('root');
root.remove();

const troubleshoot = document.getElementById('troubleshoot');
troubleshoot.style.display = 'flex';

checkNetworkAndReload();
}

function showMessage(text) {
Expand Down

0 comments on commit 342ef42

Please sign in to comment.