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

Function warnForMissingKey

packages/react-server/src/ReactFlightServer.js:1773–1837  ·  view source on GitHub ↗
(
  request: Request,
  key: null | string,
  componentDebugInfo: ReactComponentInfo,
  debugTask: null | ConsoleTask,
)

Source from the content-addressed store, hash-verified

1771}
1772
1773function warnForMissingKey(
1774 request: Request,
1775 key: null | string,
1776 componentDebugInfo: ReactComponentInfo,
1777 debugTask: null | ConsoleTask,
1778): void {
1779 if (__DEV__) {
1780 let didWarnForKey = request.didWarnForKey;
1781 if (didWarnForKey == null) {
1782 didWarnForKey = request.didWarnForKey = new WeakSet();
1783 }
1784 const parentOwner = componentDebugInfo.owner;
1785 if (parentOwner != null) {
1786 if (didWarnForKey.has(parentOwner)) {
1787 // We already warned for other children in this parent.
1788 return;
1789 }
1790 didWarnForKey.add(parentOwner);
1791 }
1792
1793 // Call with the server component as the currently rendering component
1794 // for context.
1795 const logKeyError = () => {
1796 console.error(
1797 'Each child in a list should have a unique "key" prop.' +
1798 '%s%s See https://react.dev/link/warning-keys for more information.',
1799 '',
1800 '',
1801 );
1802 };
1803
1804 if (supportsComponentStorage) {
1805 // Run the component in an Async Context that tracks the current owner.
1806 if (debugTask) {
1807 debugTask.run(
1808 // $FlowFixMe[method-unbinding]
1809 componentStorage.run.bind(
1810 componentStorage,
1811 componentDebugInfo,
1812 callComponentInDEV,
1813 logKeyError,
1814 null,
1815 componentDebugInfo,
1816 ),
1817 );
1818 } else {
1819 componentStorage.run(
1820 componentDebugInfo,
1821 callComponentInDEV,
1822 logKeyError,
1823 null,
1824 componentDebugInfo,
1825 );
1826 }
1827 } else {
1828 if (debugTask) {
1829 debugTask.run(
1830 callComponentInDEV.bind(null, logKeyError, null, componentDebugInfo),

Callers 2

renderFunctionComponentFunction · 0.70
renderElementFunction · 0.70

Calls 3

addMethod · 0.80
runMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected