-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Cased data attributes should properly diff on server hydration #10394
Conversation
Added an extra test case for |
What causes them to become lowercase in the first place? Is it per HTML spec or something? |
Attribute names are case-insensitive in the HTML-standard and according to MDN are always lower-cased. So perhaps we should even warn when trying to emit them? Also FYI, |
This sounds good to me, but does this means we can never get rid of SVG whitelist? Or is there some other solution that lets us enforce lowercase attributes except SVG? |
@gaearon I'm not super read-up on all this, but it seems like standard HTML and the special namespaces obide by two different rule sets. HTML is a large collection of special-cases (self-closing void elements being one obvious) so I don't think you can ever be free of it all. |
Sorry for the delay. I wanted to figure a few things out between this PR and #7311 SVG reads case-sensitive, but it doesn't care about authoring case sensitivity. Using the following test: https://codepen.io/nhunzaker/pen/yogOXe?editors=1010 No matter what casing the attributes are written in, the browser transforms them into the correct casing no matter what. This is demonstrated by every browser I've tested:
I've tried to be as exhaustive as possible :).
Drawing from this:
Specific to this issue, I think we should always compare attributes in a case insensitive way when diffing properties. Inconsistent casing should be a developer warning handled by React during the rendering process, not the diffing process. |
Sorry, additionally, if we don't make the diffing process case-insensitive, we need to figure out a way to reconcile the all caps reporting issues in IE Edge. |
I pushed a commit that downcases the DOM attribute name reference (480e41f). I think this has to be manually tested to ensure IE Edge properly hydrates SSR SVG. I can work on that later today. If we merge either #10397 or #10385, this PR can go away. Case-insensitive diffing is necessary for custom attributes with uppercase letters. |
IE Edge reports some SVG attributes, like stroke and fill, in all caps. This commit downcases all attribute names so that comparison when diffing is case in-sensitive.
480e41f
to
338cc0a
Compare
Assuming it sticks, the custom attribute pr overlapped with this one: Closing this out. |
@gaearon noticed this in my custom attribute PR (#7311 (comment))
Attribute names are reported back from the DOM as lower case. If a cased data attribute is given, the diffing process gets tripped up because a propKey of
data-myAttribute
reports back asdata-myattribute
. This results in an error along the lines of:The diffing process compares the component props to a list of attributes directly from the DOM element. The DOM list always has lower case names. The React property object uses whatever was given to the component. So there's an inconsistency between the
data-myAttribute
React prop, and thedata-myattribute
from the DOM.This isn't a problem for attributes in the whitelist. When properties are injected into
DOMProperties.properties
, React adds anattributeName
that is the lower case version of the React prop key name. This attribute name is what gets removed from the list of diffed props.Also it looks like cased data attributes are technically supported in React 15.6.1:
https://jsfiddle.net/84v837e9/185/
The casing goes away when the attribute is put into the DOM.