How to use emptyFindFiberByHostInstance method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ReactFiberReconciler.old.js

Source: ReactFiberReconciler.old.js Github

copy
1  var didWarnAboutNestedUpdates;
2  var didWarnAboutFindNodeInStrictMode;
3
4  {
5    didWarnAboutNestedUpdates = false;
6    didWarnAboutFindNodeInStrictMode = {};
7  }
8
9  function getContextForSubtree(parentComponent) {
10    if (!parentComponent) {
11      return emptyContextObject;
12    }
13
14    var fiber = get(parentComponent);
15    var parentContext = findCurrentUnmaskedContext(fiber);
16
17    if (fiber.tag === ClassComponent) {
18      var Component = fiber.type;
19
20      if (isContextProvider(Component)) {
21        return processChildContext(fiber, Component, parentContext);
22      }
23    }
24
25    return parentContext;
26  }
27
28  function findHostInstanceWithWarning(component, methodName) {
29    {
30      var fiber = get(component);
31
32      if (fiber === undefined) {
33        if (typeof component.render === 'function') {
34          {
35            {
36              throw Error( "Unable to find node on an unmounted component." );
37            }
38          }
39        } else {
40          {
41            {
42              throw Error( "Argument appears to not be a ReactComponent. Keys: " + Object.keys(component) );
43            }
44          }
45        }
46      }
47
48      var hostFiber = findCurrentHostFiber(fiber);
49
50      if (hostFiber === null) {
51        return null;
52      }
53
54      if (hostFiber.mode & StrictMode) {
55        var componentName = getComponentName(fiber.type) || 'Component';
56
57        if (!didWarnAboutFindNodeInStrictMode[componentName]) {
58          didWarnAboutFindNodeInStrictMode[componentName] = true;
59          var previousFiber = current;
60
61          try {
62            setCurrentFiber(hostFiber);
63
64            if (fiber.mode & StrictMode) {
65              error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which is inside StrictMode. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
66            } else {
67              error('%s is deprecated in StrictMode. ' + '%s was passed an instance of %s which renders StrictMode children. ' + 'Instead, add a ref directly to the element you want to reference. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-find-node', methodName, methodName, componentName);
68            }
69          } finally {
70            // Ideally this should reset to previous but this shouldn't be called in
71            // render and there's another warning for that anyway.
72            if (previousFiber) {
73              setCurrentFiber(previousFiber);
74            } else {
75              resetCurrentFiber();
76            }
77          }
78        }
79      }
80
81      return hostFiber.stateNode;
82    }
83  }
84
85  function createContainer(containerInfo, tag, hydrate, hydrationCallbacks) {
86    return createFiberRoot(containerInfo, tag, hydrate);
87  }
88  // 容器级别的更新 container root-app
89  function updateContainer(element, container, parentComponent, callback) {
90    {
91      // 处理外部监听根fiber调度的钩子 暴露部分信息
92      onScheduleRoot(container, element);
93    }
94
95    var current$1 = container.current; // 指向fiber
96    var eventTime = requestEventTime();
97
98    {
99      // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
100      if ('undefined' !== typeof jest) {
101        warnIfUnmockedScheduler(current$1);
102        warnIfNotScopedWithMatchingAct(current$1);
103      }
104    }
105
106    var lane = requestUpdateLane(current$1);
107
108    {
109      markRenderScheduled(lane);
110    }
111
112    var context = getContextForSubtree(parentComponent);
113
114    if (container.context === null) {
115      container.context = context;
116    } else {
117      container.pendingContext = context;
118    }
119
120    {
121      if (isRendering && current !== null && !didWarnAboutNestedUpdates) {
122        didWarnAboutNestedUpdates = true;
123
124        error('Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', getComponentName(current.type) || 'Unknown');
125      }
126    }
127
128    var update = createUpdate(eventTime, lane); // Caution: React DevTools currently depends on this property
129    // being called "element".
130
131    update.payload = {
132      element: element
133    };
134    callback = callback === undefined ? null : callback;
135
136    if (callback !== null) {
137      {
138        if (typeof callback !== 'function') {
139          error('render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback);
140        }
141      }
142
143      update.callback = callback;
144    }
145
146    enqueueUpdate(current$1, update);
147    scheduleUpdateOnFiber(current$1, lane, eventTime);
148    return lane;
149  }
150  function getPublicRootInstance(container) {
151    var containerFiber = container.current;
152
153    if (!containerFiber.child) {
154      return null;
155    }
156
157    switch (containerFiber.child.tag) {
158      case HostComponent:
159        return getPublicInstance(containerFiber.child.stateNode);
160
161      default:
162        return containerFiber.child.stateNode;
163    }
164  }
165  function attemptSynchronousHydration$1(fiber) {
166    switch (fiber.tag) {
167      case HostRoot:
168        var root = fiber.stateNode;
169
170        if (root.hydrate) {
171          // Flush the first scheduled "update".
172          var lanes = getHighestPriorityPendingLanes(root);
173          flushRoot(root, lanes);
174        }
175
176        break;
177
178      case SuspenseComponent:
179        var eventTime = requestEventTime();
180        flushSync(function () {
181          return scheduleUpdateOnFiber(fiber, SyncLane, eventTime);
182        }); // If we're still blocked after this, we need to increase
183        // the priority of any promises resolving within this
184        // boundary so that they next attempt also has higher pri.
185
186        var retryLane = InputDiscreteHydrationLane;
187        markRetryLaneIfNotHydrated(fiber, retryLane);
188        break;
189    }
190  }
191
192  function markRetryLaneImpl(fiber, retryLane) {
193    var suspenseState = fiber.memoizedState;
194
195    if (suspenseState !== null && suspenseState.dehydrated !== null) {
196      suspenseState.retryLane = higherPriorityLane(suspenseState.retryLane, retryLane);
197    }
198  } // Increases the priority of thennables when they resolve within this boundary.
199
200
201  function markRetryLaneIfNotHydrated(fiber, retryLane) {
202    markRetryLaneImpl(fiber, retryLane);
203    var alternate = fiber.alternate;
204
205    if (alternate) {
206      markRetryLaneImpl(alternate, retryLane);
207    }
208  }
209
210  function attemptUserBlockingHydration$1(fiber) {
211    if (fiber.tag !== SuspenseComponent) {
212      // We ignore HostRoots here because we can't increase
213      // their priority and they should not suspend on I/O,
214      // since you have to wrap anything that might suspend in
215      // Suspense.
216      return;
217    }
218
219    var eventTime = requestEventTime();
220    var lane = InputDiscreteHydrationLane;
221    scheduleUpdateOnFiber(fiber, lane, eventTime);
222    markRetryLaneIfNotHydrated(fiber, lane);
223  }
224  function attemptContinuousHydration$1(fiber) {
225    if (fiber.tag !== SuspenseComponent) {
226      // We ignore HostRoots here because we can't increase
227      // their priority and they should not suspend on I/O,
228      // since you have to wrap anything that might suspend in
229      // Suspense.
230      return;
231    }
232
233    var eventTime = requestEventTime();
234    var lane = SelectiveHydrationLane;
235    scheduleUpdateOnFiber(fiber, lane, eventTime);
236    markRetryLaneIfNotHydrated(fiber, lane);
237  }
238  function attemptHydrationAtCurrentPriority$1(fiber) {
239    if (fiber.tag !== SuspenseComponent) {
240      // We ignore HostRoots here because we can't increase
241      // their priority other than synchronously flush it.
242      return;
243    }
244
245    var eventTime = requestEventTime();
246    var lane = requestUpdateLane(fiber);
247    scheduleUpdateOnFiber(fiber, lane, eventTime);
248    markRetryLaneIfNotHydrated(fiber, lane);
249  }
250  function runWithPriority$2(priority, fn) {
251    var previousPriority = getCurrentUpdateLanePriority();
252
253    try {
254      setCurrentUpdateLanePriority(priority);
255      return fn();
256    } finally {
257      setCurrentUpdateLanePriority(previousPriority);
258    }
259  }
260  function findHostInstanceWithNoPortals(fiber) {
261    var hostFiber = findCurrentHostFiberWithNoPortals(fiber);
262
263    if (hostFiber === null) {
264      return null;
265    }
266
267    if (hostFiber.tag === FundamentalComponent) {
268      return hostFiber.stateNode.instance;
269    }
270
271    return hostFiber.stateNode;
272  }
273
274  var shouldSuspendImpl = function (fiber) {
275    return false;
276  };
277
278  function shouldSuspend(fiber) {
279    return shouldSuspendImpl(fiber);
280  }
281  var overrideHookState = null;
282  var overrideHookStateDeletePath = null;
283  var overrideHookStateRenamePath = null;
284  var overrideProps = null;
285  var overridePropsDeletePath = null;
286  var overridePropsRenamePath = null;
287  var scheduleUpdate = null;
288  var setSuspenseHandler = null;
289
290  {
291    var copyWithDeleteImpl = function (obj, path, index) {
292      var key = path[index];
293      var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
294
295      if (index + 1 === path.length) {
296        if (Array.isArray(updated)) {
297          updated.splice(key, 1);
298        } else {
299          delete updated[key];
300        }
301
302        return updated;
303      } // $FlowFixMe number or string is fine here
304
305
306      updated[key] = copyWithDeleteImpl(obj[key], path, index + 1);
307      return updated;
308    };
309
310    var copyWithDelete = function (obj, path) {
311      return copyWithDeleteImpl(obj, path, 0);
312    };
313
314    var copyWithRenameImpl = function (obj, oldPath, newPath, index) {
315      var oldKey = oldPath[index];
316      var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj);
317
318      if (index + 1 === oldPath.length) {
319        var newKey = newPath[index]; // $FlowFixMe number or string is fine here
320
321        updated[newKey] = updated[oldKey];
322
323        if (Array.isArray(updated)) {
324          updated.splice(oldKey, 1);
325        } else {
326          delete updated[oldKey];
327        }
328      } else {
329        // $FlowFixMe number or string is fine here
330        updated[oldKey] = copyWithRenameImpl( // $FlowFixMe number or string is fine here
331        obj[oldKey], oldPath, newPath, index + 1);
332      }
333
334      return updated;
335    };
336
337    var copyWithRename = function (obj, oldPath, newPath) {
338      if (oldPath.length !== newPath.length) {
339        warn('copyWithRename() expects paths of the same length');
340
341        return;
342      } else {
343        for (var i = 0; i < newPath.length - 1; i++) {
344          if (oldPath[i] !== newPath[i]) {
345            warn('copyWithRename() expects paths to be the same except for the deepest key');
346
347            return;
348          }
349        }
350      }
351
352      return copyWithRenameImpl(obj, oldPath, newPath, 0);
353    };
354
355    var copyWithSetImpl = function (obj, path, index, value) {
356      if (index >= path.length) {
357        return value;
358      }
359
360      var key = path[index];
361      var updated = Array.isArray(obj) ? obj.slice() : _assign({}, obj); // $FlowFixMe number or string is fine here
362
363      updated[key] = copyWithSetImpl(obj[key], path, index + 1, value);
364      return updated;
365    };
366
367    var copyWithSet = function (obj, path, value) {
368      return copyWithSetImpl(obj, path, 0, value);
369    };
370
371    var findHook = function (fiber, id) {
372      // For now, the "id" of stateful hooks is just the stateful hook index.
373      // This may change in the future with e.g. nested hooks.
374      var currentHook = fiber.memoizedState;
375
376      while (currentHook !== null && id > 0) {
377        currentHook = currentHook.next;
378        id--;
379      }
380
381      return currentHook;
382    }; // Support DevTools editable values for useState and useReducer.
383
384
385    overrideHookState = function (fiber, id, path, value) {
386      var hook = findHook(fiber, id);
387
388      if (hook !== null) {
389        var newState = copyWithSet(hook.memoizedState, path, value);
390        hook.memoizedState = newState;
391        hook.baseState = newState; // We aren't actually adding an update to the queue,
392        // because there is no update we can add for useReducer hooks that won't trigger an error.
393        // (There's no appropriate action type for DevTools overrides.)
394        // As a result though, React will see the scheduled update as a noop and bailout.
395        // Shallow cloning props works as a workaround for now to bypass the bailout check.
396
397        fiber.memoizedProps = _assign({}, fiber.memoizedProps);
398        scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
399      }
400    };
401
402    overrideHookStateDeletePath = function (fiber, id, path) {
403      var hook = findHook(fiber, id);
404
405      if (hook !== null) {
406        var newState = copyWithDelete(hook.memoizedState, path);
407        hook.memoizedState = newState;
408        hook.baseState = newState; // We aren't actually adding an update to the queue,
409        // because there is no update we can add for useReducer hooks that won't trigger an error.
410        // (There's no appropriate action type for DevTools overrides.)
411        // As a result though, React will see the scheduled update as a noop and bailout.
412        // Shallow cloning props works as a workaround for now to bypass the bailout check.
413
414        fiber.memoizedProps = _assign({}, fiber.memoizedProps);
415        scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
416      }
417    };
418
419    overrideHookStateRenamePath = function (fiber, id, oldPath, newPath) {
420      var hook = findHook(fiber, id);
421
422      if (hook !== null) {
423        var newState = copyWithRename(hook.memoizedState, oldPath, newPath);
424        hook.memoizedState = newState;
425        hook.baseState = newState; // We aren't actually adding an update to the queue,
426        // because there is no update we can add for useReducer hooks that won't trigger an error.
427        // (There's no appropriate action type for DevTools overrides.)
428        // As a result though, React will see the scheduled update as a noop and bailout.
429        // Shallow cloning props works as a workaround for now to bypass the bailout check.
430
431        fiber.memoizedProps = _assign({}, fiber.memoizedProps);
432        scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
433      }
434    }; // Support DevTools props for function components, forwardRef, memo, host components, etc.
435
436
437    overrideProps = function (fiber, path, value) {
438      fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
439
440      if (fiber.alternate) {
441        fiber.alternate.pendingProps = fiber.pendingProps;
442      }
443
444      scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
445    };
446
447    overridePropsDeletePath = function (fiber, path) {
448      fiber.pendingProps = copyWithDelete(fiber.memoizedProps, path);
449
450      if (fiber.alternate) {
451        fiber.alternate.pendingProps = fiber.pendingProps;
452      }
453
454      scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
455    };
456
457    overridePropsRenamePath = function (fiber, oldPath, newPath) {
458      fiber.pendingProps = copyWithRename(fiber.memoizedProps, oldPath, newPath);
459
460      if (fiber.alternate) {
461        fiber.alternate.pendingProps = fiber.pendingProps;
462      }
463
464      scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
465    };
466
467    scheduleUpdate = function (fiber) {
468      scheduleUpdateOnFiber(fiber, SyncLane, NoTimestamp);
469    };
470
471    setSuspenseHandler = function (newShouldSuspendImpl) {
472      shouldSuspendImpl = newShouldSuspendImpl;
473    };
474  }
475
476  function findHostInstanceByFiber(fiber) {
477    var hostFiber = findCurrentHostFiber(fiber);
478
479    if (hostFiber === null) {
480      return null;
481    }
482
483    return hostFiber.stateNode;
484  }
485
486  function emptyFindFiberByHostInstance(instance) {
487    return null;
488  }
489
490  function getCurrentFiberForDevTools() {
491    return current;
492  }
493
494  function injectIntoDevTools(devToolsConfig) {
495    var findFiberByHostInstance = devToolsConfig.findFiberByHostInstance;
496    var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
497    return injectInternals({
498      bundleType: devToolsConfig.bundleType,
499      version: devToolsConfig.version,
500      rendererPackageName: devToolsConfig.rendererPackageName,
501      rendererConfig: devToolsConfig.rendererConfig,
502      overrideHookState: overrideHookState,
503      overrideHookStateDeletePath: overrideHookStateDeletePath,
504      overrideHookStateRenamePath: overrideHookStateRenamePath,
505      overrideProps: overrideProps,
506      overridePropsDeletePath: overridePropsDeletePath,
507      overridePropsRenamePath: overridePropsRenamePath,
508      setSuspenseHandler: setSuspenseHandler,
509      scheduleUpdate: scheduleUpdate,
510      currentDispatcherRef: ReactCurrentDispatcher,
511      findHostInstanceByFiber: findHostInstanceByFiber,
512      findFiberByHostInstance: findFiberByHostInstance || emptyFindFiberByHostInstance,
513      // React Refresh
514      findHostInstancesForRefresh:  findHostInstancesForRefresh ,
515      scheduleRefresh:  scheduleRefresh ,
516      scheduleRoot:  scheduleRoot ,
517      setRefreshHandler:  setRefreshHandler ,
518      // Enables DevTools to append owner stacks to error messages in DEV mode.
519      getCurrentFiber:  getCurrentFiberForDevTools 
520    });
521  }
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)