Skip to content

Commit 888872e

Browse files
authored
Merge pull request #1 from oslabs-beta/peng
fixing bug and adding some comment
2 parents 39a03b7 + 73412e9 commit 888872e

File tree

9 files changed

+8821
-9050
lines changed

9 files changed

+8821
-9050
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
"react-split": "^2.0.14",
193193
"recoil": "0.0.10",
194194
"util": "^0.12.4",
195-
"web-vitals": "^1.1.0"
195+
"web-vitals": "^1.1.0",
196+
"yarn": "^1.22.19"
196197
}
197-
}
198+
}

src/app/components/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import MainContainer from '../containers/MainContainer';
1111
import { StoreContext } from '../store';
1212
import mainReducer from '../reducers/mainReducer.js';
1313

14-
1514
// import 'intro.js/introjs.css';
1615

1716
// currentTab is the current active tab within Google Chrome. This is used to decide what tab Reactime should be monitoring. This can be "locked"

src/app/containers/MainContainer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { useStoreContext } from '../store';
2222
function MainContainer(): any {
2323
const [store, dispatch] = useStoreContext();
2424
const {
25-
tabs, currentTab, port: currentPort, split,
25+
tabs, currentTab, port, split,
2626
} = store;
2727
const [actionView, setActionView] = useState(true);
2828
// this function handles Time Jump sidebar view
@@ -41,12 +41,12 @@ function MainContainer(): any {
4141
// let port;
4242
useEffect(() => {
4343
// only open port once
44-
if (currentPort) return;
44+
if (port) return;
4545

4646
// open long-lived connection with background script
47-
const port = chrome.runtime.connect();
47+
const currentPort = chrome.runtime.connect();
4848
// listen for a message containing snapshots from the background script
49-
port.onMessage.addListener(
49+
currentPort.onMessage.addListener(
5050
(message: {
5151
action: string;
5252
payload: Record<string, unknown>;
@@ -91,13 +91,13 @@ function MainContainer(): any {
9191
},
9292
);
9393

94-
port.onDisconnect.addListener(() => {
94+
currentPort.onDisconnect.addListener(() => {
9595
console.log('this port is disconeccting line 79');
9696
// disconnecting
9797
});
9898

9999
// assign port to state so it could be used by other components
100-
dispatch(setPort(port));
100+
dispatch(setPort(currentPort));
101101
});
102102

103103
// Error Page launch IF(Content script not launched OR RDT not installed OR Target not React app)

src/backend/index.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,37 @@ window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
4343
mode.paused = payload;
4444
break;
4545
// maybe this isn't work react cohort 45
46-
case 'onHover':
47-
if (Array.isArray(payload)) {
48-
for (let i = 0; i < payload.length; i + 1) {
49-
const element = document.getElementById(payload[i]);
50-
if (element !== null) {
51-
element.style.backgroundColor = '#C0D9D9';
52-
}
53-
}
54-
} else {
55-
const element: HTMLElement = document.querySelector(`.${payload}`);
56-
if (element !== null) {
57-
element.style.backgroundColor = '#C0D9D9';
58-
}
59-
}
60-
break;
61-
// maybe this isn't work react cohort 45
62-
case 'onHoverExit':
63-
if (Array.isArray(payload)) {
64-
for (let i = 0; i < payload.length; i++) {
65-
const element: HTMLElement = document.querySelector(`.${payload}`);
66-
if (element !== null) {
67-
element.style.backgroundColor = '';
68-
}
69-
}
70-
} else {
71-
const element: HTMLElement = document.querySelector(`.${payload}`);
72-
if (element !== null) {
73-
element.style.backgroundColor = '';
74-
}
75-
}
76-
break;
46+
// case 'onHover':
47+
// if (Array.isArray(payload)) {
48+
// for (let i = 0; i < payload.length; i + 1) {
49+
// const element = document.getElementById(payload[i]);
50+
// if (element !== null) {
51+
// element.style.backgroundColor = '#C0D9D9';
52+
// }
53+
// }
54+
// } else {
55+
// const element: HTMLElement = document.querySelector(`.${payload}`);
56+
// if (element !== null) {
57+
// element.style.backgroundColor = '#C0D9D9';
58+
// }
59+
// }
60+
// break;
61+
// // maybe this isn't work react cohort 45
62+
// case 'onHoverExit':
63+
// if (Array.isArray(payload)) {
64+
// for (let i = 0; i < payload.length; i++) {
65+
// const element: HTMLElement = document.querySelector(`.${payload}`);
66+
// if (element !== null) {
67+
// element.style.backgroundColor = '';
68+
// }
69+
// }
70+
// } else {
71+
// const element: HTMLElement = document.querySelector(`.${payload}`);
72+
// if (element !== null) {
73+
// element.style.backgroundColor = '';
74+
// }
75+
// }
76+
// break;
7777
default:
7878
break;
7979
}

src/backend/linkFiber.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,38 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
571571
document.addEventListener('visibilitychange', onVisibilityChange);
572572

573573
if (reactInstance && reactInstance.version) {
574+
console.log(devTools);
575+
console.log(devTools.onCommitFiberRoot);
574576
fiberRoot = devTools.getFiberRoots(1).values().next().value;
575-
devTools.onCommitFiberRoot = (function (original) {
577+
// original is a function
578+
// devTools.onCommitFiberRoot = (function (original) {
579+
// return function (...args) {
580+
// // eslint-disable-next-line prefer-destructuring
581+
// fiberRoot = args[1];
582+
// if (doWork) {
583+
// throttledUpdateSnapshot();
584+
// }
585+
// return original(...args);
586+
// };
587+
// }(devTools.onCommitFiberRoot));
588+
589+
// React has inherent methods that are called with react fiber
590+
// we attach new functionality without compromising the original work that onCommitFiberRoot does
591+
const addOneMoreStep = function (original) {
576592
return function (...args) {
593+
console.log(args);
577594
// eslint-disable-next-line prefer-destructuring
578595
fiberRoot = args[1];
596+
// this is the additional functionality we added
579597
if (doWork) {
580598
throttledUpdateSnapshot();
581599
}
600+
// after our added work is completed we invoke the original function
582601
return original(...args);
583602
};
584-
}(devTools.onCommitFiberRoot));
603+
};
604+
devTools.onCommitFiberRoot = addOneMoreStep(devTools.onCommitFiberRoot);
605+
585606
throttledUpdateSnapshot(); // only runs on start up
586607
}
587608
};

src/extension/background.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ let activeTab;
1212
const tabsObj = {};
1313
// Will store Chrome web vital metrics and their corresponding values.
1414
const metrics = {};
15-
1615
// This function will create the first instance of the test app's tabs object
1716
// which will hold test app's snapshots, link fiber tree info, chrome tab info, etc.
1817
function createTabObj(title) {
@@ -122,12 +121,13 @@ function changeCurrLocation(tabObj, rootNode, index, name) {
122121
}
123122
}
124123

125-
// Establishing incoming connection with devtools.
124+
// Establishing incoming connection with Reactime.
126125
chrome.runtime.onConnect.addListener(port => {
127126
// port is one end of the connection - an object
128127
// push every port connected to the ports array
129128
portsArr.push(port);
130-
129+
console.log(port, '<--port');
130+
console.log(portsArr, '<--portsArr');
131131
// On Reactime launch: make sure RT's active tab is correct
132132
if (portsArr.length > 0) {
133133
portsArr.forEach(bg => bg.postMessage({
@@ -222,7 +222,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
222222
if (request.type === 'SIGN_CONNECT') {
223223
return true;
224224
}
225-
225+
console.log(sender, '<-- sender');
226226
const tabTitle = sender.tab.title;
227227
const tabId = sender.tab.id;
228228
const {
@@ -286,7 +286,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
286286
script.setAttribute('type', 'text/javascript');
287287
script.setAttribute('src', file);
288288
// eslint-disable-next-line prefer-template
289-
document.title = tab + '-' + document.title;
289+
// document.title = tab + '-' + document.title; // error of injecting random number
290290
htmlBody.appendChild(script);
291291
};
292292

src/extension/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Reactime",
3-
"version": "14.0.0",
3+
"version": "15.0.0",
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension that helps debug React applications by memorizing the state of components with every render.",
66
"manifest_version": 3,

src/extension/contentScript.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ window.addEventListener('message', msg => {
2727
// will send snapshots of the test app's link fiber tree.
2828
const { action }: { action: string } = msg.data;
2929
if (action === 'recordSnap') {
30-
if (!isRecording) return;
31-
chrome.runtime.sendMessage(msg.data);
30+
if (isRecording) {
31+
chrome.runtime.sendMessage(msg.data);
32+
}
3233
}
3334
if (action === 'devToolsInstalled') {
3435
chrome.runtime.sendMessage(msg.data);

0 commit comments

Comments
 (0)