Skip to content

Commit 5af2af0

Browse files
committed
fixing circular component snapshot errors in timeJump
1 parent 59258f4 commit 5af2af0

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/backend/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getRouteURL(node: SnapshotNode): string {
4040
window.addEventListener('message', ({ data: { action, payload } } : MsgData) => {
4141
switch (action) {
4242
case 'jumpToSnap':
43-
timeJump(payload); // * This sets state with given payload
43+
timeJump(payload, true); // * This sets state with given payload
4444
// Get the pathname from payload and add new entry to browser history
4545
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
4646

src/backend/linkFiber.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
7474
// Carlos: these two are legacy comments, we should look into them later
7575
// prevents useEffect from crashing on load
7676
// if (memoizedState.next.queue === null) { // prevents double pushing snapshot updates
77-
// console.log('traverse hooks memoizedState', memoizedState);
78-
if (memoizedState.memoizedState) {
77+
if (memoizedState.memoizedState && memoizedState.queue.lastRenderedReducer && memoizedState.queue.lastRenderedReducer.name === 'basicStateReducer') {
7978
hooksStates.push({
8079
component: memoizedState.queue,
8180
state: memoizedState.memoizedState,
@@ -109,13 +108,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
109108
} = currentFiber;
110109

111110
let newState: any;
112-
let componentData: ComponentData = {}; /* = {
113-
index: -1,
114-
actualDuration: 0,
115-
actualStartTime: 0,
116-
selfBaseDuration: 0,
117-
treeBaseDuration: 0,
118-
};*/
111+
let componentData: ComponentData = {};
119112
let componentFound = false;
120113

121114
// Check if node is a stateful setState component
@@ -168,7 +161,6 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
168161

169162
let newNode = null;
170163
// We want to add this fiber node to the snapshot
171-
//const snapshotState = newState.state || newState.hooksState;
172164
if (componentFound || newState === 'stateless') {
173165
if (fromSibling) {
174166
newNode = tree.addSibling(newState,
@@ -211,7 +203,6 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
211203

212204
function onVisibilityChange(): void {
213205
doWork = !document.hidden;
214-
console.log('doWork is:', doWork);
215206
}
216207

217208
return () => {

src/backend/timeJump.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import 'core-js';
1515
// const componentActionsRecord = require('./masterState');
1616
import componentActionsRecord from './masterState';
1717

18+
const circularComponentTable = new Set();
19+
1820
// Carlos: origin is latest snapshot, linking to the fiber,
1921
// so changes to origin change app
2022
// module.exports = (origin, mode) => {
2123
export default (origin, mode) => {
2224
// Recursively change state of tree
2325
// Carlos: target is past state we are travelling to
2426

25-
function jump(target) {
27+
function jump(target, firstCall = false) {
2628
// Set the state of the origin tree if the component is stateful
29+
2730
if (!target) return;
2831
if (target.state === 'stateless') target.children.forEach(child => jump(child));
2932
const component = componentActionsRecord.getComponentByIndex(target.componentData.index);
@@ -45,21 +48,26 @@ export default (origin, mode) => {
4548
// const [hooksState] = [target.state.hooksState];
4649
const hooksState = Object.values(target.state.hooksState[0])[0];
4750
if (hooksComponent && hooksComponent.dispatch) {
48-
//hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
49-
console.log('setting hooksState of component id:', target.state.hooksState[1], 'to:', hooksState)
51+
// hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
5052
hooksComponent.dispatch(hooksState);
5153
}
5254
target.children.forEach(child => jump(child));
5355
}
5456

55-
if ((!component || !component.state) && !target.state.hooksState) {
56-
target.children.forEach(child => jump(child));
57-
}
57+
target.children.forEach(child => {
58+
if (!circularComponentTable.has(child)) {
59+
circularComponentTable.add(child);
60+
jump(child);
61+
}
62+
});
63+
64+
// }
5865
}
5966

60-
return target => {
67+
return (target, firstCall = false) => {
6168
// * Setting mode disables setState from posting messages to window
6269
mode.jumping = true;
70+
if (firstCall) circularComponentTable.clear();
6371
jump(target);
6472
setTimeout(() => {
6573
mode.jumping = false;

0 commit comments

Comments
 (0)