{"record":{"id":"93ee45d631bef9e3","repo":"testing-library/react-testing-library","slug":"onuncaughterror-is-not-supported-the-render-cal","errorCode":null,"errorMessage":"onUncaughtError is not supported. The `render` call will already throw on uncaught errors.","messagePattern":"onUncaughtError is not supported\\. The `render` call will already throw on uncaught errors\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/pure.js","lineNumber":254,"sourceCode":"}\n\nfunction render(\n  ui,\n  {\n    container,\n    baseElement = container,\n    legacyRoot = false,\n    onCaughtError,\n    onUncaughtError,\n    onRecoverableError,\n    queries,\n    hydrate = false,\n    wrapper,\n    reactStrictMode,\n  } = {},\n) {\n  if (onUncaughtError !== undefined) {\n    throw new Error(\n      'onUncaughtError is not supported. The `render` call will already throw on uncaught errors.',\n    )\n  }\n  if (legacyRoot && typeof ReactDOM.render !== 'function') {\n    const error = new Error(\n      '`legacyRoot: true` is not supported in this version of React. ' +\n        'If your app runs React 19 or later, you should remove this flag. ' +\n        'If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.',\n    )\n    Error.captureStackTrace(error, render)\n    throw error\n  }\n\n  if (!baseElement) {\n    // default to document.body instead of documentElement to avoid output of potentially-large\n    // head elements (such as JSS style blocks) in debug output\n    baseElement = document.body\n  }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/testing-library/react-testing-library/blob/20ce75f2907ca0e5c5a8ae595c0e9a4e368c7800/src/pure.js#L236-L272","documentation":"render() in src/pure.js explicitly rejects the onUncaughtError option (a React 19 createRoot callback). @testing-library/react deliberately does not support it because its render already runs inside act(), where an uncaught error thrown during render propagates and throws from the render() call itself — so a user-supplied onUncaughtError handler could never be honored consistently.","triggerScenarios":"Calling render(ui, {onUncaughtError: someHandler}) — passing the option at all, even as undefined-valued variable via spread, triggers the throw immediately.","commonSituations":"Migrating to React 19 where teams copied createRoot options (onUncaughtError, onCaughtError, onRecoverableError) straight into RTL render options; migrating tests from a manual createRoot harness to RTL.","solutions":["Remove the onUncaughtError option from the render() call.","Assert errors from your component with expect(() => render(...)).toThrow(...) or an error boundary instead of an onUncaughtError callback.","If you need custom uncaught-error logging, wrap the component under test in an error boundary component.","Keep onCaughtError/onRecoverableError (supported) if you only need those hooks."],"exampleFix":"// before\nrender(<App />, { onUncaughtError: (error) => log(error) })\n// after\nexpect(() => render(<App />)).toThrow('boom')","handlingStrategy":"validation","validationCode":"const options = { onCaughtError: console.error }\nif ('onUncaughtError' in options) throw new Error('onUncaughtError is not supported by @testing-library/react render()')\nrender(<App />, options)","typeGuard":"function isSupportedRenderOptions(options) {\n  return typeof options === 'object' && options !== null && !('onUncaughtError' in options)\n}","tryCatchPattern":"try {\n  render(<App />, options)\n} catch (e) {\n  if (String(e.message).includes('onUncaughtError is not supported')) {\n    const { onUncaughtError, ...rest } = options\n    render(<App />, rest)\n  } else {\n    throw e\n  }\n}","preventionTips":["Never copy createRoot-only options (onUncaughtError) into RTL render() options.","Test thrown render errors with expect(() => render(...)).toThrow() instead of callbacks.","Use error boundaries or onCaughtError/onRecoverableError (supported) for error-path coverage.","When migrating from a manual createRoot harness to RTL, audit the options object you pass along."],"tags":["react","react-19","error-handling","api-misuse"],"backgroundTag":"unsupported-render-option","analyzedSha":"20ce75f2907ca0e5c5a8ae595c0e9a4e368c7800","analyzedAt":"2026-09-02T16:11:03.216Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}