{"record":{"id":"0755e2e2c4556564","repo":"facebook/react","slug":"componentwillmount-has-been-renamed-and-is-not-re-0755e2","errorCode":null,"errorMessage":"componentWillMount has been renamed, and is not recommended for use. See https://react.dev/link/unsafe-component-lifecycles for details.\n\n* Move code from componentWillMount to componentDidMount (preferred in most cases) or the constructor.\n\nPlease update the following components: %s","messagePattern":"componentWillMount has been renamed, and is not recommended for use\\. See https://react\\.dev/link/unsafe-component-lifecycles for details\\.\n\n\\* Move code from componentWillMount to componentDidMount \\(preferred in most cases\\) or the constructor\\.\n\nPlease update the following components: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/react-server/src/ReactFizzClassComponent.js","lineNumber":553,"sourceCode":"      console.error(\n        '%s.getChildContext(): childContextTypes must be defined in order to ' +\n          'use getChildContext().',\n        name,\n      );\n    }\n  }\n}\n\nfunction callComponentWillMount(type: any, instance: any) {\n  const oldState = instance.state;\n\n  if (typeof instance.componentWillMount === 'function') {\n    if (__DEV__) {\n      if (instance.componentWillMount.__suppressDeprecationWarning !== true) {\n        const componentName = getComponentNameFromType(type) || 'Unknown';\n\n        if (!didWarnAboutDeprecatedWillMount[componentName]) {\n          console.warn(\n            // keep this warning in sync with ReactStrictModeWarning.js\n            'componentWillMount has been renamed, and is not recommended for use. ' +\n              'See https://react.dev/link/unsafe-component-lifecycles for details.\\n\\n' +\n              '* Move code from componentWillMount to componentDidMount (preferred in most cases) ' +\n              'or the constructor.\\n' +\n              '\\nPlease update the following components: %s',\n            componentName,\n          );\n          didWarnAboutDeprecatedWillMount[componentName] = true;\n        }\n      }\n    }\n\n    instance.componentWillMount();\n  }\n  if (typeof instance.UNSAFE_componentWillMount === 'function') {\n    instance.UNSAFE_componentWillMount();\n  }","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server/src/ReactFizzClassComponent.js#L535-L571","documentation":"The Fizz SSR renderer (react-server) still invokes componentWillMount during mountClassInstance via callComponentWillMount (ReactFizzClassComponent.js:693) for pre-16.3 compatibility. In dev it warns once per component name unless the method carries __suppressDeprecationWarning. The warning is stronger here than on the client: SSR may render and discard output (suspense aborts, backpressure), so side effects in componentWillMount can execute for markup that is never sent.","triggerScenarios":"renderToPipeableStream/renderToReadableStream, in a dev build, renders a class component whose prototype defines componentWillMount as a function.","commonSituations":"Legacy class trees being server-rendered for the first time; adding SSR to an old app during a framework migration; class components shared between client and RSC-adjacent server rendering.","solutions":["Move client-side effects to componentDidMount (it does not run during SSR) and derive initial state in the constructor","If the logic must run on the server, do it in the constructor or before render - not in a lifecycle React may call twice","Run `npx react-codemod rename-unsafe-lifecycles` for components you cannot refactor yet"],"exampleFix":"// before\nclass Example extends React.Component {\n  componentWillMount() { log('rendering on server'); this.setState({x: 1}); }\n}\n\n// after\nclass Example extends React.Component {\n  constructor(props) { super(props); this.state = {x: 1}; }\n  componentDidMount() { log('mounted on client'); }\n}","handlingStrategy":"validation","validationCode":"// reject class trees that SSR cannot render safely\nfunction isSsrSafeClass(ctor) {\n  const m = ctor && ctor.prototype && ctor.prototype.componentWillMount;\n  return !(typeof m === 'function' && m.__suppressDeprecationWarning !== true);\n}","typeGuard":"function definesComponentWillMount(ctor) {\n  const m = ctor && ctor.prototype && ctor.prototype.componentWillMount;\n  return typeof m === 'function' && m.__suppressDeprecationWarning !== true;\n}","tryCatchPattern":null,"preventionTips":["Keep componentWillMount free of side effects anywhere - SSR may run it for discarded output","Initialize state in the constructor and do client work in componentDidMount","Run the SSR dev server with the same class components as production to see the warnings"],"tags":["legacy-lifecycles","component-will-mount","ssr","class-components","deprecation","dev-only"],"backgroundTag":"unsafe-component-lifecycles","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}