Skip to content

Commit 43d18bc

Browse files
authored
[internal] fix console patch, add RN (facebook#32075)
The forking for `shared/ReactFeatureFlags` doesn't work in the console patches. Since they're already forked, we can import the internal ReactFeatureFlags files directly. Would have caught this in testing a PR sync, but the PR syncs are broken right now.
1 parent b158439 commit 43d18bc

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/shared/forks/consoleWithStackDev.rn.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
*/
77

88
import ReactSharedInternals from 'shared/ReactSharedInternals';
9+
import * as dynamicFlagsUntyped from 'ReactNativeInternalFeatureFlags';
10+
const enableRemoveConsolePatches =
11+
dynamicFlagsUntyped && dynamicFlagsUntyped.enableRemoveConsolePatches;
912

1013
let suppressWarning = false;
1114
export function setSuppressWarning(newSuppressWarning) {
15+
if (enableRemoveConsolePatches) {
16+
return;
17+
}
1218
if (__DEV__) {
1319
suppressWarning = newSuppressWarning;
1420
}
@@ -21,22 +27,33 @@ export function setSuppressWarning(newSuppressWarning) {
2127
// they are left as they are instead.
2228

2329
export function warn(format, ...args) {
24-
if (__DEV__) {
30+
if (enableRemoveConsolePatches) {
31+
if (__DEV__) {
32+
console['warn'](format, ...args);
33+
}
34+
} else if (__DEV__) {
2535
if (!suppressWarning) {
2636
printWarning('warn', format, args);
2737
}
2838
}
2939
}
3040

3141
export function error(format, ...args) {
32-
if (__DEV__) {
42+
if (enableRemoveConsolePatches) {
43+
if (__DEV__) {
44+
console['error'](format, ...args);
45+
}
46+
} else if (__DEV__) {
3347
if (!suppressWarning) {
3448
printWarning('error', format, args);
3549
}
3650
}
3751
}
3852

3953
function printWarning(level, format, args) {
54+
if (enableRemoveConsolePatches) {
55+
return;
56+
}
4057
if (__DEV__) {
4158
if (ReactSharedInternals.getCurrentStack) {
4259
const stack = ReactSharedInternals.getCurrentStack();

packages/shared/forks/consoleWithStackDev.www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const {enableRemoveConsolePatches} = require('shared/ReactFeatureFlags');
8+
const {enableRemoveConsolePatches} = require('ReactFeatureFlags');
99

1010
// This refers to a WWW module.
1111
const warningWWW = require('warning');

scripts/rollup/bundles.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,9 @@ const bundles = [
783783
moduleType: RENDERER,
784784
entry: 'react-native-renderer',
785785
global: 'ReactNativeRenderer',
786-
externals: ['react-native'],
786+
// ReactNativeInternalFeatureFlags temporary until we land enableRemoveConsolePatches.
787+
// Needs to be done before the next RN OSS release.
788+
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
787789
minifyWithProdErrorCodes: false,
788790
wrapWithModuleBoundaries: true,
789791
babel: opts =>
@@ -817,7 +819,9 @@ const bundles = [
817819
moduleType: RENDERER,
818820
entry: 'react-native-renderer/fabric',
819821
global: 'ReactFabric',
820-
externals: ['react-native'],
822+
// ReactNativeInternalFeatureFlags temporary until we land enableRemoveConsolePatches.
823+
// Needs to be done before the next RN OSS release.
824+
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
821825
minifyWithProdErrorCodes: false,
822826
wrapWithModuleBoundaries: true,
823827
babel: opts =>

0 commit comments

Comments
 (0)