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

ReactFiberUnwindWork.js

Source: ReactFiberUnwindWork.js Github

copy
1import { HostRoot } from './ReactWorkTags';
2import { popHostContainer } from './ReactFiberHostContext';
3import { popTopLevelContextObject } from './ReactFiberContext';
4import { resetWorkInProgressVersions } from './ReactMutableSource';
5import { DidCapture, NoFlags, ShouldCapture } from './ReactFiberFlags';
6
7const invariant = require('invariant');
8
9const unwindInterruptedWork = (interruptedWork) => {};
10
11const unwindWork = (workInProgress, renderLanes) => {
12  switch (workInProgress.tag) {
13    // case ClassComponent: {
14    //   const Component = workInProgress.type;
15    //   if (isLegacyContextProvider(Component)) {
16    //     popLegacyContext(workInProgress);
17    //   }
18    //   const flags = workInProgress.flags;
19    //   if (flags & ShouldCapture) {
20    //     workInProgress.flags = (flags & ~ShouldCapture) | DidCapture;
21    //     if (
22    //       enableProfilerTimer &&
23    //       (workInProgress.mode & ProfileMode) !== NoMode
24    //     ) {
25    //       transferActualDuration(workInProgress);
26    //     }
27    //     return workInProgress;
28    //   }
29    //   return null;
30    // }
31    case HostRoot: {
32      popHostContainer(workInProgress);
33      popTopLevelContextObject(workInProgress);
34      resetWorkInProgressVersions();
35      const flags = workInProgress.flags;
36      invariant(
37        (flags & DidCapture) === NoFlags,
38        'The root failed to unmount after an error. This is likely a bug in ' +
39          'React. Please file an issue.'
40      );
41      workInProgress.flags = (flags & ~ShouldCapture) | DidCapture;
42      console.log(flags, (flags & ~ShouldCapture) | DidCapture);
43      return workInProgress;
44    }
45    // case HostComponent: {
46    //   // TODO: popHydrationState
47    //   popHostContext(workInProgress);
48    //   return null;
49    // }
50    // case SuspenseComponent: {
51    //   popSuspenseContext(workInProgress);
52    //   if (enableSuspenseServerRenderer) {
53    //     const suspenseState: null | SuspenseState =
54    //       workInProgress.memoizedState;
55    //     if (suspenseState !== null && suspenseState.dehydrated !== null) {
56    //       invariant(
57    //         workInProgress.alternate !== null,
58    //         'Threw in newly mounted dehydrated component. This is likely a bug in ' +
59    //           'React. Please file an issue.',
60    //       );
61    //       resetHydrationState();
62    //     }
63    //   }
64    //   const flags = workInProgress.flags;
65    //   if (flags & ShouldCapture) {
66    //     workInProgress.flags = (flags & ~ShouldCapture) | DidCapture;
67    //     // Captured a suspense effect. Re-render the boundary.
68    //     if (
69    //       enableProfilerTimer &&
70    //       (workInProgress.mode & ProfileMode) !== NoMode
71    //     ) {
72    //       transferActualDuration(workInProgress);
73    //     }
74    //     return workInProgress;
75    //   }
76    //   return null;
77    // }
78    // case SuspenseListComponent: {
79    //   popSuspenseContext(workInProgress);
80    //   // SuspenseList doesn't actually catch anything. It should've been
81    //   // caught by a nested boundary. If not, it should bubble through.
82    //   return null;
83    // }
84    // case HostPortal:
85    //   popHostContainer(workInProgress);
86    //   return null;
87    // case ContextProvider:
88    //   popProvider(workInProgress);
89    //   return null;
90    // case OffscreenComponent:
91    // case LegacyHiddenComponent:
92    //   popRenderLanes(workInProgress);
93    //   return null;
94    default:
95      return null;
96  }
97};
98
99export { unwindInterruptedWork, unwindWork };
100
Full Screen

ReactFiberContext.js

Source: ReactFiberContext.js Github

