How to use mergeLanes 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.

ReactFiberNewContext.old.js

Source: ReactFiberNewContext.old.js Github

copy
1  var valueCursor = createCursor(null);
2  var rendererSigil;
3
4  {
5    // Use this to detect multiple renderers using the same context
6    rendererSigil = {};
7  }
8
9  var currentlyRenderingFiber = null;
10  var lastContextDependency = null;
11  var lastContextWithAllBitsObserved = null;
12  var isDisallowedContextReadInDEV = false;
13  function resetContextDependencies() {
14    // This is called right before React yields execution, to ensure `readContext`
15    // cannot be called outside the render phase.
16    currentlyRenderingFiber = null;
17    lastContextDependency = null;
18    lastContextWithAllBitsObserved = null;
19
20    {
21      isDisallowedContextReadInDEV = false;
22    }
23  }
24  function enterDisallowedContextReadInDEV() {
25    {
26      isDisallowedContextReadInDEV = true;
27    }
28  }
29  function exitDisallowedContextReadInDEV() {
30    {
31      isDisallowedContextReadInDEV = false;
32    }
33  }
34  function pushProvider(providerFiber, nextValue) {
35    var context = providerFiber.type._context;
36
37    {
38      push(valueCursor, context._currentValue, providerFiber);
39      context._currentValue = nextValue;
40
41      {
42        if (context._currentRenderer !== undefined && context._currentRenderer !== null && context._currentRenderer !== rendererSigil) {
43          error('Detected multiple renderers concurrently rendering the ' + 'same context provider. This is currently unsupported.');
44        }
45
46        context._currentRenderer = rendererSigil;
47      }
48    }
49  }
50  function popProvider(providerFiber) {
51    var currentValue = valueCursor.current;
52    pop(valueCursor, providerFiber);
53    var context = providerFiber.type._context;
54
55    {
56      context._currentValue = currentValue;
57    }
58  }
59  function calculateChangedBits(context, newValue, oldValue) {
60    if (objectIs(oldValue, newValue)) {
61      // No change
62      return 0;
63    } else {
64      var changedBits = typeof context._calculateChangedBits === 'function' ? context._calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT;
65
66      {
67        if ((changedBits & MAX_SIGNED_31_BIT_INT) !== changedBits) {
68          error('calculateChangedBits: Expected the return value to be a ' + '31-bit integer. Instead received: %s', changedBits);
69        }
70      }
71
72      return changedBits | 0;
73    }
74  }
75  function scheduleWorkOnParentPath(parent, renderLanes) {
76    // Update the child lanes of all the ancestors, including the alternates.
77    var node = parent;
78
79    while (node !== null) {
80      var alternate = node.alternate;
81
82      if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
83        node.childLanes = mergeLanes(node.childLanes, renderLanes);
84
85        if (alternate !== null) {
86          alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
87        }
88      } else if (alternate !== null && !isSubsetOfLanes(alternate.childLanes, renderLanes)) {
89        alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
90      } else {
91        // Neither alternate was updated, which means the rest of the
92        // ancestor path already has sufficient priority.
93        break;
94      }
95
96      node = node.return;
97    }
98  }
99  function propagateContextChange(workInProgress, context, changedBits, renderLanes) {
100    var fiber = workInProgress.child;
101
102    if (fiber !== null) {
103      // Set the return pointer of the child to the work-in-progress fiber.
104      fiber.return = workInProgress;
105    }
106
107    while (fiber !== null) {
108      var nextFiber = void 0; // Visit this fiber.
109
110      var list = fiber.dependencies;
111
112      if (list !== null) {
113        nextFiber = fiber.child;
114        var dependency = list.firstContext;
115
116        while (dependency !== null) {
117          // Check if the context matches.
118          if (dependency.context === context && (dependency.observedBits & changedBits) !== 0) {
119            // Match! Schedule an update on this fiber.
120            if (fiber.tag === ClassComponent) {
121              // Schedule a force update on the work-in-progress.
122              var update = createUpdate(NoTimestamp, pickArbitraryLane(renderLanes));
123              update.tag = ForceUpdate; // TODO: Because we don't have a work-in-progress, this will add the
124              // update to the current fiber, too, which means it will persist even if
125              // this render is thrown away. Since it's a race condition, not sure it's
126              // worth fixing.
127
128              enqueueUpdate(fiber, update);
129            }
130
131            fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
132            var alternate = fiber.alternate;
133
134            if (alternate !== null) {
135              alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
136            }
137
138            scheduleWorkOnParentPath(fiber.return, renderLanes); // Mark the updated lanes on the list, too.
139
140            list.lanes = mergeLanes(list.lanes, renderLanes); // Since we already found a match, we can stop traversing the
141            // dependency list.
142
143            break;
144          }
145
146          dependency = dependency.next;
147        }
148      } else if (fiber.tag === ContextProvider) {
149        // Don't scan deeper if this is a matching provider
150        nextFiber = fiber.type === workInProgress.type ? null : fiber.child;
151      } else if ( fiber.tag === DehydratedFragment) {
152        // If a dehydrated suspense boundary is in this subtree, we don't know
153        // if it will have any context consumers in it. The best we can do is
154        // mark it as having updates.
155        var parentSuspense = fiber.return;
156
157        if (!(parentSuspense !== null)) {
158          {
159            throw Error( "We just came from a parent so we must have had a parent. This is a bug in React." );
160          }
161        }
162
163        parentSuspense.lanes = mergeLanes(parentSuspense.lanes, renderLanes);
164        var _alternate = parentSuspense.alternate;
165
166        if (_alternate !== null) {
167          _alternate.lanes = mergeLanes(_alternate.lanes, renderLanes);
168        } // This is intentionally passing this fiber as the parent
169        // because we want to schedule this fiber as having work
170        // on its children. We'll use the childLanes on
171        // this fiber to indicate that a context has changed.
172
173
174        scheduleWorkOnParentPath(parentSuspense, renderLanes);
175        nextFiber = fiber.sibling;
176      } else {
177        // Traverse down.
178        nextFiber = fiber.child;
179      }
180
181      if (nextFiber !== null) {
182        // Set the return pointer of the child to the work-in-progress fiber.
183        nextFiber.return = fiber;
184      } else {
185        // No child. Traverse to next sibling.
186        nextFiber = fiber;
187
188        while (nextFiber !== null) {
189          if (nextFiber === workInProgress) {
190            // We're back to the root of this subtree. Exit.
191            nextFiber = null;
192            break;
193          }
194
195          var sibling = nextFiber.sibling;
196
197          if (sibling !== null) {
198            // Set the return pointer of the sibling to the work-in-progress fiber.
199            sibling.return = nextFiber.return;
200            nextFiber = sibling;
201            break;
202          } // No more siblings. Traverse up.
203
204
205          nextFiber = nextFiber.return;
206        }
207      }
208
209      fiber = nextFiber;
210    }
211  }
212  function prepareToReadContext(workInProgress, renderLanes) {
213    currentlyRenderingFiber = workInProgress;
214    lastContextDependency = null;
215    lastContextWithAllBitsObserved = null;
216    var dependencies = workInProgress.dependencies;
217
218    if (dependencies !== null) {
219      var firstContext = dependencies.firstContext;
220
221      if (firstContext !== null) {
222        if (includesSomeLane(dependencies.lanes, renderLanes)) {
223          // Context list has a pending update. Mark that this fiber performed work.
224          markWorkInProgressReceivedUpdate();
225        } // Reset the work-in-progress list
226
227
228        dependencies.firstContext = null;
229      }
230    }
231  }
232  function readContext(context, observedBits) {
233    {
234      // This warning would fire if you read context inside a Hook like useMemo.
235      // Unlike the class check below, it's not enforced in production for perf.
236      if (isDisallowedContextReadInDEV) {
237        error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
238      }
239    }
240
241    if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
242      var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
243
244      if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
245        // Observe all updates.
246        lastContextWithAllBitsObserved = context;
247        resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
248      } else {
249        resolvedObservedBits = observedBits;
250      }
251
252      var contextItem = {
253        context: context,
254        observedBits: resolvedObservedBits,
255        next: null
256      };
257
258      if (lastContextDependency === null) {
259        if (!(currentlyRenderingFiber !== null)) {
260          {
261            throw Error( "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." );
262          }
263        } // This is the first dependency for this component. Create a new list.
264
265
266        lastContextDependency = contextItem;
267        currentlyRenderingFiber.dependencies = {
268          lanes: NoLanes,
269          firstContext: contextItem,
270          responders: null
271        };
272      } else {
273        // Append a new context item.
274        lastContextDependency = lastContextDependency.next = contextItem;
275      }
276    }
277
278    return  context._currentValue ;
279  }
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)