react icon indicating copy to clipboard operation
react copied to clipboard

value|defaultValue={Symbol|Function} should be ignored, not stringified

Open gaearon opened this issue 7 years ago β€’ 88 comments

Regression in master from https://github.com/facebook/react/pull/11534. Found it thanks to the attribute fixture snapshots.

gaearon avatar Dec 01 '17 01:12 gaearon

Just for clarity: This is the correct behavior for Symbols:

screen shot 2017-11-30 at 8 22 43 pm

With my change, value and defaultValue never pass through the property sanitation layer. React tries to stringify symbols, which throws an error, and functions get turned into "function () {}".

nhunzaker avatar Dec 01 '17 01:12 nhunzaker

Now that I looked at this again, the update codepath was already broken. This just made the initial code path match it. So this is actually an improvement. We should still get https://github.com/facebook/react/pull/11741 to completion to have consistent sane behavior, but IMO this is not as urgent as I thought at first.

gaearon avatar Dec 01 '17 19:12 gaearon

Is it resolved or can I start working on it?

Sorry new to open source

kanlanc avatar Jan 06 '18 13:01 kanlanc

I think the issue still exists, it’s just more consistent now

gaearon avatar Jan 06 '18 13:01 gaearon

just for reference how do you call dibs on a bug

kanlanc avatar Jan 06 '18 13:01 kanlanc

You got it

gaearon avatar Jan 06 '18 14:01 gaearon

Ping @highskillzz, do you still on this issue?

If not, I will take it, ok @gaearon :wink:

t4deu avatar Feb 01 '18 23:02 t4deu

Sure

kanlanc avatar Feb 02 '18 05:02 kanlanc

What's the status on this one? It doesn't seem like this has been resolved since there are no warnings on assigning symbols or functions to the defaultValue prop. Even found a few TODO-s in the ReactDOMInput test.

raunofreiberg avatar Mar 16 '18 15:03 raunofreiberg

Feel free to grab it. I don't know if it's fixed or not but it's worth checking.

gaearon avatar Aug 09 '18 17:08 gaearon

@gaearon is this still open? if so, how do i claim it?

krrishdholakia avatar Aug 10 '18 10:08 krrishdholakia

@krrishdholakia Yes this is still up for grabs if it is not already fixed! Feel free to start looking into it and reach out if you have any issues along the way. 😊

philipp-spiess avatar Aug 10 '18 10:08 philipp-spiess

I checked earlier and I might be wrong but I'm quite sure this was fixed earlier by @nhunzaker

// Same goes for the `value` prop
return (
      <div>
        <input defaultValue={Symbol("test")} />
        <input defaultValue={() => {}} />
      </div>
);

produces

image

Which indicates that both symbols and functions are not stringified? I've still went ahead and added warnings for the defaultValue prop in #13360. Maybe useful.

raunofreiberg avatar Aug 10 '18 10:08 raunofreiberg

Although, textarea seems to behave differently - not sure if intentionally or not.

function App() {
  return (
    <div>
      <textarea defaultValue={() => {}} />
      <textarea value={() => {}} />
      <textarea value={Symbol("test")} />
    </div>
  );
}

Both functions get stringified and appended as text into the textarea itself. The symbol itself crashes the application with a TypeError: Cannot convert a Symbol value to a string

For reproducing: https://codesandbox.io/s/pj40nrp5px

raunofreiberg avatar Aug 10 '18 10:08 raunofreiberg

@raunofreiberg Thanks for looking into that! I agree that textarea should behave the same πŸ‘

philipp-spiess avatar Aug 10 '18 17:08 philipp-spiess

This looks perfect now. Thank you very much πŸ™‚ If you want a follow-up task, you could work on the same fix for elements.

@philipp-spiess Do you mean working on the select tag πŸ™‚? If so, I'd be happy to investigate further on that as well.

raunofreiberg avatar Aug 14 '18 09:08 raunofreiberg

Whoops. Yeah the select tag 😊 I forgot to escape the HTML.

Perfect - thank you!

philipp-spiess avatar Aug 14 '18 10:08 philipp-spiess

@raunofreiberg any remaining work that you know of here?

nhunzaker avatar Aug 14 '18 17:08 nhunzaker

Input, textarea and select are now covered. I can't think of any other form elements where these attributes might be an issue. Should be all good.

raunofreiberg avatar Aug 14 '18 17:08 raunofreiberg

Right on. Thanks for all of your contributions!

nhunzaker avatar Aug 14 '18 17:08 nhunzaker

Can somebody please update the attribute table?

https://github.com/facebook/react/tree/master/fixtures/attribute-behavior

Run the fixture, save the Markdown file and put it in the same folder.

gaearon avatar Aug 14 '18 17:08 gaearon

Ack. I'll send out a new snapshot shortly.

nhunzaker avatar Aug 14 '18 17:08 nhunzaker

PR sent out. Looks like SSR still needs to be covered for textareas and options:

image

nhunzaker avatar Aug 14 '18 18:08 nhunzaker

Hi guys is this issue still open or is someone already working on it?

code4cake avatar Sep 05 '18 10:09 code4cake

@dantesolis: @nhunzaker is working on it, check out: https://github.com/facebook/react/pull/13394 We're also probably gonna revisit the behavior here (https://github.com/facebook/react/issues/13508). I'm going to remove the "good first issue" label for now to avoid future confusion.

philipp-spiess avatar Sep 05 '18 10:09 philipp-spiess

@philipp-spiess thanks, are there any other "good first issues" that I could pick up? thanks

code4cake avatar Sep 07 '18 10:09 code4cake

@dantesolis You can look for good first issue (taken) and see if there was recent activity. If not, you can usually work on them. In our contribution guides we mention a 2 week period before others can start working on the issue as well.

I also think you can take a look at https://github.com/facebook/react/issues/11299. As far as I know there is still at least one test that uses private API and is not tackled by a community member (ReactErrorUtils-test.internal.js).

What's also great is if you can improve our test or type coverage. You'd need to research how to find uncovered lines since I don't have a solution for that right now but Jest comes with a coverage tool which might be helpful.

Let me know if you're stuck with any of the above steps. πŸ™‚

philipp-spiess avatar Sep 07 '18 10:09 philipp-spiess

@philipp-spiess then I would be giving issue-12548 a try, since I think someone already asked for #11299 before me, but I'll also keep an eye open for that one. Thanks.

About adding coverage, yes, jest comes with coverage. I'll check that one as well. ;)

code4cake avatar Sep 10 '18 10:09 code4cake

is it solved ?

kambleaa007 avatar Aug 07 '19 11:08 kambleaa007

What ever happened to this?

caelinsutch avatar May 21 '20 04:05 caelinsutch

I can work on that task? What is needed to finish that task?

ktfth avatar Mar 30 '21 01:03 ktfth

Can i look at it? And what is guidelines for contributing? I am new to open source.

axaysushir avatar May 01 '21 10:05 axaysushir

Can I take this issue up?

sebuelias avatar May 16 '21 13:05 sebuelias

I'm going to work on this issue. If you are already working on it, please let me know!

reez12g avatar Jul 21 '21 07:07 reez12g

@bvaughn hi I am new here but I want to solve it.

Madanaa avatar Aug 19 '21 13:08 Madanaa

function App() { return (

<textarea defaultValue={() => {}} /> <textarea value={() => {}} /> <textarea value={Symbol("test")} />
); }

Pankajadhana97-bit avatar Aug 20 '21 17:08 Pankajadhana97-bit

@bvaughn Can i take it, will complete in a week?

Mukulbaid63 avatar Oct 26 '21 12:10 Mukulbaid63

Sure.

bvaughn avatar Oct 26 '21 13:10 bvaughn

Hi,

@bvaughn may I now take this? I have examined the code and I believe I've come up with a potential solution

mdanyalkhan avatar Nov 23 '21 20:11 mdanyalkhan

Sure.

bvaughn avatar Nov 24 '21 16:11 bvaughn

This problem has been resolved??

ibandim123 avatar Nov 30 '21 15:11 ibandim123

Hey! I've set up a PR to address the issue (SSR side for option elements) https://github.com/facebook/react/pull/22841, @bvaughn or anyone else in the React team, let me know your thoughts!

mdanyalkhan avatar Dec 05 '21 15:12 mdanyalkhan

@philipp-spiess @bvaughn Hi guys, what's the latest status of this PR? Is it still open? I was trying out for both

michaelCHU95 avatar Dec 28 '21 07:12 michaelCHU95

hey @philipp-spiess is this issue still unresolved , I am new to open source and I would like to give it a try

AK1304 avatar Jan 18 '22 04:01 AK1304

please let me know some good first issues that I can work on as I am new to open source

AK1304 avatar Jan 18 '22 05:01 AK1304

I believe mdanyalkhan solved it in his PR https://github.com/facebook/react/pull/22841.

cesarvargas00 avatar Feb 03 '22 04:02 cesarvargas00

@gaearon can I start working on this.

its-kunal avatar Mar 14 '22 01:03 its-kunal

Hello, I am Nelson, I am new here and I want to work on the first issue but I need someone to guide me.

EngNelson avatar Apr 09 '22 00:04 EngNelson

Can we close this issue?

marcuszierke avatar May 03 '22 20:05 marcuszierke

Couldn't understand. Is this one still an issue for fixed before? Confused πŸ™„

sowrovsec avatar May 19 '22 17:05 sowrovsec

is this issue opened???

darkknight20032001 avatar Jun 19 '22 23:06 darkknight20032001

Hey is this issued still open because i am interested to resolve it...?

tejassinghsital avatar Jul 10 '22 11:07 tejassinghsital

Hi , Is this issue still open, interested to work on it.

poojavirgo avatar Jul 13 '22 04:07 poojavirgo