MCPcopy
hub / github.com/facebook/react / warnForMissingKey

Function warnForMissingKey

packages/react-server/src/ReactFizzServer.js:3665–3757  ·  view source on GitHub ↗
(request: Request, task: Task, child: mixed)

Source from the content-addressed store, hash-verified

3663}
3664
3665function warnForMissingKey(request: Request, task: Task, child: mixed): void {
3666 if (__DEV__) {
3667 if (
3668 child === null ||
3669 typeof child !== 'object' ||
3670 (child.$$typeof !== REACT_ELEMENT_TYPE &&
3671 child.$$typeof !== REACT_PORTAL_TYPE)
3672 ) {
3673 return;
3674 }
3675
3676 if (
3677 !child._store ||
3678 ((child._store.validated || child.key != null) &&
3679 child._store.validated !== 2)
3680 ) {
3681 return;
3682 }
3683
3684 if (typeof child._store !== 'object') {
3685 throw new Error(
3686 'React Component in warnForMissingKey should have a _store. ' +
3687 'This error is likely caused by a bug in React. Please file an issue.',
3688 );
3689 }
3690
3691 // $FlowFixMe[cannot-write] unable to narrow type from mixed to writable object
3692 child._store.validated = 1;
3693
3694 let didWarnForKey = request.didWarnForKey;
3695 if (didWarnForKey == null) {
3696 didWarnForKey = request.didWarnForKey = new WeakSet();
3697 }
3698 const parentStackFrame = task.componentStack;
3699 if (parentStackFrame === null || didWarnForKey.has(parentStackFrame)) {
3700 // We already warned for other children in this parent.
3701 return;
3702 }
3703 didWarnForKey.add(parentStackFrame);
3704
3705 const componentName = getComponentNameFromType(child.type);
3706 const childOwner = child._owner;
3707 const parentOwner = parentStackFrame.owner;
3708
3709 let currentComponentErrorInfo = '';
3710 if (parentOwner && typeof parentOwner.type !== 'undefined') {
3711 const name = getComponentNameFromType(parentOwner.type);
3712 if (name) {
3713 currentComponentErrorInfo =
3714 '\n\nCheck the render method of `' + name + '`.';
3715 }
3716 }
3717 if (!currentComponentErrorInfo) {
3718 if (componentName) {
3719 currentComponentErrorInfo = `\n\nCheck the top-level render call using <${componentName}>.`;
3720 }
3721 }
3722

Callers 2

renderSuspenseListRowsFunction · 0.70
renderChildrenArrayFunction · 0.70

Calls 5

getComponentNameFromTypeFunction · 0.85
addMethod · 0.80
hasMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected