Skip to content

Commit 40e0488

Browse files
committed
added flag to stop work when tab is not focused
1 parent feed54e commit 40e0488

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/backend/linkFiber.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,7 @@ import componentActionsRecord from './masterState';
4343

4444
import { throttle, getHooksNames } from './helpers';
4545

46-
const DEBUG_MODE = false;
47-
48-
const alwaysLog = console.log;
49-
50-
console.log = (original => {
51-
return (...args) => {
52-
if (DEBUG_MODE) original(...args);
53-
}
54-
})(console.log);
55-
56-
46+
let doWork = true;
5747
const circularComponentTable = new Set();
5848

5949
// module.exports = (snap, mode) => {
@@ -149,7 +139,7 @@ export default (snap, mode) => {
149139
// which includes the dispatch() function we use to change their state.
150140
const hooksStates = traverseHooks(memoizedState);
151141
const hooksNames = getHooksNames(elementType.toString());
152-
console.log('hooks names:', hooksNames);
142+
// console.log('hooks names:', hooksNames);
153143
hooksStates.forEach((state, i) => {
154144
hooksIndex = componentActionsRecord.saveNew(state.state, state.component);
155145
if (newState && newState.hooksState) {
@@ -160,7 +150,7 @@ export default (snap, mode) => {
160150
newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
161151
}
162152
componentFound = true;
163-
console.log('currentFiber of hooks state:', currentFiber);
153+
// console.log('currentFiber of hooks state:', currentFiber);
164154
});
165155
}
166156
}
@@ -210,14 +200,14 @@ export default (snap, mode) => {
210200
createTree(sibling, newNode, true);
211201
}
212202

213-
if (circularComponentTable.has(child)) {
203+
/* if (circularComponentTable.has(child)) {
214204
console.log('found circular child, exiting tree loop');
215205
}
216206
217207
if (circularComponentTable.has(sibling)) {
218208
console.log('found circular sibling, exiting tree loop');
219209
}
220-
210+
*/
221211
return tree;
222212
}
223213

@@ -230,6 +220,11 @@ export default (snap, mode) => {
230220
sendSnapshot();
231221
}
232222

223+
function onVisibilityChange() {
224+
doWork = !document.hidden;
225+
console.log('doWork is:', doWork);
226+
}
227+
233228
return async () => {
234229
/* const container = document.getElementById('root');
235230
if (container._internalRoot) {
@@ -248,12 +243,12 @@ export default (snap, mode) => {
248243
fiberRoot = devTools.getFiberRoots(1).values().next().value;
249244
const throttledUpdateSnapshot = throttle(updateSnapShotTree, 250);
250245

251-
console.log('fiberRoot:', fiberRoot);
246+
document.addEventListener('visibilitychange', onVisibilityChange);
252247
if (reactInstance && reactInstance.version) {
253248
devTools.onCommitFiberRoot = (function (original) {
254249
return function (...args) {
255250
fiberRoot = args[1];
256-
throttledUpdateSnapshot();
251+
if (doWork) throttledUpdateSnapshot();
257252
return original(...args);
258253
};
259254
}(devTools.onCommitFiberRoot));

0 commit comments

Comments
 (0)