Let web apps pass root options (onRecoverableError) to hydrateRoot and createRoot
M
Marcos Pereira
On the web, Expo's launch calls
hydrateRoot(rootTag, element)
and createRoot(rootTag)
with no options (expo/build/launch/AppRegistry.web.js
, around line 65 in 58.0.26), and nothing in the app config reaches them.So an app can't set
onRecoverableError
, and React 19 then sends every recoverable error, hydration mismatches included, to window.reportError
. That fires the window error
event, which most error reporters and error screens listen to. React has already recovered from these errors, so the user can get an error screen over a page that works fine.Right now we work around it by hooking Metro's resolver so Expo's launch imports a small wrapper around
react-dom/client
that adds onRecoverableError
. It works, but it depends on which file Expo does that import in, so we keep a test around just to notice when that file moves.It'd be great to have a supported way to pass root options, maybe a web-only export from the root layout or a field in the app config.
onRecoverableError
, onCaughtError
and onUncaughtError
would cover what we need.Related: expo/expo#52069. Thanks!