-
Notifications
You must be signed in to change notification settings - Fork 47.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: unintended .valueOf() maybe? #20594
Labels
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
Comments
dimaqq
added
the
Status: Unconfirmed
A potential issue that we haven't yet confirmed as a bug
label
Jan 15, 2021
Confirmed. @dimaqq do you want to put in a PR to fix it? You should be able to just change That change would result in this message:
|
rickhanlonii
pushed a commit
that referenced
this issue
Jan 20, 2021
koto
pushed a commit
to koto/react
that referenced
this issue
Jun 15, 2021
justingrant
added a commit
to justingrant/react
that referenced
this issue
Aug 16, 2021
Using the `+` operator to concatenate strings and objects is problematic because `+` calls `valueOf` which will throw for some types. See facebook#20594 for details. This commit globally replaces `'' + obj` with `''.concat(obj)`, which does the same thing but doesn't call `valueOf` before converting to a string. It also updates the code example in the lint rule that encouaged use of this problematic pattern.
justingrant
added a commit
to justingrant/react
that referenced
this issue
Aug 16, 2021
Using the `+` operator to concatenate strings and objects is problematic because `+` calls `valueOf` on the object. `valueOf` will throw for some types of objects. See facebook#20594 for details. This commit globally replaces `'' + obj` with `''.concat(obj)`, which does the same thing but doesn't call `valueOf` before converting to a string. It also updates the code example in the lint rule that encouaged use of this problematic pattern.
justingrant
added a commit
to justingrant/react
that referenced
this issue
Aug 16, 2021
Using the `+` operator to concatenate strings and objects is problematic because `+` calls `valueOf` on the object. `valueOf` will throw for some types of objects. See facebook#20594 for details. This commit globally replaces `'' + obj` with `''.concat(obj)`, which does the same thing but doesn't call `valueOf` before converting to a string. It also updates the code example in the lint rule that encouaged use of this problematic pattern.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While chasing tc39/proposal-temporal#1224 where I mistakenly pasted a
ZonedDateTime
into JSX, I discovered that:react-reconciler
doesn't like arbitrary objects (fair)throwOnInvalidObjectType
on such objects, source code of which looks completely fine†... "foo" + newChild + "bar" ...
‡valueOf()
objects in Consider using.valueOf()
before providing fragment warning. #4769.valueOf
(I'm ambivalent about that decision)†
react/packages/react-reconciler/src/ReactChildFiber.new.js
Lines 223 to 235 in 98313aa
‡ compiled to
throw Error( "Objects are not valid as a React child (found: " + (Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild) + "). If you meant to render a collection of children, use an array instead." );
So, react won't use
valueOf
to render an element, but will use it to report and error about an element.Maybe the "compilation" or interpolation of
invariant
is wrong?Or perhaps
%s
handling ininvariant
is wrong?Maybe my assumptions are wrong?
Maybe that type is wrong?
React version:
17.0.1
Steps To Reproduce
return <div>{ new Temporal.Instant(0n).toZonedDateTimeISO("Europe/Berlin") }</div>;
Link to code example: https://github.com/dimaqq/test-temporal
The text was updated successfully, but these errors were encountered: