Skip to content

Commit 2e948e0

Browse files
authored
Avoid .valueOf to close #20594 (#20617)
1 parent 2a646f7 commit 2e948e0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/react-reconciler/src/ReactChildFiber.new.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ function coerceRef(
222222

223223
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
224224
if (returnFiber.type !== 'textarea') {
225+
const childString = Object.prototype.toString.call(newChild);
225226
invariant(
226227
false,
227228
'Objects are not valid as a React child (found: %s). ' +
228229
'If you meant to render a collection of children, use an array ' +
229230
'instead.',
230-
Object.prototype.toString.call(newChild) === '[object Object]'
231+
childString === '[object Object]'
231232
? 'object with keys {' + Object.keys(newChild).join(', ') + '}'
232-
: newChild,
233+
: childString,
233234
);
234235
}
235236
}

packages/react-reconciler/src/ReactChildFiber.old.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ function coerceRef(
222222

223223
function throwOnInvalidObjectType(returnFiber: Fiber, newChild: Object) {
224224
if (returnFiber.type !== 'textarea') {
225+
const childString = Object.prototype.toString.call(newChild);
225226
invariant(
226227
false,
227228
'Objects are not valid as a React child (found: %s). ' +
228229
'If you meant to render a collection of children, use an array ' +
229230
'instead.',
230-
Object.prototype.toString.call(newChild) === '[object Object]'
231+
childString === '[object Object]'
231232
? 'object with keys {' + Object.keys(newChild).join(', ') + '}'
232-
: newChild,
233+
: childString,
233234
);
234235
}
235236
}

0 commit comments

Comments
 (0)