Skip to content

Commit 19b7879

Browse files
committed
working on extension bugs for large websites
1 parent 7b76537 commit 19b7879

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

dev-reactime/linkFiber.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
// const Tree = require('./tree').default;
4848
// const componentActionsRecord = require('./masterState');\
4949

50+
const DEBUG_MODE = false;
51+
52+
const alwaysLog = console.log;
53+
54+
console.log = (original => {
55+
return (...args) => {
56+
if (DEBUG_MODE) original(...args);
57+
}
58+
})(console.log);
59+
5060
import Tree from './tree';
5161
import componentActionsRecord from './masterState';
5262

@@ -57,6 +67,7 @@ export default (snap, mode) => {
5767
let fiberRoot = null;
5868

5969
function sendSnapshot() {
70+
alwaysLog('sendSnapshot called');
6071
// Don't send messages while jumping or while paused
6172
circularComponentTable.clear();
6273
// console.log('sending snapshot');
@@ -105,7 +116,7 @@ export default (snap, mode) => {
105116
//
106117
function createTree(currentFiber, tree = new Tree('root', 'root'), fromSibling = false) {
107118
// Base case: child or sibling pointed to null
108-
// console.log('linkFiber.js: creating tree');
119+
console.log('createTree: creating tree');
109120
if (!currentFiber) return null;
110121
if (!tree) return tree;
111122

@@ -129,10 +140,10 @@ export default (snap, mode) => {
129140
let componentFound = false;
130141

131142
// Check if node is a stateful setState component
132-
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {
143+
if (stateNode && stateNode.state && (tag === 0 || tag === 1)) { // { || tag === 2)) {
133144
// Save component's state and setState() function to our record for future
134145
// time-travel state changing. Add record index to snapshot so we can retrieve.
135-
// console.log('linkFiber.js: found stateNode component');
146+
console.log('createTree() found setState component');
136147
componentData.index = componentActionsRecord.saveNew(stateNode.state, stateNode);
137148
newState = stateNode.state;
138149
componentFound = true;
@@ -142,7 +153,7 @@ export default (snap, mode) => {
142153
let hooksIndex;
143154
if (memoizedState && (tag === 0 || tag === 1 || tag === 10)) {
144155
if (memoizedState.queue) {
145-
// console.log('linkFiber.js: found hooks component');
156+
console.log('createTree() found hooks component');
146157
// Hooks states are stored as a linked list using memoizedState.next,
147158
// so we must traverse through the list and get the states.
148159
// We then store them along with the corresponding memoizedState.queue,
@@ -163,7 +174,7 @@ export default (snap, mode) => {
163174
}
164175

165176
// This grabs stateless components
166-
if (!componentFound && (tag === 0 || tag === 1 || tag === 2)) {
177+
if (!componentFound && (tag === 0 || tag === 1)) { // || tag === 2)) {
167178
newState = 'stateless';
168179
}
169180

@@ -179,15 +190,18 @@ export default (snap, mode) => {
179190
let newNode = null;
180191
if (componentFound || newState === 'stateless') {
181192
if (fromSibling) {
182-
newNode = tree.addSibling(newState,
183-
elementType.name ? elementType.name : elementType,
193+
console.log('createTree(), relevant component found in sibling');
194+
newNode = tree.addSibling(newState,
195+
elementType ? elementType.name : 'nameless',
184196
componentData);
185197
} else {
186-
newNode = tree.addChild(newState,
187-
elementType.name ? elementType.name : elementType,
198+
console.log('createTree(), relevant component found in child');
199+
newNode = tree.addChild(newState,
200+
elementType ? elementType.name : 'nameless',
188201
componentData);
189202
}
190203
} else {
204+
console.log('createTree(), no new relevant nodes, continuing from same node')
191205
newNode = tree;
192206
}
193207

@@ -197,33 +211,34 @@ export default (snap, mode) => {
197211
// If this node had state we appended to the children array,
198212
// so attach children to the newly appended child.
199213
// Otherwise, attach children to this same node.
200-
// console.log('going into child');
214+
console.log('going into child');
201215
// circularComponentTable.set(child, true);
202216
createTree(child, newNode);
203217
}
204218
// Recurse on siblings
205219
if (sibling) { // && !circularComponentTable.has(sibling)) {
206-
// console.log('going into sibling');
220+
console.log('going into sibling');
207221
// circularComponentTable.set(sibling, true);
208222
createTree(sibling, newNode, true);
209223
}
210224

211-
// console.log('linkFiber.js: processed children and sibling, returning tree');
225+
// // console.log('linkFiber.js: processed children and sibling, returning tree');
212226
return tree;
213227
}
214228

215229
function updateSnapShotTree() {
216-
// console.log('linkFiber.js, updateSnapshotTree(), checking if fiberRoot updated');
230+
// console.log('updateSnapshotTree(), checking if fiberRoot updated');
217231
if (fiberRoot) {
218-
// console.log('linkFiber.js, updateSnapshotTree(), updating snapshot', snap.tree);
232+
console.log('updateSnapshotTree(), updating snapshot', snap.tree);
219233
const { current } = fiberRoot;
220234
snap.tree = createTree(current);
221-
// console.log('linkFiber.js, updateSnapshotTree(), completed snapshot', snap.tree);
235+
console.log('updateSnapshotTree(), completed snapshot', snap.tree);
222236
}
223237
}
224238

225239
return async () => {
226240

241+
/*
227242
const container = document.getElementById('root');
228243
if (container._internalRoot) {
229244
fiberRoot = container._internalRoot;
@@ -234,18 +249,21 @@ export default (snap, mode) => {
234249
} = container;
235250
// Only assign internal root if it actually exists
236251
fiberRoot = _internalRoot || _reactRootContainer;
237-
}
252+
}*/
238253

239254
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
240255
const reactInstance = devTools ? devTools.renderers.get(1) : null;
241256

242-
//console.log('fiberRoot retrieved:', fiberRoot);
257+
//// console.log('fiberRoot retrieved:', fiberRoot);
243258
if (reactInstance && reactInstance.version) {
244259
devTools.onCommitFiberRoot = (function (original) {
245260
return function (...args) {
246261
fiberRoot = args[1];
262+
//console.log('Fiber committed, updating snapshot tree with:', fiberRoot);
247263
updateSnapShotTree();
264+
console.log('Fiber committed, sending latest snapshot');
248265
sendSnapshot();
266+
console.log('Fiber committed, latest snapshot sent');
249267
return original(...args);
250268
};
251269
}(devTools.onCommitFiberRoot));

dev-reactime/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Tree {
2323
}
2424

2525
addChild(state, name, componentData) {
26-
// console.log('tree.js: in addChild');
26+
//console.log('tree.js: in addChild');
2727
const newChild = new Tree(state, name, componentData);
2828
newChild.parent = this;
2929
this.children.push(newChild);

0 commit comments

Comments
 (0)