Skip to content

Commit 7af1477

Browse files
load time optimizations and connection stabilizer implemented
1 parent 1428378 commit 7af1477

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

src/app/components/Loader.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ This file is what decides what icon (loading, checkmark, exclamation point) is d
1515

1616
const handleResult = (result: boolean): JSX.Element =>
1717
result ? (
18-
<CheckCircleOutlineIcon className='check'/>
19-
// if result boolean is true, we display a checkmark icon
18+
<CheckCircleOutlineIcon className='check'/> // if result boolean is true, we display a checkmark icon
2019
) : (
21-
<ErrorOutlineIcon className='fail'/>
22-
// if the result boolean is false, we display a fail icon
20+
<ErrorOutlineIcon className='fail'/> // if the result boolean is false, we display a fail icon
2321
);
2422

2523
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types

src/app/containers/ErrorContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ function ErrorContainer(): JSX.Element {
6161

6262
if (!status.contentScriptLaunched) { // if content script hasnt been launched/found, set a timer or immediately update 'loadingArray' state
6363

64-
if (loadingArray[0] === true) { // if loadingArray[0] is true, then that means our timeout.current is still null so we now set it to a setTimeout function that will flip loadingArray[0] to false after 1.5 seconds
64+
if (loadingArray[0] === true) { // if loadingArray[0] is true, then that means our timeout.current is still null so we now set it to a setTimeout function that will flip loadingArray[0] to false after 3 seconds
6565
timeout.current = setTimeout(() => {
6666
setLoadingArray(0, false);
67-
}, 1500);
67+
}, 3000); // increased from 1500
6868
}
6969
} else {
7070
setLoadingArray(0, false) // if status.contentScriptLaunched is true, that means timeout.current !== null. This means that useEffect was triggered previously.

src/app/containers/MainContainer.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ function MainContainer(): JSX.Element {
4545
}
4646
};
4747

48-
// let port;
4948
useEffect(() => {
5049
if (port) return; // only open port once so if it exists, do not run useEffect again
5150

5251
// chrome.runtime allows our application to retrieve our service worker (our eventual bundles/background.bundle.js after running npm run build), details about the manifest, and allows us to listen and respond to events in our application lifecycle.
5352
const currentPort = chrome.runtime.connect(); // we connect to our service worker
5453

54+
setInterval(() => { // interval to keep connection to background.js alive
55+
currentPort.postMessage({
56+
action: 'keepAlive' // messages sent to port to keep connection alive
57+
})
58+
}, 295000) // messages must happen within five minutes
59+
5560
// listen for a message containing snapshots from the /extension/build/background.js service worker
5661
currentPort.onMessage.addListener(
5762
// parameter message is an object with following type script properties
@@ -63,7 +68,7 @@ function MainContainer(): JSX.Element {
6368
const { action, payload, sourceTab } = message;
6469
let maxTab: number;
6570

66-
if (!sourceTab) { // if the sourceTab doesn't exist or is 0
71+
if (!sourceTab && action !== 'keepAlive') { // if the sourceTab doesn't exist or is 0 and it is not a 'keepAlive' action
6772
const tabsArray: Array<string> = Object.keys(payload); // we create a tabsArray of strings composed of keys from our payload object
6873
const numTabsArray: number[] = tabsArray.map((tab) => Number(tab)); // we then map out our tabsArray where we convert each string into a number
6974

src/backend/routers/linkFiber.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export default function linkFiber(mode: Status): () => Promise<void> {
7070
// -------------------CHECK REACT DEVTOOL INSTALLATION----------------------
7171
// react devtools global hook is a global object that was injected by the React Devtools content script, allows access to fiber nodes and react version
7272
// Obtain React Devtools Object:
73-
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
73+
let devTools; // changed to a different version of getting hook (08/04/2023)
74+
while (!devTools) {
75+
devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
76+
}
7477
// If React Devtools is not installed, object will be undefined.
7578
if (!devTools) return;
7679
// If React Devtools is installed, send a message to front end.

src/extension/background.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,17 @@ chrome.runtime.onConnect.addListener((port) => {
163163

164164
// On Reactime launch: make sure RT's active tab is correct
165165
if (portsArr.length > 0) {
166-
portsArr.forEach((bg) => // go through each port object (each Reactime instance)
166+
portsArr.forEach((bg) => {// go through each port object (each Reactime instance)
167167
bg.postMessage({ // send passed in action object as a message to the current port
168168
action: 'changeTab',
169169
payload: { tabId: activeTab.id, title: activeTab.title },
170-
}),
171-
);
170+
})
171+
setInterval(() => { // interval used to keep connection to MainContainer alive
172+
bg.postMessage({
173+
action: 'keepAlive' // messages sent to port to keep connection alive
174+
})
175+
}, 295000) // messages must happen within five minutes
176+
});
172177
}
173178

174179
// send tabs obj to the connected devtools as soon as connection to devtools is made
@@ -283,7 +288,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
283288
return true;
284289
}
285290
// everytime we get a new tabId, add it to the object
286-
if (isReactTimeTravel && !(tabId in tabsObj)) {
291+
while (isReactTimeTravel && !(tabId in tabsObj)) { // changed if to while 8/4/2023
287292
tabsObj[tabId] = createTabObj(tabTitle);
288293
}
289294

src/extension/contentScript.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ window.addEventListener('message', (msg) => {
1919
// One-time request tells the background script that the tab has reloaded.
2020
chrome.runtime.sendMessage({ action: 'tabReload' });
2121
firstMessage = false;
22+
setInterval(() => { // interval to keep connection to service worker connection alive
23+
chrome.runtime.sendMessage({
24+
action: 'keepAlive' // messages sent to port to keep connection alive
25+
})
26+
}, 295000) // messages must happen within five minutes
2227
}
2328

2429
// After tabs object has been created from firstMessage, backend (linkFiber.ts)

0 commit comments

Comments
 (0)