{"record":{"id":"4bebf29e79699117","repo":"facebook/react","slug":"getcomponentnamefromfiber-fiber-unknown-g","errorCode":null,"errorMessage":"${getComponentNameFromFiber(fiber) || 'Unknown'}.getChildContext(): key \"${contextKey}\" is not defined in childContextTypes.","messagePattern":"(.+?)\\.getChildContext\\(\\): key \"(.+?)\" is not defined in childContextTypes\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-reconciler/src/ReactFiberLegacyContext.js","lineNumber":201,"sourceCode":"\n        if (!warnedAboutMissingGetChildContext[componentName]) {\n          warnedAboutMissingGetChildContext[componentName] = true;\n          console.error(\n            '%s.childContextTypes is specified but there is no getChildContext() method ' +\n              'on the instance. You can either define getChildContext() on %s or remove ' +\n              'childContextTypes from it.',\n            componentName,\n            componentName,\n          );\n        }\n      }\n      return parentContext;\n    }\n\n    const childContext = instance.getChildContext();\n    for (const contextKey in childContext) {\n      if (!(contextKey in childContextTypes)) {\n        throw new Error(\n          `${\n            getComponentNameFromFiber(fiber) || 'Unknown'\n          }.getChildContext(): key \"${contextKey}\" is not defined in childContextTypes.`,\n        );\n      }\n    }\n\n    return {...parentContext, ...childContext};\n  }\n}\n\nfunction pushContextProvider(workInProgress: Fiber): boolean {\n  if (disableLegacyContext) {\n    return false;\n  } else {\n    const instance = workInProgress.stateNode;\n    // We push the context as early as possible to ensure stack integrity.\n    // If the instance does not exist yet, we will push null at first,","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-reconciler/src/ReactFiberLegacyContext.js#L183-L219","documentation":"Legacy context provider path: when a class component declares static childContextTypes and implements getChildContext(), React validates every key of the returned object against childContextTypes before merging it into the parent context. A key present in the returned child context but missing from childContextTypes throws immediately, because consumers could never read an undeclared key.","triggerScenarios":"A class component whose getChildContext() returns an object containing a key not declared in its static childContextTypes map (typo, casing difference, or a newly added key), rendered while legacy context is enabled (React 16.x line — the API is removed in newer majors).","commonSituations":"Maintaining pre-createContext class codebases; third-party libraries still on the legacy context API; copy-paste additions to getChildContext without updating childContextTypes; PropTypes typos between the two definitions.","solutions":["Add the missing key to static childContextTypes with the correct PropTypes type (e.g. theme: PropTypes.string)","Or remove the extra key from the getChildContext() return value if it is unused","Long term, migrate providers and consumers to React.createContext — the legacy API is deprecated and removed in React 17+","Keep getChildContext and childContextTypes keys in one adjacent block so they stay in sync"],"exampleFix":"// before\nclass Provider extends React.Component {\n  static childContextTypes = {theme: PropTypes.string};\n  getChildContext() {\n    return {theme: 'dark', user: this.props.user}; // 'user' not declared -> throws\n  }\n}\n\n// after\nclass Provider extends React.Component {\n  static childContextTypes = {\n    theme: PropTypes.string,\n    user: PropTypes.object, // declared\n  };\n  getChildContext() {\n    return {theme: 'dark', user: this.props.user};\n  }\n}","handlingStrategy":"validation","validationCode":"// Dev-time guard: validate getChildContext keys against childContextTypes before rendering\ndevelopment &&\n  Object.keys(new Provider().getChildContext() ?? {}).forEach((key) => {\n    if (!(key in Provider.childContextTypes)) {\n      throw new Error(`childContextTypes missing key: ${key}`);\n    }\n  });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Define childContextTypes directly adjacent to getChildContext so the two lists are updated together","Add a unit test asserting every getChildContext key exists in childContextTypes","Migrate to React.createContext — the legacy API is removed in React 17+ and this whole class of errors disappears","Watch for PropTypes typos/casing differences between the two definitions"],"tags":["react","legacy-context","class-components","child-context-types","proptypes"],"backgroundTag":"legacy-context-api","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}