From 0caa186c5accab2e7de241fce0eed1950746983d Mon Sep 17 00:00:00 2001 From: lms <1359816810@qq.com> Date: Fri, 3 Apr 2026 15:48:09 +0800 Subject: [PATCH] fix: guard against duplicate Fusebox DevTools dispatcher initialization When using Expo dev client, switching the app from background to foreground can cause 'TypeError: property is not writable' in setUpFuseboxReactDevToolsDispatcher. The issue occurs because Metro HMR may invalidate module cache during foreground transitions, causing setUpDefaultReactNativeEnvironment to be re-executed and its initialized guard to be reset. This leads to Object.defineProperty on __FUSEBOX_REACT_DEVTOOLS_DISPATCHER__ running twice. The fix is to make the property definition idempotent by checking if it already exists before defining it. --- .../setUpFuseboxReactDevToolsDispatcher.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-native/src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher.js b/packages/react-native/src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher.js index 79f7f4d7688a..e0e2486ac4fe 100644 --- a/packages/react-native/src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher.js +++ b/packages/react-native/src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher.js @@ -105,9 +105,11 @@ class FuseboxReactDevToolsDispatcher { } } -Object.defineProperty(global, '__FUSEBOX_REACT_DEVTOOLS_DISPATCHER__', { - value: FuseboxReactDevToolsDispatcher, - configurable: false, - enumerable: false, - writable: false, -}); +if (global.__FUSEBOX_REACT_DEVTOOLS_DISPATCHER__ == null) { + Object.defineProperty(global, '__FUSEBOX_REACT_DEVTOOLS_DISPATCHER__', { + value: FuseboxReactDevToolsDispatcher, + configurable: false, + enumerable: false, + writable: false, + }); +}