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

renderer.js

Source: renderer.js Github

copy
1'use strict';
2
3import ReactFiberReconciler from 'react-reconciler';
4import {
5  unstable_scheduleCallback as schedulePassiveEffects,
6  unstable_cancelCallback as cancelPassiveEffects
7} from 'scheduler';
8
9import { createInstance } from './elements';
10import propsEqual from './utils/propsEqual';
11
12const emptyObject = {};
13
14// If the Link has a strign child or render prop, substitute the instance by a Text,
15// that will ultimately render the inline Link via the textkit PDF renderer.
16const shouldReplaceLink = (type, props) =>
17  type === 'LINK' &&
18  (typeof props.children === 'string' ||
19    typeof props.children === 'number' ||
20    Array.isArray(props.children) ||
21    props.render);
22
23const PDFRenderer = ReactFiberReconciler({
24  schedulePassiveEffects,
25  cancelPassiveEffects,
26  supportsMutation: true,
27  appendInitialChild(parentInstance, child) {
28    parentInstance.appendChild(child);
29  },
30
31  createInstance(type, props, internalInstanceHandle) {
32    const instanceType = shouldReplaceLink(type, props) ? 'TEXT' : type;
33    return createInstance(
34      { type: instanceType, props },
35      internalInstanceHandle,
36    );
37  },
38
39  createTextInstance(text, rootContainerInstance) {
40    return createInstance(
41      { type: 'TEXT_INSTANCE', props: text },
42      rootContainerInstance,
43    );
44  },
45
46  finalizeInitialChildren(element, type, props) {
47    return false;
48  },
49
50  getPublicInstance(instance) {
51    return instance;
52  },
53
54  prepareForCommit() {
55    // Noop
56  },
57
58  prepareUpdate(element, type, oldProps, newProps) {
59    return !propsEqual(oldProps, newProps);
60  },
61
62  resetAfterCommit() {
63    // Noop
64  },
65
66  resetTextContent(element) {
67    // Noop
68  },
69
70  getRootHostContext() {
71    return emptyObject;
72  },
73
74  getChildHostContext() {
75    return emptyObject;
76  },
77
78  shouldSetTextContent(type, props) {
79    return false;
80  },
81
82  now: Date.now,
83
84  useSyncScheduling: true,
85
86  appendChild(parentInstance, child) {
87    parentInstance.appendChild(child);
88  },
89
90  appendChildToContainer(parentInstance, child) {
91    parentInstance.appendChild(child);
92  },
93
94  insertBefore(parentInstance, child, beforeChild) {
95    parentInstance.appendChildBefore(child, beforeChild);
96  },
97
98  removeChild(parentInstance, child) {
99    parentInstance.removeChild(child);
100  },
101
102  removeChildFromContainer(parentInstance, child) {
103    parentInstance.removeChild(child);
104  },
105
106  commitTextUpdate(textInstance, oldText, newText) {
107    textInstance.update(newText);
108  },
109
110  commitUpdate(instance, updatePayload, type, oldProps, newProps) {
111    instance.update(newProps);
112  },
113});
114
115export default PDFRenderer;
116
Full Screen

reconciler.js

Source: reconciler.js Github

copy
1import Reconciler from 'react-reconciler';
2import {
3  unstable_scheduleCallback as schedulePassiveEffects,
4  unstable_cancelCallback as cancelPassiveEffects,
5  unstable_now as now,
6} from 'scheduler';
7import {Node} from './Node';
8
9const roots = new Map();
10
11function appendInitialChild(parent, child) {
12  parent.add(child);
13}
14
15function appendChild(parent, child) {
16  parent.add(child);
17}
18
19function appendChildToContainer(parent, child) {
20  parent.add(child);
21}
22
23function removeChild(parent, child) {
24  parent.remove(child);
25}
26
27function insertBefore(parentInstance, child, beforeChild) {
28  parentInstance.add(child);
29}
30
31function createInstance(type, props, container, hostContext, fiber) {
32  const instance = new Node(type, props, container);
33
34  return instance;
35}
36
37function commitUpdate(
38  instance,
39  updatePayload,
40  type,
41  oldProps,
42  newProps,
43  fiber,
44) {
45  // this is only called if prepareUpdate returns a payload. That payload is passed
46  // into here as updatePayload.
47  instance.queueDraw();
48}
49
50function prepareUpdate(
51  instance,
52  type,
53  oldProps,
54  newProps,
55  rootContainerInstance,
56  hostContext,
57) {
58  const {args, ...props} = newProps;
59
60  instance.args = args;
61  instance.props = props;
62  // instance.context = hostContext;
63
64  // if something is returned here then commitUpdate will be called for this instance.
65  // If nothing if returned then it will not be called
66  return {...hostContext};
67}
68
69const Renderer = Reconciler({
70  now,
71  supportsMutation: true,
72  isPrimaryRenderer: false,
73  createInstance,
74  removeChild,
75  appendChild,
76  appendInitialChild,
77  appendChildToContainer,
78  removeChildFromContainer: removeChild,
79  schedulePassiveEffects,
80  cancelPassiveEffects,
81  commitUpdate,
82  prepareUpdate,
83  insertBefore,
84
85  getPublicRootInstance: () => {},
86  getPublicInstance: instance => instance,
87  getRootHostContext: rootContainerInstance => [], // Context to pass down from root
88  getChildHostContext: () => [],
89  createTextInstance: () => {},
90  finalizeInitialChildren: (instance, type, props, rootContainerInstance) =>
91    false,
92  shouldDeprioritizeSubtree: (type, props) => false,
93  prepareForCommit: rootContainerInstance => {},
94  resetAfterCommit: () => {},
95  shouldSetTextContent: props => false,
96});
97
98export function render(el, container) {
99  let root = roots.get(container);
100  if (!root) {
101    root = Renderer.createContainer(container);
102    roots.set(container, root);
103  }
104  Renderer.updateContainer(el, root, null, undefined);
105  return Renderer.getPublicRootInstance(root);
106}
107
108export default {};
109
Full Screen

