Skip to content

Commit 69a84ee

Browse files
committed
udpated setTab reducer to correctly handle mode on initial connect (assume true rather than empty object--this should help with 'no target' issue). Commented out port forEach loop in background.js on connect as it causes errors and is not necessary. Thinking of adding a new reducer function that fires on context menu click to update current tab in state.
1 parent 8f6c58b commit 69a84ee

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export default function ComponentMap({
127127
};
128128

129129
const formatRenderTime: string = (time: number): string => {
130+
if (!time) return 'No time information';
130131
const renderTime = time.toFixed(3);
131132
return `${renderTime} ms `;
132133
};

src/app/containers/MainContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function MainContainer(): JSX.Element {
8383
break;
8484
}
8585
case 'changeTab': {
86-
console.log('made it to the mainContainer dispatch');
86+
console.log('MainContainer changeTab payload: ', payload);
8787
dispatch(setTab(payload));
8888
break;
8989
}

src/app/slices/mainSlice.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ export const mainSlice = createSlice({
124124
state.port = action.payload;
125125
},
126126

127+
// JR: REFACTOR: 12.20.23 this code has if statement to catch diff shapes of payload ('number' vs 'object'). This should not be the case, the payload should always come in as expected.
128+
// consider creating a custom typescript type for the action that setTab receives.
129+
130+
//JR: DOCS: 12.20.23 This code will update the currentTab being tracked in the Redux state. It depends, however, on the 'mode', which is an unfortunately named label for the "Locked" button status.
131+
// The naming is unfortunate because the backend also has a mode variable that does a completely different thing, which creates confusion. Consider renaming this to 'locked' or somesuch.
132+
// Mode is an object that expects to contain a single key, paused, with a boolean value.
133+
// If true: Reactime is 'Locked', and navigating to another tab will not update the Redux state and trigger Reactime to take any actions.
134+
// If false: Reactime is 'Unlocked', and navigating to another tab will update the Redux state's currentTab, which will trigger Reactime to try to run on that new tab.
127135
setTab: (state, action) => {
128136
const { tabs, currentTab } = state;
129-
const { mode } = tabs[currentTab] || {};
130-
console.log('mainSlice setTab, mode: ', mode, 'payload: ', action.payload);
137+
const { mode } = tabs[currentTab] || { paused: true };
138+
console.log('mainSlice setTab, mode: ', JSON.stringify(mode), 'payload: ', action.payload);
131139
if (!mode?.paused) {
132140
if (typeof action.payload === 'number') {
133141
state.currentTab = action.payload;
@@ -178,7 +186,7 @@ export const mainSlice = createSlice({
178186
const { tabs, currentTab } = state;
179187
console.log(
180188
'changeView tabs: ',
181-
tabs,
189+
JSON.stringify(tabs),
182190
'currentTab: ',
183191
currentTab,
184192
'tabs[currentTab]: ',
@@ -343,6 +351,7 @@ export const mainSlice = createSlice({
343351
toggleMode: (state, action) => {
344352
const { port, tabs, currentTab } = state;
345353
const { mode } = tabs[currentTab] || {};
354+
console.log('toggleMode current mode destructured from tabs[currentTab]: ', mode);
346355
mode[action.payload] = !mode[action.payload];
347356
const newMode = mode[action.payload];
348357
let actionText;

src/extension/background.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function changeCurrLocation(tabObj, rootNode, index, name) {
140140
This allows us to set up listener's for when we connect, message, and disconnect the script.
141141
*/
142142

143-
// FROM FRONTEND CONNECTION TO BACKGROUND
143+
// INCOMING CONNECTION FROM FRONTEND (MainContainer) TO BACKGROUND.JS
144144
// Establishing incoming connection with Reactime.
145145
chrome.runtime.onConnect.addListener((port) => {
146146
/*
@@ -167,16 +167,17 @@ chrome.runtime.onConnect.addListener((port) => {
167167
console.log('portsArr onConnect: ', portsArr);
168168

169169
// JR: CONSIDER DELETING
170-
if (portsArr.length > 0) {
171-
portsArr.forEach((bg) => {
172-
// go through each port object (each Reactime instance)
173-
bg.postMessage({
174-
// send passed in action object as a message to the current port
175-
action: 'changeTab',
176-
payload: { tabId: activeTab.id, title: activeTab.title },
177-
});
178-
});
179-
}
170+
// 12.20.23 commenting out, possible culprit of many in no target bug
171+
// if (portsArr.length > 0) {
172+
// portsArr.forEach((bg) => {
173+
// // go through each port object (each Reactime instance)
174+
// bg.postMessage({
175+
// // send passed in action object as a message to the current port
176+
// action: 'changeTab',
177+
// payload: { tabId: activeTab.id, title: activeTab.title },
178+
// });
179+
// });
180+
// }
180181

181182
// JR: CONSIDER DELETING
182183
if (Object.keys(tabsObj).length > 0) {
@@ -198,7 +199,7 @@ chrome.runtime.onConnect.addListener((port) => {
198199
}
199200
});
200201

201-
// FROM FRONTEND TO BACKGROUND
202+
// INCOMING MESSAGE FROM FRONTEND (MainContainer) TO BACKGROUND.js
202203
// listen for message containing a snapshot from devtools and send it to contentScript -
203204
// (i.e. they're all related to the button actions on Reactime)
204205
port.onMessage.addListener((msg) => {
@@ -269,7 +270,7 @@ chrome.runtime.onConnect.addListener((port) => {
269270
});
270271
});
271272

272-
// FROM CONTENT SCRIPT TO BACKGROUND
273+
// INCOMING MESSAGE FROM CONTENT SCRIPT TO BACKGROUND.JS
273274
// background.js listening for a message from contentScript.js
274275
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
275276
console.log('background.js received message with action: ', request.action, request);
@@ -471,6 +472,7 @@ chrome.tabs.onActivated.addListener((info) => {
471472
activeTab = tab;
472473
console.log('tabs.onActivated info: ', info);
473474
console.log('activeTab: ', activeTab);
475+
console.log('tabs.onActivated portsArr: ', portsArr);
474476
if (portsArr.length > 0) {
475477
portsArr.forEach((bg) =>
476478
bg.postMessage({
@@ -509,21 +511,20 @@ chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
509511
// // this would allow you to split your screen, keep the browser open on the right side, and reactime always opens at the top left corner.
510512
// // currently, invokedScreenLeft is the left of the invoked window. To get around the issue of reactime covering the refresh button (currently needed for debugging as of 12.19.23), added a vertical offset, topOffset.
511513
// // this just pushes the top down by a fixed amount that is enough to surpass most people's bookmarks bar.
512-
chrome.system.display.getInfo((displayUnitInfo) => {
513-
console.log(displayUnitInfo);
514-
});
514+
// chrome.system.display.getInfo((displayUnitInfo) => {
515+
// console.log(displayUnitInfo);
516+
// });
515517

516518
chrome.windows.getCurrent((window) => {
517-
// const topOffset = 0; // use to push top down to approximately the start of the viewport (for easy access to refresh button)
518519
const invokedScreenHeight = window.height || 1000;
519520
const invokedScreenTop = window.top || 0;
520521
const invokedScreenLeft = -400;
521522
const options = {
522523
type: 'panel',
523524
left: invokedScreenLeft,
524-
top: invokedScreenTop, // + topOffset,
525+
top: invokedScreenTop,
525526
width: 1000,
526-
height: invokedScreenHeight, // - topOffset,
527+
height: invokedScreenHeight,
527528
url: chrome.runtime.getURL('panel.html'),
528529
};
529530
if (menuItemId === 'reactime') chrome.windows.create(options);

src/extension/contentScript.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let firstMessage = true;
1010
// Listens for window messages (from the injected script on the DOM)
1111
let isRecording = true;
1212

13+
// INCOMING MESSAGE FROM BACKEND (index.ts) TO CONTENT SCRIPT
1314
window.addEventListener('message', (msg) => {
1415
// Event listener runs constantly based on actions
1516
// recorded on the test application from backend files (linkFiber.ts).
@@ -38,6 +39,7 @@ window.addEventListener('message', (msg) => {
3839
}
3940
});
4041

42+
// FROM BACKGROUND TO CONTENT SCRIPT
4143
// Listening for messages from the UI of the Reactime extension.
4244
chrome.runtime.onMessage.addListener((request) => {
4345
const { action }: { action: string } = request;
@@ -63,8 +65,15 @@ chrome.runtime.onMessage.addListener((request) => {
6365
// To learn more about Chrome web vitals, see https://web.dev/vitals/.
6466
const metrics = {};
6567
const gatherMetrics = ({ name, value }) => {
68+
console.log(
69+
'contentScript gatherMetrics: prior metrics Obj: ',
70+
metrics,
71+
'name: ',
72+
name,
73+
'value: ',
74+
value,
75+
);
6676
metrics[name] = value;
67-
6877
chrome.runtime.sendMessage({
6978
type: 'performance:metric',
7079
name,

0 commit comments

Comments
 (0)