{"record":{"id":"860fca36e0204dc9","repo":"facebook/react","slug":"expected-the-root-instance-to-already-exist-when-s","errorCode":null,"errorMessage":"Expected the root instance to already exist when starting profiling","messagePattern":"Expected the root instance to already exist when starting profiling","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-devtools-shared/src/backend/fiber/renderer.js","lineNumber":7350,"sourceCode":"\n  function startProfiling(shouldRecordChangeDescriptions: boolean) {\n    if (isProfiling) {\n      return;\n    }\n\n    recordChangeDescriptions = shouldRecordChangeDescriptions;\n\n    // Capture initial values as of the time profiling starts.\n    // It's important we snapshot both the durations and the id-to-root map,\n    // since either of these may change during the profiling session\n    // (e.g. when a fiber is re-rendered or when a fiber gets removed).\n    displayNamesByRootID = new Map();\n    initialTreeBaseDurationsMap = new Map();\n\n    hook.getFiberRoots(rendererID).forEach(root => {\n      const rootInstance = rootToFiberInstanceMap.get(root);\n      if (rootInstance === undefined) {\n        throw new Error(\n          'Expected the root instance to already exist when starting profiling',\n        );\n      }\n      const rootID = rootInstance.id;\n      (displayNamesByRootID as any as DisplayNamesByRootID).set(\n        rootID,\n        getDisplayNameForRoot(root.current),\n      );\n      const initialTreeBaseDurations: Array<[number, number]> = [];\n      snapshotTreeBaseDurations(rootInstance, initialTreeBaseDurations);\n      (initialTreeBaseDurationsMap as any).set(\n        rootID,\n        initialTreeBaseDurations,\n      );\n    });\n\n    isProfiling = true;\n    profilingStartTime = getCurrentTime();","sourceCodeStart":7332,"sourceCodeEnd":7368,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-devtools-shared/src/backend/fiber/renderer.js#L7332-L7368","documentation":"startProfiling() snapshots initial state for every root the hook knows (hook.getFiberRoots(rendererID)) and requires each root to already have a DevTools FiberInstance in rootToFiberInstanceMap - i.e. at least one processed commit (or the initial flush) per root before profiling begins. The throw fires when profiling starts while a known Fiber root was never processed by the backend, so there is no id/tree snapshot to record.","triggerScenarios":"Clicking the Profiler record button (bridge 'startProfiling'), or auto-start (shouldStartProfilingNow at renderer.js:7378, e.g. 'reload and start profiling'), while a root exists that never committed - pre-created createRoot() containers, roots mounted during the same tick profiling starts, or a hook/backend version skew where root registration diverges.","commonSituations":"Using reload-and-profile on apps with lazily rendered roots; starting a profile immediately after page load before the tree paints; pages with several renderers where one root renders on interaction only.","solutions":["Let every root render at least once before starting the profiler (interact with the app once, then record).","Avoid 'reload and profile immediately' flows on apps whose roots mount lazily; start recording after load instead.","Keep React and DevTools versions matched and current.","If it persists, file a React issue noting which roots were unrendered when profiling started."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// in a custom frontend: only start profiling after at least one commit flush per renderer\nif (store.hasReceivedOperations(rendererID)) {\n  bridge.send('startProfiling', {recordChangeDescriptions});\n}","typeGuard":null,"tryCatchPattern":"try {\n  bridge.send('startProfiling', {...});\n} catch (err) {\n  if (err.message.includes('when starting profiling')) {\n    // one of the renderer's roots never committed; reload and profile after first render\n    console.warn('A root never committed before profiling - reload and retry after render');\n  } else {\n    throw err;\n  }\n}","preventionTips":["Avoid 'reload and profile instantly' flows on apps whose roots mount lazily - start recording after the first render.","Ensure every createRoot container renders once before profiling.","Keep DevTools and React versions in sync."],"tags":["react-devtools","profiler","fiber-root","race-condition"],"backgroundTag":"unregistered-fiber-root","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}