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

  1. Declare the missing key in static childContextTypes = {key: PropTypes.string.isRequired}
  2. Prefer the modern createContext()/useContext API over legacy child context
  3. 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

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


AI-assisted analysis of facebook/react@eafeac097b (2026-08-21). Data as JSON: /api/errors/c1404a706e15abd4. Report an issue: GitHub.