Skip to content

Commit

Permalink
Move setUpReactDevTools to InitializeCore (#48871)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48871

# Changelog: [Internal]

Forward-fixing D68380665.

Requirements:
- `setUpReactDevTools` should be called before `setUpErrorHandling` to avoid React DevTools mutating `console.error` call arguments.
- `setUpReactDevTools` should be called after `setUpTimers`, because it is using `queueMicrotask`, see https://fb.workplace.com/groups/rn.panelapps/permalink/1120810879540337/.
- `setUpTimers` should be called after `polyfillPromise`, because it uses on `global.Promise`.

I went over bundles, which are not using `InitializeCore` and using either `setUpErrorHandling` or `setUpDeveloperTools` and updated their order of initialization accordingly.

Reviewed By: javache

Differential Revision: D68510100

fbshipit-source-id: 4331dcc7a7cb1dc438ca2ed5ccae49e736c41b2a
  • Loading branch information
hoxyq authored and facebook-github-bot committed Jan 23, 2025
1 parent c5af752 commit 8a586f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/react-native/Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ const start = Date.now();
require('./setUpGlobals');
require('../../src/private/setup/setUpDOM').default();
require('./setUpPerformance');
require('./setUpErrorHandling');
require('./polyfillPromise');
require('./setUpRegeneratorRuntime');
require('./setUpTimers');
if (__DEV__) {
require('./setUpReactDevTools');
}
require('./setUpErrorHandling');
require('./setUpRegeneratorRuntime');
require('./setUpXHR');
require('./setUpAlert');
require('./setUpNavigator');
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native/Libraries/Core/setUpErrorHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

'use strict';

if (__DEV__) {
// React DevTools need to be set up before the console.error patch.
require('./setUpReactDevTools');
}

if (global.RN$useAlwaysAvailableJSErrorHandling !== true) {
/**
* Sets up the console and exception handling (redbox) for React Native.
Expand Down
16 changes: 16 additions & 0 deletions packages/react-native/Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
import type {Domain} from '../../src/private/debugging/setUpFuseboxReactDevToolsDispatcher';
import type {Spec as NativeReactDevToolsRuntimeSettingsModuleSpec} from '../../src/private/fusebox/specs/NativeReactDevToolsRuntimeSettingsModule';

if (__DEV__) {
if (typeof global.queueMicrotask !== 'function') {
console.error(
'queueMicrotask should exist before setting up React DevTools.',
);
}

// Keep in sync with ExceptionsManager/installConsoleErrorReporter
// $FlowExpectedError[prop-missing]
if (console._errorOriginal != null) {
console.error(
'ExceptionsManager should be set up after React DevTools to avoid console.error arguments mutation',
);
}
}

if (__DEV__) {
// Register dispatcher on global, which can be used later by Chrome DevTools frontend
require('../../src/private/debugging/setUpFuseboxReactDevToolsDispatcher');
Expand Down

0 comments on commit 8a586f2

Please sign in to comment.