-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Attributes not removed when set to null on updates #1448
Comments
cc @sebmarkbage @benjamn @zpao
Some benchmarking shows that it's not as clear in practice, what's clear though is that all the slow browsers are enormously faster at dealing with properties, Properties being roughly 3 times faster than attributes with the mixed test roughly in the middle. But we're only really interested in removing attributes, so that leaves us with the current implementation being roughly 50-100% faster than Considering even poor IE8 can churn through 300.000 property assignments and attribute removes per second (or 5000 per frame at 60 FPS, IE9 can do 15000 per frame). Couple that with toggling between values and explicitly So it seems to me that, unless my tests are seriously flawed, that switching to Incidentally, this will also solve #1431 (in a preferable way even, perhaps). Percentages are relative to current implementation, 2nd vs 1st and 3rd vs 1st respectively. The op/s per second is total assignments + removes per second for the 1st column (2nd test). So unless we want to go all-out attributes, only the first column is of interest.
|
Proper implementation #1510 |
What is the consequence of leaving the DOM attribute there? Is it messing with your CSS rules? What is the end problem caused by leaving them in? |
@sebmarkbage As I mention in my PR, FF and Chrome are actually faster with the attribute methods. Although older browsers suffer slightly (still blazingly fast though). |
I think it might make sense to have several different code paths based on browser and/or the attribute used. Before committing to this as a permanent supported solution, I'd like to clarify that this is a common enough problem. There is another reason I'd like to treat React props as properties rather than attributes in general. HTML/SVG and Web Components doesn't allow complex types as attributes. To support complex types like style, class lists, custom user data, we prefer to model these as properties rather than attributes. If a property is inherently broken in the DOM (missing functionality) we can fix those on a case-by-case basis. Ideally the behavior of React props should correspond to DOM properties instead of DOM attributes. But in the end, we'll do whatever makes sense. |
@sebmarkbage My proposed solution only uses |
Just bringing in the reason it's a problem from my closed duplicate - when a link has an empty href it still takes focus. I can kind of sort out the style problems with extra css but it'll still get focus as you tab the focus through the controls on the page. |
@sebmarkbage |
I'm also running into the In practice, this means that our markdown editor isn't making things appear as non-links when they become invalid. I can't comment on the implementation or html properties vs attributes (yuck :( ), but this is surprising as a user. I'll probably just leave it and let it be confusing, but if this behaviour wasn't acceptable, working around it would be a bit painful (key the |
I decided to swap out the |
I have PR #1510 for this which seems rather safe (perhaps need to add a test for "property-only" properties), nag on @sebmarkbage a bit more and he might consider it. ;) |
Setting the href attribute to null created <a href /> meaning it was still an active link (see facebook/react#1448). So swapped the anchor for a span instead
Apparently the Things to note: The For now, my component has this in place: componentDidUpdate: function() {
if (!this.props.dir) {
this.getDOMNode().removeAttribute('dir');
}
} |
@ezequiel Ah good to know. |
I'm also getting bit by this, specifically for hrefs on anchor tags. Here is a minimal test case of the very unexpected behavior: https://jsfiddle.net/vsa3Ln40/1/ I'm happy to make the changes if the maintainers agree that the current behavior is unexpected enough to warrant a change. |
|
I opened a bug against the IE team for this: https://connect.microsoft.com/IE/feedbackdetail/view/1525237/removeattribute-slowness-compared-to-other-browsers Feel free to upvote it, all. |
Why React removes included attributes from any html tag autonomously? It can cause css selection problem :( |
The behavior of attributes with a value of
null
orundefined
is inconsistent. On first render they are not present on the element at all. On subsequent renders, the attribute sticks around with an empty value.For example,
<a href={null} />
renders what you expect (<a />
), but if the value ofhref
changes tonull
after the first render, you get<a href />
. In the case ofhref
(and likely others) an empty attribute has unintended side effects.See this fiddle: http://jsfiddle.net/pGG2A/1/
The text was updated successfully, but these errors were encountered: