-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Can't update 'checked' attribute #6321
Comments
I can't reproduce this (or maybe am misunderstanding what you're saying). https://jsfiddle.net/rkc64ybp/ is showing that the node is unchecked in the DOM. You might run into issues if you use |
@zpao I believe he means that, even after unchecking it, the Chrome |
Yes, that is what I meant, sorry if it wasn't clear. I tried Firefox and Chrome. A screenshot of the fiddle with the debugger showing The strange thing is that indeed The contrary effect is also true: I have initially unchecked inputs that never get the |
Ah, I see. The attribute is set but the property isn't. That will be solved in v15 where we will remove the attribute instead of just setting the property to false. See https://jsfiddle.net/rkc64ybp/1/ (same code, just with |
@zpao should React add the |
That's a good question… @syranide - was there any discussion about that? |
@zpao There was/is a separate discussion about inputs and value somewhere else (cc @spicyj). I'm not sure where it ended up but it was about going away from the native behavior seen here to actively update the attribute in the DOM (EDIT: perhaps not intentionally, but that was the result). However, it should be noted that the behavior seen here is expected behavior, you get this behavior with native checkboxes as well; the |
Ah, I did not know that it was the native behavior... Then it is not a React issue at all, and I don't think React should try to have a different behavior. That sucks though, it means for instance that one should never use the |
@muraveill I would assume |
Once again, I'll repeat that it does not make sense to talk about the native behavior here. That is, HTML does not have a concept of going from
to
We created this concept. In HTML, you can do a property assignment ( We can decide for any of these to be the behavior that React matches. None of them is the objectively correct "native behavior" so it's misleading to talk as if that were the case. It seems like setting the attribute is least confusing for people in most cases (so that both |
I still don't buy it, the specification explicitly states that the attribute reflects the initial value and the property reflects the current value. So if you check it without any additional scripting applied, this is the behavior you get, you're also meant to generally update it via Anyway, I don't want to derail this. |
Why are you "meant to" update it with the property? |
If you want to simulate user input/filter/normalize/etc then you use the property so you don't change the initial value. If you want to replace the value (i.e. changing data source) then you use the attribute (similar to setting the key in React), you're "resetting" the checkbox in a sense. Again I agree this differentiation doesn't really work well in React (and there's no good reason to), but there is a difference. I don't really mind, it doesn't really have any major implications, but it is clearly different from plain IMHO. |
Conceptually, upon every change, we throw away the entire page and rerender from scratch. Ideally, the output of an initial render should be identical to the output of an initial render followed by an update render, assuming the final state is the same. |
@jimfb Yes, but it's a partial truth, inputs also have focus, selection, undo history, etc and in the context of this discussion, they also have an initial value that is reflected in the attribute. We currently control the lifetime of internal and external state via |
had a breaking change in one of my unit test suites regarding this issue when upgrading from 0.14 -> 0.15...I built a custom checkbox component that wraps an |
I agree with @rovolution. I see similar case in my code, I use radio inputs like this (a few of them):
on every change value of
what means the way you render on the server is different than on the client. |
@krzysu |
yes, I know that, but that happens only after upgrading to react v15. so the way new react is rendering inputs is different between client and server, and that's why I'm writing here. |
@krzysu I'm unable to reproduce this myself. Rendering a checked radio input on the server and then resuming on the client works just fine for me, no mismatch error. |
ok, I will try to prepare an example which reproduces it |
ok, so my issue is different that the one from @rovolution @syranide as promised, I extracted my code into a reproducible example, which you can find here https://github.com/krzysztofurbas-home24/react15-input-checked-issue. |
@krzysu 👍 Are you using npm3? npm2 has a problem with its hierarchical dependencies such that some plugins may depend on older versions of React and have those be installed side-by-side. They are not compatible and will generate slightly different markup which can cause the problem seen above, which I also find likely considering that the subsequent attributes are not even the same (order) in client/server output warning. This generally shows itself differently in my experience, so who knows, but some external versioning conflict obviously. |
@rovolution from component.jsx
to html
When I click checkbox, It has been changed checked property internally. But the checked attribute |
please helpe me
Στις 12:20 π.μ. Τετάρτη, 26 Απριλίου 2017, ο/η Marko Stijak <notifications@github.com> έγραψε:
I'm seeing the same problem in all browsers. Unfortunately, it's difficult to extract a smaller example reproducing the issue.
My workaround is to assign a different key based on the value, but I really hate it.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
εγκατεστησα αυτο το προγραμμα γ να βλεπω κωδικους κ διαφορα αλλα δν ξερω τι να καν απο δω κ περα.εχω κανει προφιλ .βλεπω το πλαισιο ( κωδικο θεματα αποθετηρια κ ολα τα υπολοιπα αλλα εγω δν ξερω τιποτα που να παω κ πως να δω τους κωδικους κ ολα τα αλλα ειμαι ελληνιδα κ μου ειναι δυσκολο το προγγραμμα ειναι στα αγγλικα μπορεις να με βοηθησεις?
Στις 12:20 π.μ. Τετάρτη, 26 Απριλίου 2017, ο/η Marko Stijak <notifications@github.com> έγραψε:
I'm seeing the same problem in all browsers. Unfortunately, it's difficult to extract a smaller example reproducing the issue.
My workaround is to assign a different key based on the value, but I really hate it.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I’ll close since there’s a few different things discussed here, and it’s hard for me to say what’s the status on either of them. Please file a new issue with a reproducing example if you still experience problems related to this. |
Consider this input:
If the first time the component is rendered,
this.state.value === '1'
, then this input will remainchecked
forever in the DOM, even if it appears unchecked visually. For instance this can happen withI am using React 0.14.7.
The text was updated successfully, but these errors were encountered: