{"record":{"id":"a6bea27902bf7614","repo":"mobxjs/mobx","slug":"mobx-react-it-seems-that-a-re-rendering-of-a-rea","errorCode":null,"errorMessage":"[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.","messagePattern":"\\[mobx-react\\] It seems that a re-rendering of a React component is triggered while in static \\(server-side\\) mode\\. Please make sure components are rendered only once server-side\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mobx-react/src/observerClass.ts","lineNumber":239,"sourceCode":"            // This happens when component is abandoned after render - our reaction is already created and reacts to changes.\n            // `componenDidMount` runs synchronously after `render`, so unlike functional component, there is no delay during which the reaction could be invalidated.\n            // However `componentDidMount` runs AFTER it's descendants' `componentDidMount`, which CAN invalidate the reaction, see #3730. Therefore remember and forceUpdate on mount.\n            admin.reactionInvalidatedBeforeMount = true\n            return\n        }\n\n        try {\n            admin.forceUpdate?.()\n        } catch (error) {\n            admin.reaction?.dispose()\n            admin.reaction = null\n        }\n    })\n}\n\nfunction observerSCU(nextProps: ClassAttributes<any>, nextState: any): boolean {\n    if (isUsingStaticRendering()) {\n        console.warn(\n            \"[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.\"\n        )\n    }\n    // update on any state changes (as is the default)\n    if (this.state !== nextState) {\n        return true\n    }\n    // update if props are shallowly not equal, inspired by PureRenderMixin\n    // we could return just 'false' here, and avoid the `skipRender` checks etc\n    // however, it is nicer if lifecycle events are triggered like usually,\n    // so we return true here if props are shallowly modified.\n    return !shallowEqual(this.props, nextProps)\n}\n\nfunction createObservablePropDescriptor(key: \"props\" | \"state\" | \"context\") {\n    return {\n        configurable: true,\n        enumerable: true,","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/mobxjs/mobx/blob/01211a698b64ea94de8e5f276ff8235fcf8ddf96/packages/mobx-react/src/observerClass.ts#L221-L257","documentation":"In static rendering mode (used for server-side rendering via useStaticRendering(true) or StaticRenderer), observer components should render exactly once with no subsequent updates. The class component's shouldComponentUpdate (observerSCU) detects a re-render attempt while static rendering is active and logs this warning — state/props updates after the initial SSR render indicate a lifecycle misuse. It is a console.warn, not a throw.","triggerScenarios":"Calling setState, receiving new props, or otherwise triggering shouldComponentUpdate on an observer class component while isUsingStaticRendering() is true (server render or static-render test setup).","commonSituations":"Rendering components during SSR where parent code calls setState in render or lifecycle; running components under mobx's static rendering in tests but mutating state mid-render; accidental client-side use of useStaticRendering(true).","solutions":["Ensure components are rendered only once server-side; remove setState calls during SSR","Guard state updates with typeof window checks or move updates to componentDidMount (client-only)","Call useStaticRendering(false) (or use enableStaticRendering(false)) for client bundles","In tests, reset static rendering mode between suites (resetMobxReactTestState)"],"exampleFix":"// before\ncomponentDidMount() { /* ok */ }\nstatic rendering + this.setState(...) during render\n// after\n// only update on the client, after mount:\ncomponentDidMount() { if (!isUsingStaticRendering()) this.setState(...) }","handlingStrategy":"validation","validationCode":"// before mutating state, check static rendering\nimport { isUsingStaticRendering } from 'mobx-react'\nif (!isUsingStaticRendering()) {\n    this.setState({ ... })\n}","typeGuard":"function canUpdateOnClient(): boolean {\n    return typeof window !== 'undefined' && !require('mobx-react').isUsingStaticRendering()\n}","tryCatchPattern":"null","preventionTips":["Never call setState during server-side rendering","Call useStaticRendering/enableStaticRendering(true) only in server entry points","Reset static rendering flags in test teardown (resetMobxReactTestState)","Move post-mount updates to componentDidMount/Effect which only run client-side"],"tags":["mobx-react","ssr","static-rendering","console-warning"],"backgroundTag":"static-rendering-rerender","analyzedSha":"01211a698b64ea94de8e5f276ff8235fcf8ddf96","analyzedAt":"2026-08-28T22:10:08.831Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}