Skip to content

Commit fc18ebc

Browse files
committed
Change formatMessage parameter to getStack
Gives us flexibility in the future to deal with the stack and the message separately.
1 parent 00a64eb commit fc18ebc

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/isomorphic/classic/types/checkPropTypes.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ var loggedTypeFailures = {};
2626
* @param {object} values Runtime values that need to be type-checked
2727
* @param {string} location e.g. "prop", "context", "child context"
2828
* @param {string} componentName Name of the component for error messages.
29-
* @param {?Function} formatMessage Function that transforms the error message, to add additional info.
29+
* @param {?Function} getStack Returns the component stack.
3030
* @private
3131
*/
32-
function checkPropTypes(typeSpecs, values, location, componentName, formatMessage) {
32+
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
3333
for (var typeSpecName in typeSpecs) {
3434
if (typeSpecs.hasOwnProperty(typeSpecName)) {
3535
var error;
@@ -68,13 +68,14 @@ function checkPropTypes(typeSpecs, values, location, componentName, formatMessag
6868
// same error.
6969
loggedTypeFailures[error.message] = true;
7070

71-
var message = formatMessage ? formatMessage(error.message) : error.message;
71+
var stack = getStack ? getStack() : '';
7272

7373
warning(
7474
false,
75-
'Failed %s type: %s',
75+
'Failed %s type: %s%s',
7676
location,
77-
message,
77+
error.message,
78+
stack,
7879
);
7980
}
8081
}

src/shared/types/checkReactTypeSpec.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,32 @@ function checkReactTypeSpec(
3838
// only during reconciliation (begin and complete phase).
3939
workInProgressOrDebugID
4040
) {
41-
function formatMessage(message) {
41+
function getStack() {
42+
let stack = '';
4243
if (__DEV__) {
43-
let componentStackInfo = '';
4444
if (!ReactComponentTreeHook) {
4545
ReactComponentTreeHook = require('ReactComponentTreeHook');
4646
}
4747
if (workInProgressOrDebugID != null) {
4848
if (typeof workInProgressOrDebugID === 'number') {
4949
// DebugID from Stack.
5050
const debugID = workInProgressOrDebugID;
51-
componentStackInfo = ReactComponentTreeHook.getStackAddendumByID(debugID);
51+
stack = ReactComponentTreeHook.getStackAddendumByID(debugID);
5252
} else if (typeof workInProgressOrDebugID.tag === 'number') {
5353
// This is a Fiber.
5454
// The stack will only be correct if this is a work in progress
5555
// version and we're calling it during reconciliation.
5656
const workInProgress = workInProgressOrDebugID;
57-
componentStackInfo = ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
57+
stack = ReactComponentTreeHook.getStackAddendumByWorkInProgressFiber(workInProgress);
5858
}
5959
} else if (element !== null) {
60-
componentStackInfo = ReactComponentTreeHook.getCurrentStackAddendum(element);
60+
stack = ReactComponentTreeHook.getCurrentStackAddendum(element);
6161
}
62-
message += componentStackInfo;
6362
}
64-
return message;
63+
return stack;
6564
}
6665

67-
checkPropTypes(typeSpecs, values, location, componentName, formatMessage);
66+
checkPropTypes(typeSpecs, values, location, componentName, getStack);
6867
}
6968

7069
module.exports = checkReactTypeSpec;

0 commit comments

Comments
 (0)