Skip to content

Commit 02ef696

Browse files
added support for suspense
1 parent e48557d commit 02ef696

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

package/linkFiber.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,25 @@ module.exports = (snap, mode) => {
7070
let index = 0;
7171
astHooks = Object.values(astHooks);
7272
// while memoizedState is truthy, save the value to the object
73-
while (memoizedState && memoizedState.queue) {
73+
while (memoizedState && memoizedState.queue) { // prevents useEffect from crashing on load
74+
// if (memoizedState.next.queue === null) { // prevents double pushing snapshot updates
7475
changeUseState(memoizedState);
75-
76+
// }
77+
// memoized[astHooks[index]] = memoizedState.memoizedState;
7678
memoized[astHooks[index]] = memoizedState.memoizedState;
7779
// Reassign memoizedState to its next value
7880
memoizedState = memoizedState.next;
79-
index += 2; // Increment the index by 2
81+
// Increment the index by 2
82+
index += 2;
8083
}
8184
return memoized;
8285
}
8386

8487
function createTree(currentFiber, tree = new Tree('root')) {
8588
if (!currentFiber) return tree;
8689

90+
// console.log("currentFiber", currentFiber);
91+
8792
const {
8893
sibling,
8994
stateNode,
@@ -101,10 +106,11 @@ module.exports = (snap, mode) => {
101106
changeSetState(stateNode);
102107
}
103108
// Check if the component uses hooks
104-
if (
105-
memoizedState
106-
&& Object.hasOwnProperty.call(memoizedState, 'baseState')
107-
) {
109+
// console.log("memoizedState", memoizedState);
110+
111+
if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
112+
// 'catch-all' for suspense elements (experimental)
113+
if (typeof elementType.$$typeof === 'symbol') return;
108114
// Traverse through the currentFiber and extract the getters/setters
109115
astHooks = astParser(elementType);
110116
saveState(astHooks);
@@ -135,6 +141,7 @@ module.exports = (snap, mode) => {
135141
// only assign internal rootp if it actually exists
136142
fiberRoot = _internalRoot || _reactRootContainer;
137143

144+
138145
updateSnapShotTree();
139146
// send the initial snapshot once the content script has started up
140147
window.addEventListener('message', ({ data: { action } }) => {

0 commit comments

Comments
 (0)