copy
1import { ClassComponent, HostRoot } from './ReactWorkTags';
2import { createCursor, push, pop } from './ReactFiberStack';
3
4const emptyContextObject = {};
5
6const contextStackCursor = createCursor(emptyContextObject);
7const didPerformWorkStackCursor = createCursor(false);
8
9let previousContext = emptyContextObject;
10
11const isContextProvider = (type) => {
12  const { childContextTypes } = type;
13  return childContextTypes !== null && childContextTypes !== undefined;
14};
15
16const popContext = (fiber) => {
17  pop(didPerformWorkStackCursor, fiber);
18  pop(contextStackCursor, fiber);
19};
20
21const findCurrentUnmaskedContext = (fiber) => {
22  let node = fiber;
23
24  do {
25    switch (node.tag) {
26      case HostRoot:
27        return node.stateNode.context;
28      case ClassComponent: {
29        const Component = node.type;
30        if (isContextProvider(Component)) {
31          return node.stateNode.__reactInternalMemoizedMergedChildContext;
32        }
33        break;
34      }
35    }
36    node = node.return;
37  } while (node !== null);
38};
39
40const processChildContext = (fiber, type, parentContext) => {
41  const instance = fiber.stateNode;
42
43  if (typeof instance.getChildContext !== 'function') return parentContext;
44
45  const childContext = instance.getChildContext();
46
47  return { ...parentContext, ...childContext };
48};
49
50const hasContextChanged = () => didPerformWorkStackCursor.current;
51
52const pushTopLevelContextObject = (fiber, context, didChange) => {
53  push(contextStackCursor, context, fiber);
54  push(didPerformWorkStackCursor, didChange, fiber);
55};
56
57const popTopLevelContextObject = (fiber) => {
58  pop(didPerformWorkStackCursor, fiber);
59  pop(contextStackCursor, fiber);
60};
61
62const pushContextProvider = (workInProgress) => {
63  const instance = workInProgress.stateNode;
64
65  const memoizedMergedChildContext =
66    (instance && instance.__reactInternalMemoizedMergedChildContext) ||
67    emptyContextObject;
68
69  previousContext = contextStackCursor.current;
70  push(contextStackCursor, memoizedMergedChildContext, workInProgress);
71  push(
72    didPerformWorkStackCursor,
73    didPerformWorkStackCursor.current,
74    workInProgress
75  );
76
77  return true;
78};
79
80const getUnmaskedContext = (
81  workInProgress,
82  Component,
83  didPushOwnContextIfProvider
84) => {
85  if (didPushOwnContextIfProvider && isContextProvider(Component)) {
86    return previousContext;
87  }
88  return contextStackCursor.current;
89};
90
91const cacheContext = (workInProgress, unmaskedContext, maskedContext) => {
92  const instance = workInProgress.stateNode;
93  instance.__reactInternalMemoizedUnmaskedChildContext = unmaskedContext;
94  instance.__reactInternalMemoizedMaskedChildContext = maskedContext;
95};
96
97const getMaskedContext = (workInProgress, unmaskedContext) => {
98  const type = workInProgress.type;
99  const contextTypes = type.contextTypes;
100  if (!contextTypes) return emptyContextObject;
101
102  const instance = workInProgress.stateNode;
103  if (
104    instance &&
105    instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
106  ) {
107    return instance.__reactInternalMemoizedMaskedChildContext;
108  }
109
110  const context = {};
111  for (const key in contextTypes) {
112    context[key] = unmaskedContext[key];
113  }
114
115  if (instance) {
116    cacheContext(workInProgress, unmaskedContext, context);
117  }
118
119  return context;
120};
121
122const invalidateContextProvider = (workInProgress, type, didChange) => {
123  const instance = workInProgress.stateNode;
124  invariant(
125    instance,
126    'Expected to have an instance by this point. ' +
127      'This error is likely caused by a bug in React. Please file an issue.'
128  );
129
130  if (didChange) {
131    const mergedContext = processChildContext(
132      workInProgress,
133      type,
134      previousContext
135    );
136    instance.__reactInternalMemoizedMergedChildContext = mergedContext;
137
138    pop(didPerformWorkStackCursor, workInProgress);
139    pop(contextStackCursor, workInProgress);
140
141    push(contextStackCursor, mergedContext, workInProgress);
142    push(didPerformWorkStackCursor, didChange, workInProgress);
143  } else {
144    pop(didPerformWorkStackCursor, workInProgress);
145    push(didPerformWorkStackCursor, didChange, workInProgress);
146  }
147};
148
149export {
150  emptyContextObject,
151  isContextProvider,
152  popContext,
153  findCurrentUnmaskedContext,
154  processChildContext,
155  hasContextChanged,
156  pushTopLevelContextObject,
157  popTopLevelContextObject,
158  pushContextProvider,
159  getUnmaskedContext,
160  getMaskedContext,
161  cacheContext,
162  invalidateContextProvider,
163};
164
Full Screen

ReactFiberCompleteWork.js

Source: ReactFiberCompleteWork.js Github

