[internal] fix console patch, add RN (#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.
Ricky committed
Jan 15, 2025 at 10:20 UTC
43d18bc2d3d31f43706f513a996ef9b4a7495237
3 files changed
+26
-5
packages/shared/forks/consoleWithStackDev.rn.js
+19
-2
@@ -6,9 +6,15 @@
6
*/
7
8
import ReactSharedInternals from 'shared/ReactSharedInternals';
9
+import * as dynamicFlagsUntyped from 'ReactNativeInternalFeatureFlags';
10
+const enableRemoveConsolePatches =
11
+ dynamicFlagsUntyped && dynamicFlagsUntyped.enableRemoveConsolePatches;
12
13
let suppressWarning = false;
14
export function setSuppressWarning(newSuppressWarning) {
15
+ if (enableRemoveConsolePatches) {
16
+ return;
17
+ }
18
if (__DEV__) {
19
suppressWarning = newSuppressWarning;
20
}
@@ -21,7 +27,11 @@ export function setSuppressWarning(newSuppressWarning) {
27
// they are left as they are instead.
28
29
export function warn(format, ...args) {
24
- if (__DEV__) {
30
+ if (enableRemoveConsolePatches) {
31
+ if (__DEV__) {
32
+ console['warn'](format, ...args);
33
+ }
34
+ } else if (__DEV__) {
35
if (!suppressWarning) {
36
printWarning('warn', format, args);
37
}
@@ -29,7 +39,11 @@ export function warn(format, ...args) {
39
}
40
41
export function error(format, ...args) {
32
- if (__DEV__) {
42
+ if (enableRemoveConsolePatches) {
43
+ if (__DEV__) {
44
+ console['error'](format, ...args);
45
+ }
46
+ } else if (__DEV__) {
47
if (!suppressWarning) {
48
printWarning('error', format, args);
49
}
@@ -37,6 +51,9 @@ export function error(format, ...args) {
51
}
52
53
function printWarning(level, format, args) {
54
+ if (enableRemoveConsolePatches) {
55
+ return;
56
+ }
57
if (__DEV__) {
58
if (ReactSharedInternals.getCurrentStack) {
59
const stack = ReactSharedInternals.getCurrentStack();
packages/shared/forks/consoleWithStackDev.www.js
+1
-1
@@ -5,7 +5,7 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
-const {enableRemoveConsolePatches} = require('shared/ReactFeatureFlags');
8
+const {enableRemoveConsolePatches} = require('ReactFeatureFlags');
9
10
// This refers to a WWW module.
11
const warningWWW = require('warning');
scripts/rollup/bundles.js
+6
-2
@@ -783,7 +783,9 @@ const bundles = [
783
moduleType: RENDERER,
784
entry: 'react-native-renderer',
785
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'],
789
minifyWithProdErrorCodes: false,
790
wrapWithModuleBoundaries: true,
791
babel: opts =>
@@ -817,7 +819,9 @@ const bundles = [
819
moduleType: RENDERER,
820
entry: 'react-native-renderer/fabric',
821
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'],
825
minifyWithProdErrorCodes: false,
826
wrapWithModuleBoundaries: true,
827
babel: opts =>