{"record":{"id":"1c4996f8af1d1ac4","repo":"facebook/react","slug":"server-functions-cannot-be-called-during-initial-r-1c4996","errorCode":null,"errorMessage":"Server Functions cannot be called during initial render. This would create a fetch waterfall. Try to use a Server Component to pass data to Client Components instead.","messagePattern":"Server Functions cannot be called during initial render\\. This would create a fetch waterfall\\. Try to use a Server Component to pass data to Client Components instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-turbopack/src/client/ReactFlightDOMClientEdge.js","lineNumber":55,"sourceCode":"  processBinaryChunk,\n  close,\n} from 'react-client/src/ReactFlightClient';\n\nimport {\n  processReply,\n  createServerReference as createServerReferenceImpl,\n} from 'react-client/src/ReactFlightReplyClient';\n\nexport {registerServerReference} from 'react-client/src/ReactFlightReplyClient';\n\nimport type {TemporaryReferenceSet} from 'react-client/src/ReactFlightTemporaryReferences';\n\nexport {createTemporaryReferenceSet} from 'react-client/src/ReactFlightTemporaryReferences';\n\nexport type {TemporaryReferenceSet};\n\nfunction noServerCall() {\n  throw new Error(\n    'Server Functions cannot be called during initial render. ' +\n      'This would create a fetch waterfall. Try to use a Server Component ' +\n      'to pass data to Client Components instead.',\n  );\n}\n\nexport function createServerReference<A: Iterable<any>, T>(\n  id: any,\n  callServer: any,\n): (...A) => Promise<T> {\n  return createServerReferenceImpl(id, noServerCall);\n}\n\ntype EncodeFormActionCallback = <A>(\n  id: any,\n  args: Promise<A>,\n) => ReactCustomFormAction;\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-turbopack/src/client/ReactFlightDOMClientEdge.js#L37-L73","documentation":"The Edge SSR client runtime wires noServerCall in as callServer for every server reference: during edge streaming/prerender there is no request context to loop back to the server, so invoking a server function during render throws and directs you to fetch initial data via server components instead.","triggerScenarios":"Invoking a server action during render on the edge runtime — in a component body, top-level module scope executed during SSR, or a shared hook that fires the action on mount without an effect guard.","commonSituations":"Client hooks shared with SSR that call actions eagerly; prerendering pages that trigger actions during render; porting data fetching to actions instead of server components.","solutions":["Call server functions only from event handlers or inside useEffect","Fetch initial data in a server component and pass it down as props","When code must run on both sides, gate the call so it never executes during SSR"],"exampleFix":"// before\nexport default function Page() {\n  getUser(); // called during render -> Error on edge SSR\n}\n\n// after\nexport default function Page() {\n  useEffect(() => {\n    getUser();\n  }, []);\n  return <Profile />;\n}","handlingStrategy":"validation","validationCode":"function useServerActionWhenInteractive(action) {\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return useCallback((...args) => {\n    if (!mounted) {\n      throw new Error('Server functions cannot run during render/SSR');\n    }\n    return action(...args);\n  }, [action, mounted]);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only call server functions from event handlers or useEffect","Fetch initial data in server components and pass as props","Audit shared hooks for action calls that run during SSR"],"tags":["server-actions","turbopack","edge-runtime","ssr","render-phase"],"backgroundTag":"server-action-during-render","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}