Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!(reactIs.isForwardRef(element) || typeof element.type === 'function' || reactIs.isMemo(element.type))) {
{
throw ReactError(Error("ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `" + (Array.isArray(element.type) ? 'array' : element.type === null ? 'null' : typeof element.type) + "`."));
}
}
})();
if (this._rendering) {
return;
}
if (this._element != null && this._element.type !== element.type) {
this._reset();
}
var elementType = reactIs.isMemo(element.type) ? element.type.type : element.type;
var previousElement = this._element;
this._rendering = true;
this._element = element;
this._context = getMaskedContext(elementType.contextTypes, context); // Inner memo component props aren't currently validated in createElement.
if (reactIs.isMemo(element.type) && elementType.propTypes) {
currentlyValidatingElement = element;
checkPropTypes(elementType.propTypes, element.props, 'prop', getComponentName(elementType), getStackAddendum);
}
if (this._instance) {
this._updateClassComponent(elementType, element, this._context);
} else {
if (shouldConstruct(elementType)) {
this._instance = new elementType(element.props, this._context, this._updater);
'components, but the provided element type was `%s`.',
Array.isArray(element.type)
? 'array'
: element.type === null
? 'null'
: typeof element.type,
);
if (this._rendering) {
return;
}
if (this._element != null && this._element.type !== element.type) {
this._reset();
}
const elementType = isMemo(element) ? element.type.type : element.type;
const previousElement = this._element;
this._rendering = true;
this._element = element;
this._context = getMaskedContext(elementType.contextTypes, context);
// Inner memo component props aren't currently validated in createElement.
if (isMemo(element) && elementType.propTypes) {
currentlyValidatingElement = element;
checkPropTypes(
elementType.propTypes,
element.props,
'prop',
getComponentName(elementType),
getStackAddendum,
);
currentlyValidatingElement = element;
checkPropTypes(
elementType.contextTypes,
this._context,
'context',
getName(elementType, this._instance),
getStackAddendum,
);
currentlyValidatingElement = null;
}
this._mountClassComponent(elementType, element, this._context);
} else {
let shouldRender = true;
if (isMemo(element) && previousElement !== null) {
// This is a Memo component that is being re-rendered.
const compare = element.type.compare || shallowEqual;
if (compare(previousElement.props, element.props)) {
shouldRender = false;
}
}
if (shouldRender) {
const prevDispatcher = ReactCurrentDispatcher.current;
ReactCurrentDispatcher.current = this._dispatcher;
try {
// elementType could still be a ForwardRef if it was
// nested inside Memo.
if (elementType.$$typeof === ForwardRef) {
invariant(
typeof elementType.render === 'function',
'forwardRef requires a render function but was given %s.',
if (this._rendering) {
return;
}
if (this._element != null && this._element.type !== element.type) {
this._reset();
}
const elementType = isMemo(element) ? element.type.type : element.type;
const previousElement = this._element;
this._rendering = true;
this._element = element;
this._context = getMaskedContext(elementType.contextTypes, context);
// Inner memo component props aren't currently validated in createElement.
if (isMemo(element) && elementType.propTypes) {
currentlyValidatingElement = element;
checkPropTypes(
elementType.propTypes,
element.props,
'prop',
getComponentName(elementType),
getStackAddendum,
);
}
if (this._instance) {
this._updateClassComponent(elementType, element, this._context);
} else {
if (shouldConstruct(elementType)) {
this._instance = new elementType(
element.props,
currentlyValidatingElement = element;
checkPropTypes(
elementType.contextTypes,
this._context,
'context',
getName(elementType, this._instance),
getStackAddendum,
);
currentlyValidatingElement = null;
}
this._mountClassComponent(elementType, element, this._context);
} else {
let shouldRender = true;
if (isMemo(element) && previousElement !== null) {
// This is a Memo component that is being re-rendered.
const compare = element.type.compare || shallowEqual;
if (compare(previousElement.props, element.props)) {
shouldRender = false;
}
}
if (shouldRender) {
const prevDispatcher = ReactCurrentDispatcher.current;
ReactCurrentDispatcher.current = this._dispatcher;
try {
// elementType could still be a ForwardRef if it was
// nested inside Memo.
if (elementType.$$typeof === ForwardRef) {
invariant(
typeof elementType.render === 'function',
'forwardRef requires a render function but was given %s.',
function mergeOptions(Widget) {
// cache return value as property of widget for proper react reconciliation
if (!Widget.MergedWidget) {
const defaultOptions =
(Widget.defaultProps && Widget.defaultProps.options) || {};
Widget.MergedWidget = ({ options = {}, ...props }) => (
);
}
return Widget.MergedWidget;
}
if (
typeof widget === "function" ||
ReactIs.isForwardRef(React.createElement(widget)) ||
ReactIs.isMemo(widget)
) {
return mergeOptions(widget);
}
if (typeof widget !== "string") {
throw new Error(`Unsupported widget definition: ${typeof widget}`);
}
if (registeredWidgets.hasOwnProperty(widget)) {
const registeredWidget = registeredWidgets[widget];
return getWidget(schema, registeredWidget, registeredWidgets);
}
if (!widgetMap.hasOwnProperty(type)) {
throw new Error(`No widget for type "${type}"`);
}
function getStatics(component) {
// React v16.11 and below
if (isMemo(component)) {
return MEMO_STATICS;
}
// React v16.12 and above
return TYPE_STATICS[component['$$typeof']] || REACT_STATICS;
}
function getDisplayName(element) {
if (element == null) {
return '#empty';
} else if (typeof element === 'string' || typeof element === 'number') {
return '#text';
} else if (typeof element.type === 'string') {
return element.type;
} else {
const elementType = isMemo(element) ? element.type.type : element.type;
return elementType.displayName || elementType.name || 'Unknown';
}
}
function getDisplayName(element) {
if (element == null) {
return '#empty';
} else if (typeof element === 'string' || typeof element === 'number') {
return '#text';
} else if (typeof element.type === 'string') {
return element.type;
} else {
var elementType = reactIs.isMemo(element.type) ? element.type.type : element.type;
return elementType.displayName || elementType.name || 'Unknown';
}
}