Skip to content

Commit a27c6d1

Browse files
sebmarkbagezpao
authored andcommitted
Always use a static message formats
These are the only places that seems to be including environment specific variables in the message format. By ensuring that they're static, we make it easier to group logs by format. I also ensure that I keep each addendum separate so that they can be filtered/grouped separately.
1 parent 4bad1aa commit a27c6d1

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/classic/element/ReactElementValidator.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,30 @@ function warnAndMonitorForKeyUse(message, element, parentType) {
146146
}
147147
memoizer[useName] = true;
148148

149-
message +=
149+
var parentOrOwnerAddendum =
150150
ownerName ? ` Check the render method of ${ownerName}.` :
151151
parentName ? ` Check the React.render call using <${parentName}>.` :
152152
'';
153153

154154
// Usually the current owner is the offender, but if it accepts children as a
155155
// property, it may be the creator of the child that's responsible for
156156
// assigning it a key.
157+
var childOwnerAddendum = '';
157158
if (element &&
158159
element._owner &&
159160
element._owner !== ReactCurrentOwner.current) {
160161
// Name of the component that originally created this child.
161162
var childOwnerName = getName(element._owner);
162163

163-
message += ` It was passed a child from ${childOwnerName}.`;
164+
childOwnerAddendum = ` It was passed a child from ${childOwnerName}.`;
164165
}
165166

166-
message += ' See http://fb.me/react-warning-keys for more information.';
167-
warning(false, message);
167+
warning(
168+
false,
169+
message + '%s%s See http://fb.me/react-warning-keys for more information.',
170+
parentOrOwnerAddendum,
171+
childOwnerAddendum
172+
);
168173
}
169174

170175
/**
@@ -248,7 +253,7 @@ function checkPropTypes(componentName, propTypes, props, location) {
248253
loggedTypeFailures[error.message] = true;
249254

250255
var addendum = getDeclarationErrorAddendum(this);
251-
warning(false, 'Failed propType: ' + error.message + addendum);
256+
warning(false, 'Failed propType: %s%s', error.message, addendum);
252257
}
253258
}
254259
}

src/core/ReactCompositeComponent.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,16 @@ var ReactCompositeComponentMixin = {
449449
// Preface gives us something to blacklist in warning module
450450
warning(
451451
false,
452-
'Failed Composite propType: %s',
453-
error.message + addendum
452+
'Failed Composite propType: %s%s',
453+
error.message,
454+
addendum
454455
);
455456
} else {
456457
warning(
457458
false,
458-
'Failed Context Types: %s',
459-
error.message + addendum
459+
'Failed Context Types: %s%s',
460+
error.message,
461+
addendum
460462
);
461463
}
462464
}

0 commit comments

Comments
 (0)