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

ReactDOMSelect.js

Source: ReactDOMSelect.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 */
9
10// TODO: direct imports like some-package/src/* are bad. Fix me.
11import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
12
13import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
14import {getToStringValue, toString} from './ToStringValue';
15
16let didWarnValueDefaultValue;
17
18
19
20type SelectWithWrapperState = HTMLSelectElement & {
21  _wrapperState: {wasMultiple: boolean},
22};
23
24function getDeclarationErrorAddendum() {
25  const ownerName = getCurrentFiberOwnerNameInDevOrNull();
26  if (ownerName) {
27    return '\n\nCheck the render method of `' + ownerName + '`.';
28  }
29  return '';
30}
31
32const valuePropNames = ['value', 'defaultValue'];
33
34function updateOptions(
35  node: HTMLSelectElement,
36  multiple: boolean,
37  propValue: any,
38  setDefaultSelected: boolean,
39) {
40  type IndexableHTMLOptionsCollection = HTMLOptionsCollection & {
41    [key: number]: HTMLOptionElement,
42    ...,
43  };
44  const options: IndexableHTMLOptionsCollection = node.options;
45
46  if (multiple) {
47    const selectedValues = (propValue: Array<string>);
48    const selectedValue = {};
49    for (let i = 0; i < selectedValues.length; i++) {
50      // Prefix to avoid chaos with special keys.
51      selectedValue['$' + selectedValues[i]] = true;
52    }
53    for (let i = 0; i < options.length; i++) {
54      const selected = selectedValue.hasOwnProperty('$' + options[i].value);
55      if (options[i].selected !== selected) {
56        options[i].selected = selected;
57      }
58      if (selected && setDefaultSelected) {
59        options[i].defaultSelected = true;
60      }
61    }
62  } else {
63    // Do not set `select.value` as exact behavior isn't consistent across all
64    // browsers for all cases.
65    const selectedValue = toString(getToStringValue((propValue: any)));
66    let defaultSelected = null;
67    for (let i = 0; i < options.length; i++) {
68      if (options[i].value === selectedValue) {
69        options[i].selected = true;
70        if (setDefaultSelected) {
71          options[i].defaultSelected = true;
72        }
73        return;
74      }
75      if (defaultSelected === null && !options[i].disabled) {
76        defaultSelected = options[i];
77      }
78    }
79    if (defaultSelected !== null) {
80      defaultSelected.selected = true;
81    }
82  }
83}
84
85/**
86 * Implements a <select> host component that allows optionally setting the
87 * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
88 * stringable. If `multiple` is true, the prop must be an array of stringables.
89 *
90 * If `value` is not supplied (or null/undefined), user actions that change the
91 * selected option will trigger updates to the rendered options.
92 *
93 * If it is supplied (and not null/undefined), the rendered options will not
94 * update in response to user actions. Instead, the `value` prop must change in
95 * order for the rendered options to update.
96 *
97 * If `defaultValue` is provided, any options with the supplied values will be
98 * selected.
99 */
100
101export function getHostProps(element: Element, props: Object) {
102  return Object.assign({}, props, {
103    value: undefined,
104  });
105}
106
107export function initWrapperState(element: Element, props: Object) {
108  const node = ((element: any): SelectWithWrapperState);
109
110
111  node._wrapperState = {
112    wasMultiple: !!props.multiple,
113  };
114
115
116}
117
118export function postMountWrapper(element: Element, props: Object) {
119  const node = ((element: any): SelectWithWrapperState);
120  node.multiple = !!props.multiple;
121  const value = props.value;
122  if (value != null) {
123    updateOptions(node, !!props.multiple, value, false);
124  } else if (props.defaultValue != null) {
125    updateOptions(node, !!props.multiple, props.defaultValue, true);
126  }
127}
128
129export function postUpdateWrapper(element: Element, props: Object) {
130  const node = ((element: any): SelectWithWrapperState);
131  const wasMultiple = node._wrapperState.wasMultiple;
132  node._wrapperState.wasMultiple = !!props.multiple;
133
134  const value = props.value;
135  if (value != null) {
136    updateOptions(node, !!props.multiple, value, false);
137  } else if (wasMultiple !== !!props.multiple) {
138    // For simplicity, reapply `defaultValue` if `multiple` is toggled.
139    if (props.defaultValue != null) {
140      updateOptions(node, !!props.multiple, props.defaultValue, true);
141    } else {
142      // Revert the select back to its default unselected state.
143      updateOptions(node, !!props.multiple, props.multiple ? [] : '', false);
144    }
145  }
146}
147
148export function restoreControlledState(element: Element, props: Object) {
149  const node = ((element: any): SelectWithWrapperState);
150  const value = props.value;
151
152  if (value != null) {
153    updateOptions(node, !!props.multiple, value, false);
154  }
155}
156
Full Screen

ReactCurrentFiber.js

Source: ReactCurrentFiber.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 */
9
10import type {Fiber} from './ReactInternalTypes';
11
12
13import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
14
15
16
17export let current: Fiber | null = null;
18export let isRendering: boolean = false;
19
20export function getCurrentFiberOwnerNameInDevOrNull(): string | null {
21
22  return null;
23}
24
25function getCurrentFiberStackInDev(): string {
26
27  return '';
28}
29
30export function resetCurrentFiber() {
31
32}
33
34export function setCurrentFiber(fiber: Fiber) {
35
36}
37
38export function setIsRendering(rendering: boolean) {
39
40}
41
42export function getIsRendering() {
43
44}
45
Full Screen

