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

ReactFiberTransitionPool.old.js

Source: ReactFiberTransitionPool.old.js Github

copy
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9import type {FiberRoot} from './ReactInternalTypes';
10import type {Lanes} from './ReactFiberLane.old';
11import type {StackCursor} from './ReactFiberStack.old';
12import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.old';
13
14import {enableCache} from 'shared/ReactFeatureFlags';
15import {isPrimaryRenderer} from './ReactFiberHostConfig';
16import {createCursor, push, pop} from './ReactFiberStack.old';
17import {getWorkInProgressRoot} from './ReactFiberWorkLoop.old';
18import {
19  createCache,
20  retainCache,
21  CacheContext,
22} from './ReactFiberCacheComponent.old';
23
24// When retrying a Suspense/Offscreen boundary, we restore the cache that was
25// used during the previous render by placing it here, on the stack.
26const resumedCache: StackCursor<Cache | null> = createCursor(null);
27
28function peekCacheFromPool(): Cache | null {
29  if (!enableCache) {
30    return (null: any);
31  }
32
33  // Check if the cache pool already has a cache we can use.
34
35  // If we're rendering inside a Suspense boundary that is currently hidden,
36  // we should use the same cache that we used during the previous render, if
37  // one exists.
38  const cacheResumedFromPreviousRender = resumedCache.current;
39  if (cacheResumedFromPreviousRender !== null) {
40    return cacheResumedFromPreviousRender;
41  }
42
43  // Otherwise, check the root's cache pool.
44  const root = (getWorkInProgressRoot(): any);
45  const cacheFromRootCachePool = root.pooledCache;
46
47  return cacheFromRootCachePool;
48}
49
50export function requestCacheFromPool(renderLanes: Lanes): Cache {
51  // Similar to previous function, except if there's not already a cache in the
52  // pool, we allocate a new one.
53  const cacheFromPool = peekCacheFromPool();
54  if (cacheFromPool !== null) {
55    return cacheFromPool;
56  }
57
58  // Create a fresh cache and add it to the root cache pool. A cache can have
59  // multiple owners:
60  // - A cache pool that lives on the FiberRoot. This is where all fresh caches
61  //   are originally created (TODO: except during refreshes, until we implement
62  //   this correctly). The root takes ownership immediately when the cache is
63  //   created. Conceptually, root.pooledCache is an Option<Arc<Cache>> (owned),
64  //   and the return value of this function is a &Arc<Cache> (borrowed).
65  // - One of several fiber types: host root, cache boundary, suspense
66  //   component. These retain and release in the commit phase.
67
68  const root = (getWorkInProgressRoot(): any);
69  const freshCache = createCache();
70  root.pooledCache = freshCache;
71  retainCache(freshCache);
72  if (freshCache !== null) {
73    root.pooledCacheLanes |= renderLanes;
74  }
75  return freshCache;
76}
77
78export function pushRootTransitionPool(root: FiberRoot) {
79  if (enableCache) {
80    return;
81  }
82  // Note: This function currently does nothing but I'll leave it here for
83  // code organization purposes in case that changes.
84}
85
86export function popRootTransitionPool(root: FiberRoot, renderLanes: Lanes) {
87  if (enableCache) {
88    return;
89  }
90  // Note: This function currently does nothing but I'll leave it here for
91  // code organization purposes in case that changes.
92}
93
94export function pushTransitionPool(
95  offscreenWorkInProgress: Fiber,
96  prevCachePool: SpawnedCachePool | null,
97): void {
98  if (enableCache) {
99    if (prevCachePool === null) {
100      push(resumedCache, resumedCache.current, offscreenWorkInProgress);
101    } else {
102      push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
103    }
104  }
105}
106
107export function popTransitionPool(workInProgress: Fiber) {
108  if (enableCache) {
109    pop(resumedCache, workInProgress);
110  }
111}
112
113export function getSuspendedCachePool(): SpawnedCachePool | null {
114  if (!enableCache) {
115    return null;
116  }
117  // This function is called when a Suspense boundary suspends. It returns the
118  // cache that would have been used to render fresh data during this render,
119  // if there was any, so that we can resume rendering with the same cache when
120  // we receive more data.
121  const cacheFromPool = peekCacheFromPool();
122  if (cacheFromPool === null) {
123    return null;
124  }
125
126  return {
127    // We must also save the parent, so that when we resume we can detect
128    // a refresh.
129    parent: isPrimaryRenderer
130      ? CacheContext._currentValue
131      : CacheContext._currentValue2,
132    pool: cacheFromPool,
133  };
134}
135
136export function getOffscreenDeferredCachePool(): SpawnedCachePool | null {
137  if (!enableCache) {
138    return null;
139  }
140
141  const cacheFromPool = peekCacheFromPool();
142  if (cacheFromPool === null) {
143    return null;
144  }
145
146  return {
147    // We must also store the parent, so that when we resume we can detect
148    // a refresh.
149    parent: isPrimaryRenderer
150      ? CacheContext._currentValue
151      : CacheContext._currentValue2,
152    pool: cacheFromPool,
153  };
154}
155
Full Screen

ReactFiberTransition.new.js

