App: [$250] [Bug] ActiveClientManager doesn't track the currently active tab well and needs improved

Problem

The purpose of ActiveClientManager is to ensure that when there are multiple tabs open, only one tab handles write requests. There are a few bugs with this.

In order to test this, I used the following diff and then ran ActiveClientManager.isClientTheLeader() from the command line.

diff --git a/src/setup/addUtilsToWindow.ts b/src/setup/addUtilsToWindow.ts
index d2d11e1384..30419a5eb5 100644
--- a/src/setup/addUtilsToWindow.ts
+++ b/src/setup/addUtilsToWindow.ts
@@ -1,6 +1,7 @@
 import Onyx from 'react-native-onyx';
 import * as Environment from '@libs/Environment/Environment';
 import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead';
+import * as ActiveClientManager from '@libs/ActiveClientManager';
 import * as Session from '@userActions/Session';

 /**
@@ -49,5 +50,7 @@ export default function addUtilsToWindow() {
         // Workaround to give employees the ability to mark reports as read via the JS console
         // eslint-disable-next-line @typescript-eslint/no-explicit-any
         (window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead;
+
+        window.ActiveClientManager = ActiveClientManager;
     });
 }

Bug 1: Multiple tabs becoming active

  1. Open a single tab (TabA)
  2. Verify isClientTheLeader() === true
  3. Open a second tab (TabB) in the same window
  4. Verify isClientTheLeader() === true
  5. Go back to TabA

Expected result: isClientTheLeader() === false because TabB took over as the new leader

Actual result: isClientTheLeader() === true and both tabs think they are the leader

Bug 2: If active tab is closed, there are no active tabs

[!NOTE] I was unable to reproduce this because of Bug1. However, once Bug1 is fixed, I think this bug would happen.

  1. Have TabA open and be the active client
  2. Have TabB open and be a non-active client
  3. Close TabA

Expected result: Tab B takes over and becomes the new active client

Actual result: Tab B remains as an inactive client

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~012e35885da3cd69cf
  • Upwork Job ID: 1778173291530903552
  • Last Price Increase: 2024-04-17

About this issue

  • Original URL
  • State: open
  • Created 3 months ago
  • Comments: 29 (14 by maintainers)

Most upvoted comments

@isabelastisser I’m preparing a PR, the code is ready

Taking over as C+

@Santhosh-Sellavel Will you be able to look at these proposals today?