ReactDOMTextarea.js

Source: ReactDOMTextarea.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 */
9
10import invariant from 'shared/invariant';
11import warning from 'shared/warning';
12
13import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
14import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
15import {getToStringValue, toString} from './ToStringValue';
16import type {ToStringValue} from './ToStringValue';
17
18let didWarnValDefaultVal = false;
19
20type TextAreaWithWrapperState = HTMLTextAreaElement & {
21  _wrapperState: {
22    initialValue: ToStringValue,
23  },
24};
25
26/**
27 * Implements a <textarea> host component that allows setting `value`, and
28 * `defaultValue`. This differs from the traditional DOM API because value is
29 * usually set as PCDATA children.
30 *
31 * If `value` is not supplied (or null/undefined), user actions that affect the
32 * value will trigger updates to the element.
33 *
34 * If `value` is supplied (and not null/undefined), the rendered element will
35 * not trigger updates to the element. Instead, the `value` prop must change in
36 * order for the rendered element to be updated.
37 *
38 * The rendered element will be initialized with an empty value, the prop
39 * `defaultValue` if specified, or the children content (deprecated).
40 */
41
42export function getHostProps(element: Element, props: Object) {
43  const node = ((element: any): TextAreaWithWrapperState);
44  invariant(
45    props.dangerouslySetInnerHTML == null,
46    '`dangerouslySetInnerHTML` does not make sense on <textarea>.',
47  );
48
49  // Always set children to the same thing. In IE9, the selection range will
50  // get reset if `textContent` is mutated.  We could add a check in setTextContent
51  // to only set the value if/when the value differs from the node value (which would
52  // completely solve this IE9 bug), but Sebastian+Sophie seemed to like this
53  // solution. The value can be a boolean or object so that's why it's forced
54  // to be a string.
55  const hostProps = {
56    ...props,
57    value: undefined,
58    defaultValue: undefined,
59    children: toString(node._wrapperState.initialValue),
60  };
61
62  return hostProps;
63}
64
65export function initWrapperState(element: Element, props: Object) {
66  const node = ((element: any): TextAreaWithWrapperState);
67  if (__DEV__) {
68    ReactControlledValuePropTypes.checkPropTypes('textarea', props);
69    if (
70      props.value !== undefined &&
71      props.defaultValue !== undefined &&
72      !didWarnValDefaultVal
73    ) {
74      warning(
75        false,
76        '%s contains a textarea with both value and defaultValue props. ' +
77          'Textarea elements must be either controlled or uncontrolled ' +
78          '(specify either the value prop, or the defaultValue prop, but not ' +
79          'both). Decide between using a controlled or uncontrolled textarea ' +
80          'and remove one of these props. More info: ' +
81          'https://fb.me/react-controlled-components',
82        getCurrentFiberOwnerNameInDevOrNull() || 'A component',
83      );
84      didWarnValDefaultVal = true;
85    }
86  }
87
88  let initialValue = props.value;
89
90  // Only bother fetching default value if we're going to use it
91  if (initialValue == null) {
92    let defaultValue = props.defaultValue;
93    // TODO (yungsters): Remove support for children content in <textarea>.
94    let children = props.children;
95    if (children != null) {
96      if (__DEV__) {
97        warning(
98          false,
99          'Use the `defaultValue` or `value` props instead of setting ' +
100            'children on <textarea>.',
101        );
102      }
103      invariant(
104        defaultValue == null,
105        'If you supply `defaultValue` on a <textarea>, do not pass children.',
106      );
107      if (Array.isArray(children)) {
108        invariant(
109          children.length <= 1,
110          '<textarea> can only have at most one child.',
111        );
112        children = children[0];
113      }
114
115      defaultValue = children;
116    }
117    if (defaultValue == null) {
118      defaultValue = '';
119    }
120    initialValue = defaultValue;
121  }
122
123  node._wrapperState = {
124    initialValue: getToStringValue(initialValue),
125  };
126}
127
128export function updateWrapper(element: Element, props: Object) {
129  const node = ((element: any): TextAreaWithWrapperState);
130  const value = getToStringValue(props.value);
131  const defaultValue = getToStringValue(props.defaultValue);
132  if (value != null) {
133    // Cast `value` to a string to ensure the value is set correctly. While
134    // browsers typically do this as necessary, jsdom doesn't.
135    const newValue = toString(value);
136    // To avoid side effects (such as losing text selection), only set value if changed
137    if (newValue !== node.value) {
138      node.value = newValue;
139    }
140    if (props.defaultValue == null && node.defaultValue !== newValue) {
141      node.defaultValue = newValue;
142    }
143  }
144  if (defaultValue != null) {
145    node.defaultValue = toString(defaultValue);
146  }
147}
148
149export function postMountWrapper(element: Element, props: Object) {
150  const node = ((element: any): TextAreaWithWrapperState);
151  // This is in postMount because we need access to the DOM node, which is not
152  // available until after the component has mounted.
153  const textContent = node.textContent;
154
155  // Only set node.value if textContent is equal to the expected
156  // initial value. In IE10/IE11 there is a bug where the placeholder attribute
157  // will populate textContent as well.
158  // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
159  if (textContent === node._wrapperState.initialValue) {
160    node.value = textContent;
161  }
162}
163
164export function restoreControlledState(element: Element, props: Object) {
165  // DOM component is still mounted; update
166  updateWrapper(element, props);
167}
168
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)