Skip to content

[internal] fix console patch, add RN #32075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/shared/forks/consoleWithStackDev.rn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
*/

import ReactSharedInternals from 'shared/ReactSharedInternals';
import * as dynamicFlagsUntyped from 'ReactNativeInternalFeatureFlags';
const enableRemoveConsolePatches =
dynamicFlagsUntyped && dynamicFlagsUntyped.enableRemoveConsolePatches;

let suppressWarning = false;
export function setSuppressWarning(newSuppressWarning) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
suppressWarning = newSuppressWarning;
}
Expand All @@ -21,22 +27,33 @@ export function setSuppressWarning(newSuppressWarning) {
// they are left as they are instead.

export function warn(format, ...args) {
if (__DEV__) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['warn'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('warn', format, args);
}
}
}

export function error(format, ...args) {
if (__DEV__) {
if (enableRemoveConsolePatches) {
if (__DEV__) {
console['error'](format, ...args);
}
} else if (__DEV__) {
if (!suppressWarning) {
printWarning('error', format, args);
}
}
}

function printWarning(level, format, args) {
if (enableRemoveConsolePatches) {
return;
}
if (__DEV__) {
if (ReactSharedInternals.getCurrentStack) {
const stack = ReactSharedInternals.getCurrentStack();
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/consoleWithStackDev.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

const {enableRemoveConsolePatches} = require('shared/ReactFeatureFlags');
const {enableRemoveConsolePatches} = require('ReactFeatureFlags');

// This refers to a WWW module.
const warningWWW = require('warning');
Expand Down
8 changes: 6 additions & 2 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,9 @@ const bundles = [
moduleType: RENDERER,
entry: 'react-native-renderer',
global: 'ReactNativeRenderer',
externals: ['react-native'],
// ReactNativeInternalFeatureFlags temporary until we land enableRemoveConsolePatches.
// Needs to be done before the next RN OSS release.
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
minifyWithProdErrorCodes: false,
wrapWithModuleBoundaries: true,
babel: opts =>
Expand Down Expand Up @@ -817,7 +819,9 @@ const bundles = [
moduleType: RENDERER,
entry: 'react-native-renderer/fabric',
global: 'ReactFabric',
externals: ['react-native'],
// ReactNativeInternalFeatureFlags temporary until we land enableRemoveConsolePatches.
// Needs to be done before the next RN OSS release.
externals: ['react-native', 'ReactNativeInternalFeatureFlags'],
minifyWithProdErrorCodes: false,
wrapWithModuleBoundaries: true,
babel: opts =>
Expand Down
Loading