Source: ReactFiberTransition.new.js Github

copy
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9import type {FiberRoot} from './ReactInternalTypes';
10import type {Lanes} from './ReactFiberLane.new';
11import type {StackCursor} from './ReactFiberStack.new';
12import type {Cache, SpawnedCachePool} from './ReactFiberCacheComponent.new';
13
14import {enableCache} from 'shared/ReactFeatureFlags';
15import {isPrimaryRenderer} from './ReactFiberHostConfig';
16import {createCursor, push, pop} from './ReactFiberStack.new';
17import {getWorkInProgressRoot} from './ReactFiberWorkLoop.new';
18import {
19  createCache,
20  retainCache,
21  CacheContext,
22} from './ReactFiberCacheComponent.new';
23
24// When retrying a Suspense/Offscreen boundary, we restore the cache that was
25// used during the previous render by placing it here, on the stack.
26const resumedCache: StackCursor<Cache | null> = createCursor(null);
27
28function peekCacheFromPool(): Cache | null {
29  if (!enableCache) {
30    return (null: any);
31  }
32
33  // Check if the cache pool already has a cache we can use.
34
35  // If we're rendering inside a Suspense boundary that is currently hidden,
36  // we should use the same cache that we used during the previous render, if
37  // one exists.
38  const cacheResumedFromPreviousRender = resumedCache.current;
39  if (cacheResumedFromPreviousRender !== null) {
40    return cacheResumedFromPreviousRender;
41  }
42
43  // Otherwise, check the root's cache pool.
44  const root = (getWorkInProgressRoot(): any);
45  const cacheFromRootCachePool = root.pooledCache;
46
47  return cacheFromRootCachePool;
48}
49
50export function requestCacheFromPool(renderLanes: Lanes): Cache {
51  // Similar to previous function, except if there's not already a cache in the
52  // pool, we allocate a new one.
53  const cacheFromPool = peekCacheFromPool();
54  if (cacheFromPool !== null) {
55    return cacheFromPool;
56  }
57
58  // Create a fresh cache and add it to the root cache pool. A cache can have
59  // multiple owners:
60  // - A cache pool that lives on the FiberRoot. This is where all fresh caches
61  //   are originally created (TODO: except during refreshes, until we implement
62  //   this correctly). The root takes ownership immediately when the cache is
63  //   created. Conceptually, root.pooledCache is an Option<Arc<Cache>> (owned),
64  //   and the return value of this function is a &Arc<Cache> (borrowed).
65  // - One of several fiber types: host root, cache boundary, suspense
66  //   component. These retain and release in the commit phase.
67
68  const root = (getWorkInProgressRoot(): any);
69  const freshCache = createCache();
70  root.pooledCache = freshCache;
71  retainCache(freshCache);
72  if (freshCache !== null) {
73    root.pooledCacheLanes |= renderLanes;
74  }
75  return freshCache;
76}
77
78export function pushRootTransition(root: FiberRoot) {
79  if (enableCache) {
80    return;
81  }
82  // Note: This function currently does nothing but I'll leave it here for
83  // code organization purposes in case that changes.
84}
85
86export function popRootTransition(root: FiberRoot, renderLanes: Lanes) {
87  if (enableCache) {
88    return;
89  }
90  // Note: This function currently does nothing but I'll leave it here for
91  // code organization purposes in case that changes.
92}
93
94export function pushTransition(
95  offscreenWorkInProgress: Fiber,
96  prevCachePool: SpawnedCachePool | null,
97): void {
98  if (enableCache) {
99    if (prevCachePool === null) {
100      push(resumedCache, resumedCache.current, offscreenWorkInProgress);
101    } else {
102      push(resumedCache, prevCachePool.pool, offscreenWorkInProgress);
103    }
104  }
105}
106
107export function popTransition(workInProgress: Fiber) {
108  if (enableCache) {
109    pop(resumedCache, workInProgress);
110  }
111}
112
113export function getSuspendedCache(): SpawnedCachePool | null {
114  if (!enableCache) {
115    return null;
116  }
117  // This function is called when a Suspense boundary suspends. It returns the
118  // cache that would have been used to render fresh data during this render,
119  // if there was any, so that we can resume rendering with the same cache when
120  // we receive more data.
121  const cacheFromPool = peekCacheFromPool();
122  if (cacheFromPool === null) {
123    return null;
124  }
125
126  return {
127    // We must also save the parent, so that when we resume we can detect
128    // a refresh.
129    parent: isPrimaryRenderer
130      ? CacheContext._currentValue
131      : CacheContext._currentValue2,
132    pool: cacheFromPool,
133  };
134}
135
136export function getOffscreenDeferredCache(): SpawnedCachePool | null {
137  if (!enableCache) {
138    return null;
139  }
140
141  const cacheFromPool = peekCacheFromPool();
142  if (cacheFromPool === null) {
143    return null;
144  }
145
146  return {
147    // We must also store the parent, so that when we resume we can detect
148    // a refresh.
149    parent: isPrimaryRenderer
150      ? CacheContext._currentValue
151      : CacheContext._currentValue2,
152    pool: cacheFromPool,
153  };
154}
155
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)