host.js

Source: host.js Github

copy
1import Reconciler from 'react-reconciler';
2
3let UNDEFINED;
4
5import {
6  unstable_scheduleCallback as schedulePassiveEffects,
7  unstable_cancelCallback as cancelPassiveEffects,
8  unstable_now as now
9} from 'scheduler';
10import propsEqual from './props-equal';
11import * as N from '@pptx-renderer/primitives';
12
13const emptyObject = {};
14
15const HostConfig = {
16  schedulePassiveEffects,
17
18  cancelPassiveEffects,
19
20  supportsMutation: true,
21
22  isPrimaryRenderer: false,
23
24  warnsIfNotActing: false,
25
26  now,
27
28  useSyncScheduling: true,
29
30  appendInitialChild(parentInstance, child) {
31    parentInstance.children.push(child);
32  },
33
34  createInstance(type, { children, ...props }) {
35    return {
36      type,
37      props: props || {},
38      style:{},
39      children: []
40    };
41  },
42
43  createTextInstance(text /* rootContainerInstance*/) {
44    return { type: N.TextInstance, value: text };
45  },
46
47  finalizeInitialChildren(/* element, type, props*/) {
48    return false;
49  },
50
51  getPublicInstance(instance) {
52    return instance;
53  },
54
55  prepareForCommit() {
56    // Noop
57  },
58
59  clearContainer() {
60    // Noop
61  },
62
63  prepareUpdate(element, type, oldProps, newProps) {
64    return !propsEqual(oldProps, newProps);
65  },
66
67  resetAfterCommit(/* params*/) {
68    // Noop
69  },
70
71  resetTextContent(/* element*/) {
72    // Noop
73  },
74
75  getRootHostContext() {
76    return emptyObject;
77  },
78
79  getChildHostContext() {
80    return emptyObject;
81  },
82
83  shouldSetTextContent(/* type, props*/) {
84    return false;
85  },
86
87  appendChild(parentInstance, child) {
88    parentInstance.children.push(child);
89  },
90
91  appendChildToContainer(parentInstance, child) {
92    if (parentInstance.type === 'ROOT') {
93      parentInstance.document = child;
94    } else {
95      parentInstance.children.push(child);
96    }
97  },
98
99  insertBefore(parentInstance, child, beforeChild) {
100    const index = parentInstance.children?.indexOf(beforeChild);
101
102    if (index === UNDEFINED) {
103      return;
104    }
105
106    if (index !== -1 && child) {
107      parentInstance.children.splice(index, 0, child);
108    }
109  },
110
111  removeChild(parentInstance, child) {
112    const index = parentInstance.children?.indexOf(child);
113
114    if (index === UNDEFINED) {
115      return;
116    }
117
118    if (index !== -1) {
119      parentInstance.children.splice(index, 1);
120    }
121  },
122
123  removeChildFromContainer(parentInstance, child) {
124    const index = parentInstance.children?.indexOf(child);
125
126    if (index === UNDEFINED) {
127      return;
128    }
129
130    if (index !== -1) {
131      parentInstance.children.splice(index, 1);
132    }
133  },
134
135  commitTextUpdate(textInstance, oldText, newText) {
136    textInstance.value = newText;
137  },
138
139  commitUpdate(instance, updatePayload, type, oldProps, newProps) {
140    instance.props = newProps;
141  }
142};
143
144export const renderer = new Reconciler(HostConfig);
145
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)