facebook/react · error · Error
108
108
Error message
${getComponentNameFromType(type) || 'Unknown'}.getChildContext(): key "${contextKey}" is not defined in childContextTypes. What it means
Legacy (pre-16.3) class context requires every key returned by instance.getChildContext() to be declared in the component's static childContextTypes. During SSR, Fizz iterates the returned object and throws error code 108 for the first key missing from childContextTypes.
Source
Thrown at packages/react-server/src/ReactFizzLegacyContext.js:74
if (!warnedAboutMissingGetChildContext[componentName]) {
warnedAboutMissingGetChildContext[componentName] = true;
console.error(
'%s.childContextTypes is specified but there is no getChildContext() method ' +
'on the instance. You can either define getChildContext() on %s or remove ' +
'childContextTypes from it.',
componentName,
componentName,
);
}
}
return parentContext;
}
const childContext = instance.getChildContext();
for (const contextKey in childContext) {
if (!(contextKey in childContextTypes)) {
throw new Error(
`${
getComponentNameFromType(type) || 'Unknown'
}.getChildContext(): key "${contextKey}" is not defined in childContextTypes.`,
);
}
}
return {...parentContext, ...childContext};
}
}
View on GitHub (pinned to eafeac097b)
Solutions
- Declare the missing key in static childContextTypes = {key: PropTypes.string.isRequired}
- Prefer the modern createContext()/useContext API over legacy child context
- If the key is obsolete, stop returning it from getChildContext()
Example fix
// before
class Provider extends React.Component {
getChildContext() {
return {theme: 'dark', locale: 'en'}; // locale missing below -> throws
}
}
Provider.childContextTypes = {theme: PropTypes.string};
// after
Provider.childContextTypes = {
theme: PropTypes.string,
locale: PropTypes.string,
}; Defensive patterns
Strategy: validation
Validate before calling
// dev-only check around legacy providers
const ctx = instance.getChildContext();
for (const key of Object.keys(ctx)) {
if (!(key in Component.childContextTypes)) {
console.error(`getChildContext key '${key}' is missing from childContextTypes`);
}
} Prevention
- Declare every key in childContextTypes exactly as returned by getChildContext
- Migrate legacy providers and consumers to createContext/useContext
- Add a dev-time assertion that walks getChildContext output before shipping
When it happens
Trigger: A class component's getChildContext() returns a key that the static childContextTypes declaration does not list; adding or renaming context keys without updating the static declaration.
Common situations: Maintaining pre-16.3 class-based context code; partial migrations where childContextTypes was trimmed; copy-pasting legacy provider patterns.
Related errors
- ${getComponentNameFromFiber(fiber) || 'Unknown'}.getChildCon
- componentWillMount has been renamed, and is not recommended
- File/Blob fields are not yet supported in progressive forms.
- Can only set one of `children` or `props.dangerouslySetInner
- `props.dangerouslySetInnerHTML` must be in the form `{__html
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/c1404a706e15abd4.
Report an issue: GitHub.