Skip to content

Commit 03de0ee

Browse files
authored
Merge pull request #40 from crperezt/byebyenpm
Grabs fiberRoot from root id of DOM
2 parents 88449f4 + 7b76537 commit 03de0ee

File tree

3 files changed

+31
-41
lines changed

3 files changed

+31
-41
lines changed

dev-reactime/linkFiber.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default (snap, mode) => {
6565

6666
if (!snap.tree) {
6767
// console.log('snapshot empty, sending root');
68-
snap.tree = new Tree('root');
68+
snap.tree = new Tree('root', 'root');
6969
}
7070
const payload = snap.tree.cleanTreeCopy();// snap.tree.getCopy();
7171

@@ -103,7 +103,7 @@ export default (snap, mode) => {
103103

104104
// Carlos: This runs after EVERY Fiber commit. It creates a new snapshot,
105105
//
106-
function createTree(currentFiber, tree = new Tree('root'), fromSibling = false) {
106+
function createTree(currentFiber, tree = new Tree('root', 'root'), fromSibling = false) {
107107
// Base case: child or sibling pointed to null
108108
// console.log('linkFiber.js: creating tree');
109109
if (!currentFiber) return null;
@@ -223,21 +223,23 @@ export default (snap, mode) => {
223223
}
224224

225225
return async () => {
226-
// if (container._internalRoot) {
227-
// fiberRoot = container._internalRoot;
228-
// } else {
229-
// const {
230-
// _reactRootContainer: { _internalRoot },
231-
// _reactRootContainer,
232-
// } = container;
233-
// // Only assign internal root if it actually exists
234-
// fiberRoot = _internalRoot || _reactRootContainer;
235-
// }
226+
227+
const container = document.getElementById('root');
228+
if (container._internalRoot) {
229+
fiberRoot = container._internalRoot;
230+
} else {
231+
const {
232+
_reactRootContainer: { _internalRoot },
233+
_reactRootContainer,
234+
} = container;
235+
// Only assign internal root if it actually exists
236+
fiberRoot = _internalRoot || _reactRootContainer;
237+
}
236238

237239
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
238240
const reactInstance = devTools ? devTools.renderers.get(1) : null;
239-
// console.log('devTools:', devTools);
240241

242+
//console.log('fiberRoot retrieved:', fiberRoot);
241243
if (reactInstance && reactInstance.version) {
242244
devTools.onCommitFiberRoot = (function (original) {
243245
return function (...args) {
@@ -249,13 +251,15 @@ export default (snap, mode) => {
249251
}(devTools.onCommitFiberRoot));
250252
}
251253
updateSnapShotTree();
254+
sendSnapshot();
255+
// updateSnapShotTree();
252256
// Send the initial snapshot once the content script has started up
253257
// This message is sent from contentScript.js in chrome extension bundles
254-
window.addEventListener('message', ({ data: { action } }) => {
255-
if (action === 'contentScriptStarted') {
256-
// console.log('content script started received at linkFiber.js')
257-
sendSnapshot();
258-
}
259-
});
258+
// window.addEventListener('message', ({ data: { action } }) => {
259+
// if (action === 'contentScriptStarted') {
260+
// // console.log('content script started received at linkFiber.js')
261+
// sendSnapshot();
262+
// }
263+
// });
260264
};
261265
};

src/extension/background.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
197197
action === 'tabReload'
198198
|| action === 'recordSnap'
199199
|| action === 'jumpToSnap'
200+
|| action === 'injectScript'
200201
) {
201202
isReactTimeTravel = true;
202203
} else return true;
@@ -215,8 +216,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
215216
break;
216217
}
217218
// this case causes d3 graph to display 1 instead of 0
218-
case 'tabReload': {
219-
219+
case 'injectScript': {
220220
console.log('ran execute script to inject backend');
221221
chrome.tabs.executeScript(tabId, {
222222
code: `
@@ -231,7 +231,9 @@ chrome.runtime.onMessage.addListener((request, sender) => {
231231
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
232232
`,
233233
});
234-
234+
break;
235+
}
236+
case 'tabReload': {
235237
tabsObj[tabId].mode.locked = false;
236238
tabsObj[tabId].mode.paused = false;
237239
// dont remove snapshots if persisting

src/extension/contentScript.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ let firstMessage = true;
99
window.addEventListener('message', msg => { // runs automatically every second
1010
// window listener picks up the message it sends, so we should filter
1111
// messages sent by contentscrip
12-
13-
if (msg.data.action !== 'contentScriptStarted' && firstMessage) {
14-
// since contentScript is run everytime a page is refreshed
12+
if (firstMessage) {
1513
// tell the background script that the tab has reloaded
14+
console.log('event from window, now sending message to extension:', msg);
1615
chrome.runtime.sendMessage({ action: 'tabReload' });
1716
firstMessage = false;
1817
}
@@ -45,19 +44,4 @@ chrome.runtime.onMessage.addListener(request => { // seems to never fire
4544
return true; // attempt to fix port closing console error
4645
});
4746

48-
49-
50-
51-
// // inject script into DOM that grabs window
52-
// function injectScript(file, node) {
53-
// const th = document.getElementsByTagName(node)[0];
54-
// const s = document.createElement('script');
55-
// s.setAttribute('type', 'text/javascript');
56-
// s.setAttribute('src', file);
57-
// th.appendChild(s);
58-
// }
59-
60-
// // console.log('WINDOW in content script:', window);
61-
// reactimeBackend.default(devTools);
62-
63-
//window.postMessage({ action: 'contentScriptStarted' });
47+
chrome.runtime.sendMessage({ action: 'injectScript' });

0 commit comments

Comments
 (0)