Fix concatenation of null to a warning message (#13166)
Dan Abramov committed
Jul 9, 2018 at 13:56 UTC
96d38d178ae3956e0eecbde789e3fcf3e487cfea
14 files changed
+60
-75
packages/react-dom/src/client/ReactDOMFiberComponent.js
+10
-10
@@ -10,7 +10,7 @@
10
// TODO: direct imports like some-package/src/* are bad. Fix me.
11
import {
12
getCurrentFiberOwnerNameInDevOrNull,
13
- getCurrentFiberStackInDevOrNull,
13
+ getCurrentFiberStackInDev,
14
} from 'react-reconciler/src/ReactCurrentFiber';
15
import {registrationNameModules} from 'events/EventPluginRegistry';
16
import warning from 'shared/warning';
@@ -61,7 +61,7 @@ const HTML = '__html';
61
62
const {html: HTML_NAMESPACE} = Namespaces;
63
64
-let getStackInDevOrNull = () => '';
64
+let getStackInDev = () => '';
65
66
let warnedUnknownTags;
67
let suppressHydrationWarning;
@@ -76,7 +76,7 @@ let normalizeMarkupForTextOrAttribute;
76
let normalizeHTML;
77
78
if (__DEV__) {
79
- getStackInDevOrNull = getCurrentFiberStackInDevOrNull;
79
+ getStackInDev = getCurrentFiberStackInDev;
80
81
warnedUnknownTags = {
82
// Chrome is the only major browser not shipping <time>. But as of July
@@ -180,7 +180,7 @@ if (__DEV__) {
180
registrationName,
181
registrationName,
182
registrationName,
183
- getCurrentFiberStackInDevOrNull(),
183
+ getCurrentFiberStackInDev(),
184
);
185
} else {
186
warning(
@@ -188,7 +188,7 @@ if (__DEV__) {
188
'Expected `%s` listener to be a function, instead got a value of `%s` type.%s',
189
registrationName,
190
typeof listener,
191
- getCurrentFiberStackInDevOrNull(),
191
+ getCurrentFiberStackInDev(),
192
);
193
}
194
};
@@ -269,7 +269,7 @@ function setInitialDOMProperties(
269
CSSPropertyOperations.setValueForStyles(
270
domElement,
271
nextProp,
272
- getStackInDevOrNull,
272
+ getStackInDev,
273
);
274
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
275
const nextHtml = nextProp ? nextProp[HTML] : undefined;
@@ -329,7 +329,7 @@ function updateDOMProperties(
329
CSSPropertyOperations.setValueForStyles(
330
domElement,
331
propValue,
332
- getStackInDevOrNull,
332
+ getStackInDev,
333
);
334
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
335
setInnerHTML(domElement, propValue);
@@ -523,7 +523,7 @@ export function setInitialProperties(
523
props = rawProps;
524
}
525
526
- assertValidProps(tag, props, getStackInDevOrNull);
526
+ assertValidProps(tag, props, getStackInDev);
527
528
setInitialDOMProperties(
529
tag,
@@ -611,7 +611,7 @@ export function diffProperties(
611
break;
612
}
613
614
- assertValidProps(tag, nextProps, getStackInDevOrNull);
614
+ assertValidProps(tag, nextProps, getStackInDev);
615
616
let propKey;
617
let styleName;
@@ -902,7 +902,7 @@ export function diffHydratedProperties(
902
break;
903
}
904
905
- assertValidProps(tag, rawProps, getStackInDevOrNull);
905
+ assertValidProps(tag, rawProps, getStackInDev);
906
907
if (__DEV__) {
908
extraAttributeNames = new Set();
packages/react-dom/src/client/ReactDOMFiberInput.js
+4
-4
@@ -10,7 +10,7 @@
10
// TODO: direct imports like some-package/src/* are bad. Fix me.
11
import {
12
getCurrentFiberOwnerNameInDevOrNull,
13
- getCurrentFiberStackInDevOrNull,
13
+ getCurrentFiberStackInDev,
14
} from 'react-reconciler/src/ReactCurrentFiber';
15
import invariant from 'shared/invariant';
16
import warning from 'shared/warning';
@@ -74,7 +74,7 @@ export function initWrapperState(element: Element, props: Object) {
74
ReactControlledValuePropTypes.checkPropTypes(
75
'input',
76
props,
77
- getCurrentFiberStackInDevOrNull,
77
+ getCurrentFiberStackInDev,
78
);
79
80
if (
@@ -153,7 +153,7 @@ export function updateWrapper(element: Element, props: Object) {
153
'Decide between using a controlled or uncontrolled input ' +
154
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components%s',
155
props.type,
156
- getCurrentFiberStackInDevOrNull(),
156
+ getCurrentFiberStackInDev(),
157
);
158
didWarnUncontrolledToControlled = true;
159
}
@@ -169,7 +169,7 @@ export function updateWrapper(element: Element, props: Object) {
169
'Decide between using a controlled or uncontrolled input ' +
170
'element for the lifetime of the component. More info: https://fb.me/react-controlled-components%s',
171
props.type,
172
- getCurrentFiberStackInDevOrNull(),
172
+ getCurrentFiberStackInDev(),
173
);
174
didWarnControlledToUncontrolled = true;
175
}
packages/react-dom/src/client/ReactDOMFiberSelect.js
+2
-2
@@ -10,7 +10,7 @@
10
// TODO: direct imports like some-package/src/* are bad. Fix me.
11
import {
12
getCurrentFiberOwnerNameInDevOrNull,
13
- getCurrentFiberStackInDevOrNull,
13
+ getCurrentFiberStackInDev,
14
} from 'react-reconciler/src/ReactCurrentFiber';
15
import warning from 'shared/warning';
16
@@ -46,7 +46,7 @@ function checkSelectPropTypes(props) {
46
ReactControlledValuePropTypes.checkPropTypes(
47
'select',
48
props,
49
- getCurrentFiberStackInDevOrNull,
49
+ getCurrentFiberStackInDev,
50
);
51
52
for (let i = 0; i < valuePropNames.length; i++) {
packages/react-dom/src/client/ReactDOMFiberTextarea.js
+2
-2
@@ -10,7 +10,7 @@
10
import invariant from 'shared/invariant';
11
import warning from 'shared/warning';
12
// TODO: direct imports like some-package/src/* are bad. Fix me.
13
-import {getCurrentFiberStackInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
13
+import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber';
14
15
import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
16
@@ -67,7 +67,7 @@ export function initWrapperState(element: Element, props: Object) {
67
ReactControlledValuePropTypes.checkPropTypes(
68
'textarea',
69
props,
70
- getCurrentFiberStackInDevOrNull,
70
+ getCurrentFiberStackInDev,
71
);
72
if (
73
props.value !== undefined &&
packages/react-dom/src/client/validateDOMNesting.js
+2
-2
@@ -7,7 +7,7 @@
7
8
import warning from 'shared/warning';
9
// TODO: direct imports like some-package/src/* are bad. Fix me.
10
-import {getCurrentFiberStackInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
10
+import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber';
11
12
let validateDOMNesting = () => {};
13
@@ -426,7 +426,7 @@ if (__DEV__) {
426
}
427
428
const ancestorTag = invalidParentOrAncestor.tag;
429
- const addendum = getCurrentFiberStackInDevOrNull();
429
+ const addendum = getCurrentFiberStackInDev();
430
431
const warnKey =
432
!!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + addendum;
packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
+5
-10
@@ -18,11 +18,6 @@ const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
18
19
const hasOwnProperty = Object.prototype.hasOwnProperty;
20
21
-function getStackAddendum() {
22
- const stack = ReactDebugCurrentFrame.getStackAddendum();
23
- return stack != null ? stack : '';
24
-}
25
-
21
function validateProperty(tagName, name) {
22
if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
23
return true;
@@ -41,7 +36,7 @@ function validateProperty(tagName, name) {
36
false,
37
'Invalid ARIA attribute `%s`. ARIA attributes follow the pattern aria-* and must be lowercase.%s',
38
name,
44
- getStackAddendum(),
39
+ ReactDebugCurrentFrame.getStackAddendum(),
40
);
41
warnedProperties[name] = true;
42
return true;
@@ -53,7 +48,7 @@ function validateProperty(tagName, name) {
48
'Invalid ARIA attribute `%s`. Did you mean `%s`?%s',
49
name,
50
correctName,
56
- getStackAddendum(),
51
+ ReactDebugCurrentFrame.getStackAddendum(),
52
);
53
warnedProperties[name] = true;
54
return true;
@@ -79,7 +74,7 @@ function validateProperty(tagName, name) {
74
'Unknown ARIA attribute `%s`. Did you mean `%s`?%s',
75
name,
76
standardName,
82
- getStackAddendum(),
77
+ ReactDebugCurrentFrame.getStackAddendum(),
78
);
79
warnedProperties[name] = true;
80
return true;
@@ -110,7 +105,7 @@ function warnInvalidARIAProps(type, props) {
105
'For details, see https://fb.me/invalid-aria-prop%s',
106
unknownPropString,
107
type,
113
- getStackAddendum(),
108
+ ReactDebugCurrentFrame.getStackAddendum(),
109
);
110
} else if (invalidProps.length > 1) {
111
warning(
@@ -119,7 +114,7 @@ function warnInvalidARIAProps(type, props) {
114
'For details, see https://fb.me/invalid-aria-prop%s',
115
unknownPropString,
116
type,
122
- getStackAddendum(),
117
+ ReactDebugCurrentFrame.getStackAddendum(),
118
);
119
}
120
}
packages/react-dom/src/shared/ReactDOMNullInputValuePropHook.js
+2
-7
@@ -10,11 +10,6 @@ import warning from 'shared/warning';
10
11
let didWarnValueNull = false;
12
13
-function getStackAddendum() {
14
- const stack = ReactDebugCurrentFrame.getStackAddendum();
15
- return stack != null ? stack : '';
16
-}
17
-
13
export function validateProperties(type, props) {
14
if (type !== 'input' && type !== 'textarea' && type !== 'select') {
15
return;
@@ -29,7 +24,7 @@ export function validateProperties(type, props) {
24
'Consider using an empty array when `multiple` is set to `true` ' +
25
'to clear the component or `undefined` for uncontrolled components.%s',
26
type,
32
- getStackAddendum(),
27
+ ReactDebugCurrentFrame.getStackAddendum(),
28
);
29
} else {
30
warning(
@@ -38,7 +33,7 @@ export function validateProperties(type, props) {
33
'Consider using an empty string to clear the component or `undefined` ' +
34
'for uncontrolled components.%s',
35
type,
41
- getStackAddendum(),
36
+ ReactDebugCurrentFrame.getStackAddendum(),
37
);
38
}
39
}
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
+11
-16
@@ -21,11 +21,6 @@ import {
21
import isCustomComponent from './isCustomComponent';
22
import possibleStandardNames from './possibleStandardNames';
23
24
-function getStackAddendum() {
25
- const stack = ReactDebugCurrentFrame.getStackAddendum();
26
- return stack != null ? stack : '';
27
-}
28
-
24
let validateProperty = () => {};
25
26
if (__DEV__) {
@@ -69,7 +64,7 @@ if (__DEV__) {
64
'Invalid event handler property `%s`. Did you mean `%s`?%s',
65
name,
66
registrationName,
72
- getStackAddendum(),
67
+ ReactDebugCurrentFrame.getStackAddendum(),
68
);
69
warnedProperties[name] = true;
70
return true;
@@ -79,7 +74,7 @@ if (__DEV__) {
74
false,
75
'Unknown event handler property `%s`. It will be ignored.%s',
76
name,
82
- getStackAddendum(),
77
+ ReactDebugCurrentFrame.getStackAddendum(),
78
);
79
warnedProperties[name] = true;
80
return true;
@@ -94,7 +89,7 @@ if (__DEV__) {
89
'Invalid event handler property `%s`. ' +
90
'React events use the camelCase naming convention, for example `onClick`.%s',
91
name,
97
- getStackAddendum(),
92
+ ReactDebugCurrentFrame.getStackAddendum(),
93
);
94
}
95
warnedProperties[name] = true;
@@ -137,7 +132,7 @@ if (__DEV__) {
132
'Received a `%s` for a string attribute `is`. If this is expected, cast ' +
133
'the value to a string.%s',
134
typeof value,
140
- getStackAddendum(),
135
+ ReactDebugCurrentFrame.getStackAddendum(),
136
);
137
warnedProperties[name] = true;
138
return true;
@@ -149,7 +144,7 @@ if (__DEV__) {
144
'Received NaN for the `%s` attribute. If this is expected, cast ' +
145
'the value to a string.%s',
146
name,
152
- getStackAddendum(),
147
+ ReactDebugCurrentFrame.getStackAddendum(),
148
);
149
warnedProperties[name] = true;
150
return true;
@@ -167,7 +162,7 @@ if (__DEV__) {
162
'Invalid DOM property `%s`. Did you mean `%s`?%s',
163
name,
164
standardName,
170
- getStackAddendum(),
165
+ ReactDebugCurrentFrame.getStackAddendum(),
166
);
167
warnedProperties[name] = true;
168
return true;
@@ -184,7 +179,7 @@ if (__DEV__) {
179
'it from the DOM element.%s',
180
name,
181
lowerCasedName,
187
- getStackAddendum(),
182
+ ReactDebugCurrentFrame.getStackAddendum(),
183
);
184
warnedProperties[name] = true;
185
return true;
@@ -205,7 +200,7 @@ if (__DEV__) {
200
name,
201
value,
202
name,
208
- getStackAddendum(),
203
+ ReactDebugCurrentFrame.getStackAddendum(),
204
);
205
} else {
206
warning(
@@ -222,7 +217,7 @@ if (__DEV__) {
217
name,
218
name,
219
name,
225
- getStackAddendum(),
220
+ ReactDebugCurrentFrame.getStackAddendum(),
221
);
222
}
223
warnedProperties[name] = true;
@@ -265,7 +260,7 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) {
260
'For details, see https://fb.me/react-attribute-behavior%s',
261
unknownPropString,
262
type,
268
- getStackAddendum(),
263
+ ReactDebugCurrentFrame.getStackAddendum(),
264
);
265
} else if (unknownProps.length > 1) {
266
warning(
@@ -275,7 +270,7 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) {
270
'For details, see https://fb.me/react-attribute-behavior%s',
271
unknownPropString,
272
type,
278
- getStackAddendum(),
273
+ ReactDebugCurrentFrame.getStackAddendum(),
274
);
275
}
276
};
packages/react-reconciler/src/ReactChildFiber.js
+8
-8
@@ -39,7 +39,7 @@ import {
39
} from './ReactFiber';
40
import {emptyRefsObject} from './ReactFiberClassComponent';
41
import {
42
- getCurrentFiberStackInDevOrNull,
42
+ getCurrentFiberStackInDev,
43
getStackByFiberInDevAndProd,
44
} from './ReactCurrentFiber';
45
import {StrictMode} from './ReactTypeOfMode';
@@ -80,7 +80,7 @@ if (__DEV__) {
80
'Each child in an array or iterator should have a unique ' +
81
'"key" prop. See https://fb.me/react-warning-keys for ' +
82
'more information.' +
83
- (getCurrentFiberStackInDevOrNull() || '');
83
+ getCurrentFiberStackInDev();
84
if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
85
return;
86
}
@@ -91,7 +91,7 @@ if (__DEV__) {
91
'Each child in an array or iterator should have a unique ' +
92
'"key" prop. See https://fb.me/react-warning-keys for ' +
93
'more information.%s',
94
- getCurrentFiberStackInDevOrNull(),
94
+ getCurrentFiberStackInDev(),
95
);
96
};
97
}
@@ -197,7 +197,7 @@ function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
197
addendum =
198
' If you meant to render a collection of children, use an array ' +
199
'instead.' +
200
- (getCurrentFiberStackInDevOrNull() || '');
200
+ getCurrentFiberStackInDev();
201
}
202
invariant(
203
false,
@@ -215,7 +215,7 @@ function warnOnFunctionType() {
215
'Functions are not valid as a React child. This may happen if ' +
216
'you return a Component instead of <Component /> from render. ' +
217
'Or maybe you meant to call this function rather than return it.' +
218
- (getCurrentFiberStackInDevOrNull() || '');
218
+ getCurrentFiberStackInDev();
219
220
if (ownerHasFunctionTypeWarning[currentComponentErrorInfo]) {
221
return;
@@ -227,7 +227,7 @@ function warnOnFunctionType() {
227
'Functions are not valid as a React child. This may happen if ' +
228
'you return a Component instead of <Component /> from render. ' +
229
'Or maybe you meant to call this function rather than return it.%s',
230
- getCurrentFiberStackInDevOrNull() || '',
230
+ getCurrentFiberStackInDev(),
231
);
232
}
233
@@ -719,7 +719,7 @@ function ChildReconciler(shouldTrackSideEffects) {
719
'duplicated and/or omitted — the behavior is unsupported and ' +
720
'could change in a future version.%s',
721
key,
722
- getCurrentFiberStackInDevOrNull(),
722
+ getCurrentFiberStackInDev(),
723
);
724
break;
725
default:
@@ -912,7 +912,7 @@ function ChildReconciler(shouldTrackSideEffects) {
912
'Using Maps as children is unsupported and will likely yield ' +
913
'unexpected results. Convert it to a sequence/iterable of keyed ' +
914
'ReactElements instead.%s',
915
- getCurrentFiberStackInDevOrNull(),
915
+ getCurrentFiberStackInDev(),
916
);
917
didWarnAboutMaps = true;
918
}
packages/react-reconciler/src/ReactCurrentFiber.js
+4
-4
@@ -66,16 +66,16 @@ export function getCurrentFiberOwnerNameInDevOrNull(): string | null {
66
return null;
67
}
68
69
-export function getCurrentFiberStackInDevOrNull(): string | null {
69
+export function getCurrentFiberStackInDev(): string {
70
if (__DEV__) {
71
if (current === null) {
72
- return null;
72
+ return '';
73
}
74
// Safe because if current fiber exists, we are reconciling,
75
// and it is guaranteed to be the work-in-progress version.
76
return getStackByFiberInDevAndProd(current);
77
}
78
- return null;
78
+ return '';
79
}
80
81
export function resetCurrentFiber() {
@@ -88,7 +88,7 @@ export function resetCurrentFiber() {
88
89
export function setCurrentFiber(fiber: Fiber) {
90
if (__DEV__) {
91
- ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDevOrNull;
91
+ ReactDebugCurrentFrame.getCurrentStack = getCurrentFiberStackInDev;
92
current = fiber;
93
phase = null;
94
}
packages/react-reconciler/src/ReactFiberBeginWork.js
+2
-2
@@ -675,7 +675,7 @@ function mountIndeterminateComponent(
675
'Stateless function components cannot be given refs. ' +
676
'Attempts to access this ref will fail.%s%s',
677
info,
678
- ReactCurrentFiber.getCurrentFiberStackInDevOrNull(),
678
+ ReactCurrentFiber.getCurrentFiberStackInDev(),
679
);
680
}
681
}
@@ -933,7 +933,7 @@ function updateContextProvider(current, workInProgress, renderExpirationTime) {
933
newProps,
934
'prop',
935
'Context.Provider',
936
- ReactCurrentFiber.getCurrentFiberStackInDevOrNull,
936
+ ReactCurrentFiber.getCurrentFiberStackInDev,
937
);
938
}
939
}
packages/react-reconciler/src/ReactFiberContext.js
+2
-2
@@ -96,7 +96,7 @@ function getMaskedContext(
96
context,
97
'context',
98
name,
99
- ReactCurrentFiber.getCurrentFiberStackInDevOrNull,
99
+ ReactCurrentFiber.getCurrentFiberStackInDev,
100
);
101
}
102
@@ -205,7 +205,7 @@ function processChildContext(fiber: Fiber, parentContext: Object): Object {
205
// context from the parent component instance. The stack will be missing
206
// because it's outside of the reconciliation, and so the pointer has not
207
// been set. This is rare and doesn't matter. We'll also remove that API.
208
- ReactCurrentFiber.getCurrentFiberStackInDevOrNull,
208
+ ReactCurrentFiber.getCurrentFiberStackInDev,
209
);
210
}
211
packages/react/src/ReactDebugCurrentFrame.js
+4
-4
@@ -11,14 +11,14 @@ const ReactDebugCurrentFrame = {};
11
12
if (__DEV__) {
13
// Component that is being worked on
14
- ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string | null));
14
+ ReactDebugCurrentFrame.getCurrentStack = (null: null | (() => string));
15
16
- ReactDebugCurrentFrame.getStackAddendum = function(): string | null {
16
+ ReactDebugCurrentFrame.getStackAddendum = function(): string {
17
const impl = ReactDebugCurrentFrame.getCurrentStack;
18
if (impl) {
19
- return impl();
19
+ return impl() || '';
20
}
21
- return null;
21
+ return '';
22
};
23
}
24
packages/react/src/ReactElementValidator.js
+2
-2
@@ -74,7 +74,7 @@ if (__DEV__) {
74
owner && getComponentName(owner),
75
);
76
}
77
- stack += ReactDebugCurrentFrame.getStackAddendum() || '';
77
+ stack += ReactDebugCurrentFrame.getStackAddendum();
78
return stack;
79
};
80
}
@@ -324,7 +324,7 @@ export function createElementWithValidation(type, props, children) {
324
info += getDeclarationErrorAddendum();
325
}
326
327
- info += getStackAddendum() || '';
327
+ info += getStackAddendum();
328
329
let typeString;
330
if (type === null) {