GeezerVison is showing github.com — Warning system refactoring (part 1) (#16799) · react/react@18d2e0c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOM.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,7 +61,7 @@ import ReactVersion from 'shared/ReactVersion'; | 61 | 61 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | 62 | 62 | import getComponentName from 'shared/getComponentName'; | 63 | 63 | import invariant from 'shared/invariant'; | 64 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 64 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 65 | 65 | import warningWithoutStack from 'shared/warningWithoutStack'; | 66 | 66 | import {enableStableConcurrentModeAPIs} from 'shared/ReactFeatureFlags'; | 67 | 67 |
| @@ -542,7 +542,7 @@ function legacyCreateRootFromDOMContainer( | 542 | 542 | if (__DEV__) { | 543 | 543 | if (shouldHydrate && !forceHydrate && !warnedAboutHydrateAPI) { | 544 | 544 | warnedAboutHydrateAPI = true; | 545 | | - lowPriorityWarning( | | 545 | + lowPriorityWarningWithoutStack( | 546 | 546 | false, | 547 | 547 | 'render(): Calling ReactDOM.render() to hydrate server-rendered markup ' + | 548 | 548 | 'will stop working in React v17. Replace the ReactDOM.render() call ' + | @@ -801,7 +801,7 @@ const ReactDOM: Object = { | 801 | 801 | unstable_createPortal(...args) { | 802 | 802 | if (!didWarnAboutUnstableCreatePortal) { | 803 | 803 | didWarnAboutUnstableCreatePortal = true; | 804 | | - lowPriorityWarning( | | 804 | + lowPriorityWarningWithoutStack( | 805 | 805 | false, | 806 | 806 | 'The ReactDOM.unstable_createPortal() alias has been deprecated, ' + | 807 | 807 | 'and will be removed in React 17+. Update your code to use ' + | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactPartialRenderer.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes'; | 15 | 15 | import React from 'react'; | 16 | 16 | import invariant from 'shared/invariant'; | 17 | 17 | import getComponentName from 'shared/getComponentName'; | 18 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 18 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 19 | 19 | import warning from 'shared/warning'; | 20 | 20 | import warningWithoutStack from 'shared/warningWithoutStack'; | 21 | 21 | import describeComponentFrame from 'shared/describeComponentFrame'; | @@ -588,7 +588,7 @@ function resolve( | 588 | 588 | const componentName = getComponentName(Component) || 'Unknown'; | 589 | 589 |
| 590 | 590 | if (!didWarnAboutDeprecatedWillMount[componentName]) { | 591 | | - lowPriorityWarning( | | 591 | + lowPriorityWarningWithoutStack( | 592 | 592 | false, | 593 | 593 | // keep this warning in sync with ReactStrictModeWarning.js | 594 | 594 | 'componentWillMount has been renamed, and is not recommended for use. ' + | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/test-utils/ReactTestUtils.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ import { | 17 | 17 | } from 'shared/ReactWorkTags'; | 18 | 18 | import SyntheticEvent from 'legacy-events/SyntheticEvent'; | 19 | 19 | import invariant from 'shared/invariant'; | 20 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 20 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 21 | 21 | import {ELEMENT_NODE} from '../shared/HTMLNodeType'; | 22 | 22 | import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes'; | 23 | 23 | import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags'; | @@ -361,7 +361,7 @@ const ReactTestUtils = { | 361 | 361 | mockComponent: function(module, mockTagName) { | 362 | 362 | if (!hasWarnedAboutDeprecatedMockComponent) { | 363 | 363 | hasWarnedAboutDeprecatedMockComponent = true; | 364 | | - lowPriorityWarning( | | 364 | + lowPriorityWarningWithoutStack( | 365 | 365 | false, | 366 | 366 | 'ReactTestUtils.mockComponent() is deprecated. ' + | 367 | 367 | 'Use shallow rendering or jest.mock() instead.\n\n' + | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-is/src/ReactIs.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ import { | 25 | 25 | REACT_SUSPENSE_TYPE, | 26 | 26 | } from 'shared/ReactSymbols'; | 27 | 27 | import isValidElementType from 'shared/isValidElementType'; | 28 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 28 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 29 | 29 |
| 30 | 30 | export function typeOf(object: any) { | 31 | 31 | if (typeof object === 'object' && object !== null) { | @@ -88,7 +88,7 @@ export function isAsyncMode(object: any) { | 88 | 88 | if (__DEV__) { | 89 | 89 | if (!hasWarnedAboutDeprecatedIsAsyncMode) { | 90 | 90 | hasWarnedAboutDeprecatedIsAsyncMode = true; | 91 | | - lowPriorityWarning( | | 91 | + lowPriorityWarningWithoutStack( | 92 | 92 | false, | 93 | 93 | 'The ReactIs.isAsyncMode() alias has been deprecated, ' + | 94 | 94 | 'and will be removed in React 17+. Update your code to use ' + | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactStrictModeWarnings.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ import {getStackByFiberInDevAndProd} from './ReactCurrentFiber'; | 13 | 13 |
| 14 | 14 | import getComponentName from 'shared/getComponentName'; | 15 | 15 | import {StrictMode} from './ReactTypeOfMode'; | 16 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 16 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 17 | 17 | import warningWithoutStack from 'shared/warningWithoutStack'; | 18 | 18 |
| 19 | 19 | type FiberArray = Array<Fiber>; | @@ -237,7 +237,7 @@ if (__DEV__) { | 237 | 237 | if (componentWillMountUniqueNames.size > 0) { | 238 | 238 | const sortedNames = setToSortedString(componentWillMountUniqueNames); | 239 | 239 |
| 240 | | - lowPriorityWarning( | | 240 | + lowPriorityWarningWithoutStack( | 241 | 241 | false, | 242 | 242 | 'componentWillMount has been renamed, and is not recommended for use. ' + | 243 | 243 | 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + | @@ -256,7 +256,7 @@ if (__DEV__) { | 256 | 256 | componentWillReceivePropsUniqueNames, | 257 | 257 | ); | 258 | 258 |
| 259 | | - lowPriorityWarning( | | 259 | + lowPriorityWarningWithoutStack( | 260 | 260 | false, | 261 | 261 | 'componentWillReceiveProps has been renamed, and is not recommended for use. ' + | 262 | 262 | 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + | @@ -276,7 +276,7 @@ if (__DEV__) { | 276 | 276 | if (componentWillUpdateUniqueNames.size > 0) { | 277 | 277 | const sortedNames = setToSortedString(componentWillUpdateUniqueNames); | 278 | 278 |
| 279 | | - lowPriorityWarning( | | 279 | + lowPriorityWarningWithoutStack( | 280 | 280 | false, | 281 | 281 | 'componentWillUpdate has been renamed, and is not recommended for use. ' + | 282 | 282 | 'See https://fb.me/react-unsafe-component-lifecycles for details.\n\n' + | |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/ReactBaseClasses.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | */ | 7 | 7 |
| 8 | 8 | import invariant from 'shared/invariant'; | 9 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 9 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 10 | 10 |
| 11 | 11 | import ReactNoopUpdateQueue from './ReactNoopUpdateQueue'; | 12 | 12 |
| @@ -105,7 +105,7 @@ if (__DEV__) { | 105 | 105 | const defineDeprecationWarning = function(methodName, info) { | 106 | 106 | Object.defineProperty(Component.prototype, methodName, { | 107 | 107 | get: function() { | 108 | | - lowPriorityWarning( | | 108 | + lowPriorityWarningWithoutStack( | 109 | 109 | false, | 110 | 110 | '%s(...) is deprecated in plain JavaScript React classes. %s', | 111 | 111 | info[0], | |
Collapse file Copy file name to clipboardExpand all lines: packages/react/src/ReactElementValidator.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | * that support it. | 13 | 13 | */ | 14 | 14 |
| 15 | | -import lowPriorityWarning from 'shared/lowPriorityWarning'; | | 15 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | 16 | 16 | import isValidElementType from 'shared/isValidElementType'; | 17 | 17 | import getComponentName from 'shared/getComponentName'; | 18 | 18 | import { | @@ -477,7 +477,7 @@ export function createFactoryWithValidation(type) { | 477 | 477 | Object.defineProperty(validatedFactory, 'type', { | 478 | 478 | enumerable: false, | 479 | 479 | get: function() { | 480 | | - lowPriorityWarning( | | 480 | + lowPriorityWarningWithoutStack( | 481 | 481 | false, | 482 | 482 | 'Factory.type is deprecated. Access the class directly ' + | 483 | 483 | 'before passing it to createFactory.', | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/lowPriorityWarningWithoutStack.www.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | * LICENSE file in the root directory of this source tree. | 6 | 6 | */ | 7 | 7 |
| | 8 | +// This "lowPriorityWarning" is an external module | 8 | 9 | export default require('lowPriorityWarning'); |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/lowPriorityWarning.js +10-30Lines changed: 10 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | * LICENSE file in the root directory of this source tree. | 6 | 6 | */ | 7 | 7 |
| | 8 | +import lowPriorityWarningWithoutStack from 'shared/lowPriorityWarningWithoutStack'; | | 9 | +import ReactSharedInternals from 'shared/ReactSharedInternals'; | | 10 | + | 8 | 11 | /** | 9 | | - * Forked from fbjs/warning: | 10 | | - * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js | 11 | | - * | 12 | | - * Only change is we use console.warn instead of console.error, | 13 | | - * and do nothing when 'console' is not supported. | 14 | | - * This really simplifies the code. | 15 | | - * --- | 16 | 12 | * Similar to invariant but only logs a warning if the condition is not met. | 17 | 13 | * This can be used to log issues in development environments in critical | 18 | 14 | * paths. Removing the logging code for production environments will keep the | 19 | 15 | * same logic and follow the same code paths. | 20 | 16 | */ | 21 | 17 |
| 22 | | -let lowPriorityWarning = function() {}; | | 18 | +let lowPriorityWarning = lowPriorityWarningWithoutStack; | 23 | 19 |
| 24 | 20 | if (__DEV__) { | 25 | | - const printWarning = function(format, ...args) { | 26 | | - let argIndex = 0; | 27 | | - const message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); | 28 | | - if (typeof console !== 'undefined') { | 29 | | - console.warn(message); | 30 | | - } | 31 | | - try { | 32 | | - // --- Welcome to debugging React --- | 33 | | - // This error was thrown as a convenience so that you can use this stack | 34 | | - // to find the callsite that caused this warning to fire. | 35 | | - throw new Error(message); | 36 | | - } catch (x) {} | 37 | | - }; | 38 | | - | 39 | 21 | lowPriorityWarning = function(condition, format, ...args) { | 40 | | - if (format === undefined) { | 41 | | - throw new Error( | 42 | | - '`lowPriorityWarning(condition, format, ...args)` requires a warning ' + | 43 | | - 'message argument', | 44 | | - ); | 45 | | - } | 46 | | - if (!condition) { | 47 | | - printWarning(format, ...args); | | 22 | + if (condition) { | | 23 | + return; | 48 | 24 | } | | 25 | + const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; | | 26 | + const stack = ReactDebugCurrentFrame.getStackAddendum(); | | 27 | + // eslint-disable-next-line react-internal/warning-and-invariant-args | | 28 | + lowPriorityWarningWithoutStack(false, format + '%s', ...args, stack); | 49 | 29 | }; | 50 | 30 | } | 51 | 31 |
| |
Collapse file Copy file name to clipboard +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/** | | 2 | + * Copyright (c) Facebook, Inc. and its affiliates. | | 3 | + * | | 4 | + * This source code is licensed under the MIT license found in the | | 5 | + * LICENSE file in the root directory of this source tree. | | 6 | + */ | | 7 | + | | 8 | +/** | | 9 | + * Forked from fbjs/warning: | | 10 | + * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js | | 11 | + * | | 12 | + * Only change is we use console.warn instead of console.error, | | 13 | + * and do nothing when 'console' is not supported. | | 14 | + * This really simplifies the code. | | 15 | + * --- | | 16 | + * Similar to invariant but only logs a warning if the condition is not met. | | 17 | + * This can be used to log issues in development environments in critical | | 18 | + * paths. Removing the logging code for production environments will keep the | | 19 | + * same logic and follow the same code paths. | | 20 | + */ | | 21 | + | | 22 | +let lowPriorityWarningWithoutStack = function() {}; | | 23 | + | | 24 | +if (__DEV__) { | | 25 | + const printWarning = function(format, ...args) { | | 26 | + let argIndex = 0; | | 27 | + const message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]); | | 28 | + if (typeof console !== 'undefined') { | | 29 | + console.warn(message); | | 30 | + } | | 31 | + try { | | 32 | + // --- Welcome to debugging React --- | | 33 | + // This error was thrown as a convenience so that you can use this stack | | 34 | + // to find the callsite that caused this warning to fire. | | 35 | + throw new Error(message); | | 36 | + } catch (x) {} | | 37 | + }; | | 38 | + | | 39 | + lowPriorityWarningWithoutStack = function(condition, format, ...args) { | | 40 | + if (format === undefined) { | | 41 | + throw new Error( | | 42 | + '`lowPriorityWarningWithoutStack(condition, format, ...args)` requires a warning ' + | | 43 | + 'message argument', | | 44 | + ); | | 45 | + } | | 46 | + if (!condition) { | | 47 | + printWarning(format, ...args); | | 48 | + } | | 49 | + }; | | 50 | +} | | 51 | + | | 52 | +export default lowPriorityWarningWithoutStack; |
|