1
+ /* eslint-disable no-underscore-dangle */
1
2
/* eslint-disable func-names */
2
3
/* eslint-disable no-use-before-define */
3
4
/* eslint-disable no-param-reassign */
@@ -10,6 +11,7 @@ const { saveState } = require('./masterState');
10
11
module . exports = ( snap , mode ) => {
11
12
let fiberRoot = null ;
12
13
let astHooks ;
14
+ let concurrent = false ; // flag to check if we are in concurrent mode
13
15
14
16
function sendSnapshot ( ) {
15
17
// don't send messages while jumping or while paused
@@ -87,7 +89,6 @@ module.exports = (snap, mode) => {
87
89
function createTree ( currentFiber , tree = new Tree ( 'root' ) ) {
88
90
if ( ! currentFiber ) return tree ;
89
91
90
- // console.log("currentFiber", currentFiber);
91
92
92
93
const {
93
94
sibling,
@@ -128,21 +129,39 @@ module.exports = (snap, mode) => {
128
129
}
129
130
// runs when page initially loads
130
131
// but skips 1st hook click
131
- function updateSnapShotTree ( ) {
132
- const { current } = fiberRoot ;
132
+ async function updateSnapShotTree ( ) {
133
+ let current ;
134
+ // if concurrent mode, grab current.child'
135
+ if ( concurrent ) {
136
+ // we need a way to wait for current child to populate
137
+ const promise = new Promise ( ( resolve , reject ) => {
138
+ setTimeout ( ( ) => resolve ( fiberRoot . current . child ) , 400 ) ;
139
+ } ) ;
140
+
141
+ current = await promise ;
142
+
143
+ current = fiberRoot . current . child ;
144
+ } else {
145
+ current = fiberRoot . current ;
146
+ }
147
+
133
148
snap . tree = createTree ( current ) ;
134
149
}
135
150
136
- return container => {
137
- const {
138
- _reactRootContainer : { _internalRoot } ,
139
- _reactRootContainer,
140
- } = container ;
141
- // only assign internal rootp if it actually exists
142
- fiberRoot = _internalRoot || _reactRootContainer ;
143
-
151
+ return async container => {
152
+ if ( container . _internalRoot ) {
153
+ fiberRoot = container . _internalRoot ;
154
+ concurrent = true ;
155
+ } else {
156
+ const {
157
+ _reactRootContainer : { _internalRoot } ,
158
+ _reactRootContainer,
159
+ } = container ;
160
+ // only assign internal rootp if it actually exists
161
+ fiberRoot = _internalRoot || _reactRootContainer ;
162
+ }
144
163
145
- updateSnapShotTree ( ) ;
164
+ await updateSnapShotTree ( ) ;
146
165
// send the initial snapshot once the content script has started up
147
166
window . addEventListener ( 'message' , ( { data : { action } } ) => {
148
167
if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
0 commit comments