copy
1import { HostRoot, HostComponent, HostText, HostPortal } from './ReactWorkTags';
2import { Ref, Update, NoFlags, DidCapture, Snapshot } from './ReactFiberFlags';
3import { popTopLevelContextObject } from './ReactFiberContext';
4import {
5  popHostContainer,
6  getRootHostContainer,
7  getHostContext,
8  popHostContext,
9} from './ReactFiberHostContext';
10import { resetWorkInProgressVersions } from './ReactMutableSource';
11import {
12  popHydrationState,
13  prepareToHydrateHostInstance,
14} from './ReactFiberHydrationContext';
15import {
16  prepareUpdate,
17  createInstance,
18  appendInitialChild,
19  finalizeInitialChildren,
20} from './ReactFiberHostConfig';
21
22const invariant = require('invariant');
23
24const markUpdate = (workInProgress) => {
25  workInProgress.flags |= Update;
26};
27
28const updateHostComponent = (
29  current,
30  workInProgress,
31  type,
32  newProps,
33  rootContainerInstance
34) => {
35  const oldProps = current.memoizedProps;
36  if (oldProps === newProps) return;
37
38  const instance = workInProgress.stateNode;
39  const currentHostContext = getHostContext();
40
41  const updatePayload = prepareUpdate(
42    instance,
43    type,
44    oldProps,
45    newProps,
46    rootContainerInstance,
47    currentHostContext
48  );
49
50  workInProgress.updateQueue = updatePayload;
51
52  if (updatePayload) {
53    markUpdate(workInProgress);
54  }
55};
56
57const appendAllChildren = (
58  parent,
59  workInProgress,
60  needsVisibilityToggle,
61  isHidden
62) => {
63  let node = workInProgress.child;
64  while (node !== null) {
65    if (node.tag === HostComponent || node.tag === HostText) {
66      appendInitialChild(parent, node.stateNode);
67    } else if (node.tag === HostPortal) {
68      // If we have a portal child, then we don't want to traverse
69      // down its children. Instead, we'll get insertions from each child in
70      // the portal directly.
71    } else if (node.child !== null) {
72      node.child.return = node;
73      node = node.child;
74      continue;
75    }
76    if (node === workInProgress) {
77      return;
78    }
79    while (node.sibling === null) {
80      if (node.return === null || node.return === workInProgress) {
81        return;
82      }
83      node = node.return;
84    }
85    node.sibling.return = node.return;
86    node = node.sibling;
87  }
88};
89
90const completeWork = (current, workInProgress, renderLanes) => {
91  const newProps = workInProgress.pendingProps;
92
93  switch (workInProgress.tag) {
94    case HostRoot: {
95      popHostContainer(workInProgress);
96      popTopLevelContextObject(workInProgress);
97      resetWorkInProgressVersions();
98      const fiberRoot = workInProgress.stateNode;
99      if (fiberRoot.pendingContext) {
100        fiberRoot.context = fiberRoot.pendingContext;
101        fiberRoot.pendingContext = null;
102      }
103      if (current === null || current.child === null) {
104        const wasHydrated = popHydrationState(workInProgress);
105        if (wasHydrated) {
106          markUpdate(workInProgress);
107        } else if (!fiberRoot.hydrate) {
108          workInProgress.flags |= Snapshot;
109        }
110      }
111
112      return null;
113    }
114    case HostComponent: {
115      popHostContext(workInProgress);
116      const rootContainerInstance = getRootHostContainer();
117
118      const type = workInProgress.type;
119      if (current !== null && workInProgress.stateNode != null) {
120        updateHostComponent(
121          current,
122          workInProgress,
123          type,
124          newProps,
125          rootContainerInstance
126        );
127
128        if (current.ref !== workInProgress.ref) {
129          markRef(workInProgress);
130        }
131      } else {
132        if (!newProps) {
133          invariant(
134            workInProgress.stateNode !== null,
135            'We must have new props for new mounts. This error is likely ' +
136              'caused by a bug in React. Please file an issue.'
137          );
138
139          return null;
140        }
141
142        const currentHostContext = getHostContext();
143
144        const wasHydrated = popHydrationState(workInProgress);
145        if (wasHydrated) {
146          if (
147            prepareToHydrateHostInstance(
148              workInProgress,
149              rootContainerInstance,
150              currentHostContext
151            )
152          ) {
153            markUpdate(workInProgress);
154          }
155        } else {
156          const instance = createInstance(
157            type,
158            newProps,
159            rootContainerInstance,
160            currentHostContext,
161            workInProgress
162          );
163
164          appendAllChildren(instance, workInProgress, false, false);
165
166          workInProgress.stateNode = instance;
167
168          if (
169            finalizeInitialChildren(
170              instance,
171              type,
172              newProps,
173              rootContainerInstance,
174              currentHostContext
175            )
176          ) {
177            markUpdate(workInProgress);
178          }
179        }
180
181        if (workInProgress.ref !== null) {
182          markRef(workInProgress);
183        }
184      }
185      return null;
186    }
187  }
188};
189
190export { completeWork };
191
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)