Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist.#10385
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist.#10385
Conversation
|
:O |
| // Style must be explicitely set in the attribute list. React components | ||
| // expect a style object | ||
| start: HAS_NUMERIC_VALUE, | ||
| // Style must be explicitely set in the attribute list. React components |
| srcLang: 0, | ||
| srcSet: 0, | ||
| // Style must be explicitely set in the attribute list. React components | ||
| // expect a style object |
|
How did you verify the changes? Is it worth creating a test page with all these attributes to ensure their support didn’t regress? (At least once.) |
|
My testing could be more exhaustive. I'll make a test page. |
| label: 0, | ||
| lang: 0, | ||
| list: 0, | ||
| loop: HAS_BOOLEAN_VALUE, |
There was a problem hiding this comment.
Is there anything special about it?
There was a problem hiding this comment.
Ack! This is a mistake 😢
There was a problem hiding this comment.
Looks like this is still missing in the latest version here, unless I'm missing something?
There was a problem hiding this comment.
Oh I see it moved down.
| srcSet: 0, | ||
| start: HAS_NUMERIC_VALUE, | ||
| step: 0, | ||
| // Style must be explicitly set in the attribute list. React components |
There was a problem hiding this comment.
Is this a note about server renderer? I imagine we don't get into style branch on the client because there’s a hardcoded one earlier.
What about custom elements? Does style still work correctly on those? (And did it at all in the past?)
There was a problem hiding this comment.
Excellent questions. I will verify.
There was a problem hiding this comment.
I imagine we don't get into style branch on the client because there’s a hardcoded one earlier.
We don't get to the style branch, but we validate all properties here:
https://github.com/facebook/react/blob/master/src/renderers/dom/fiber/ReactDOMFiberComponent.js#L406
The UnknownPropertyHook calls DOMProperty.shouldSetAttribute and sees that the style property is using an object, so it warns. This check doesn't happen if the style property is in the attribute config.
So keeping style: 0 here prevents the warning.
What about custom elements? Does style still work correctly on those? (And did it at all in the past?)
What is the intended behavior of passing style to custom elements? Should it pass the value "as is", or provide style pre-processing? Right now it looks like it's sending down a style string.
There was a problem hiding this comment.
I think for now we're okay with doing whatever we used to be doing.
a218130 to
019de2b
Compare
| itemScope: HAS_BOOLEAN_VALUE, | ||
| // Facebook internal attribute. This is an object attribute that | ||
| // impliments a custom toString() method | ||
| // impliments a custom toString() method. Objects are not allowed as |
There was a problem hiding this comment.
Man I need a git commit hook for impliments. Every. Single. Time. Fixed in aaafa7f
|
|
||
| return DOMProperty.properties.hasOwnProperty(lowerCased) | ||
| ? DOMProperty.properties[lowerCased] | ||
| : null; |
There was a problem hiding this comment.
Just a final word here. In this scenario, all attributes are referenced as their lowercase form internally. I've hidden that within getPropertyInfo to avoid needing to know about lowercasing attributes outside of DOMProperty.js.
| zoomAndPan: 'zoomAndPan', | ||
| }; | ||
|
|
||
| var SVGDOMPropertyConfig = { |
There was a problem hiding this comment.
I feel like there's another step here where we could string manipulate xml:lang or vert-origin-y into camel-case, that might cut the overall gzip size.
There was a problem hiding this comment.
Ah I want to try it. I'll take 5.
aaafa7f to
d51ee9d
Compare
|
|
||
| if (DOMPropertyNames.hasOwnProperty(propName)) { | ||
| propertyInfo.propertyName = DOMPropertyNames[propName]; | ||
| } |
There was a problem hiding this comment.
DOMPropertyNames is not used by any injection.
gaearon
left a comment
There was a problem hiding this comment.
This is amazing work.
There's a (hopefully!) last change in semantics we need to make that I wrote about in #10399 (comment).
Thanks again for working through this! I really hope this is the last change we need to make. If not, I’ll try to address the rest myself tomorrow.
| additive: 0, | ||
| alignmentBaseline: 'alignment-baseline', | ||
| allowReorder: 'allowReorder', | ||
| alphabetic: 0, |
There was a problem hiding this comment.
I can't figure out if this is a boolean attribute or not.
There was a problem hiding this comment.
There was a problem hiding this comment.
I just discovered this page. True life saver.
| ascent: 0, | ||
| attributeName: 'attributeName', | ||
| attributeType: 'attributeType', | ||
| autoReverse: 'autoReverse', |
There was a problem hiding this comment.
There was a problem hiding this comment.
This is not in the spec.
| hanging: 0, | ||
| horizAdvX: 'horiz-adv-x', | ||
| horizOriginX: 'horiz-origin-x', | ||
| ideographic: 0, |
There was a problem hiding this comment.
This is a value for dominantBaseline, and I can't find a description of it anywhere.
There was a problem hiding this comment.
Number.
https://www.w3.org/TR/SVG/fonts.html#FontFaceElementIdeographicAttribute
Jeez Nate. Why don't you read the spec?
There was a problem hiding this comment.
There was a problem hiding this comment.
Haha :-) It's a bit tough to find.
|
We'll really need some automated way to test we didn't regress here (just once). I'm thinking maybe we could take all existing whitelists, make a page that renders all these properties with React 15, and then verify these values are still there with 16. I'll try to do it tomorrow. |
|
@gaearon Okay. This is not in a fully tested, and possibly not in a working state, but I've pushed up commits that add back what I believe are all the boolean properties. In addition to the ones you identified, I went through the entire SVG spec (okay okay I cmd + f'ed through it) and the only boolean SVG attributes I could find were:
autoReverse is technically from SMIL. I'll browse through and see if we aren't missing anything. |
|
SMIL state module defines a few more:
I think that's it. |
Follow-up work from #7311. This PR implements scenario 2 for custom attributes, as described in #7311 (comment).
arabicform, do not alias. They write asclassname,htmlfor, andarabicform.Build size:
react-dom.production.min.js: 109.01kb (34.40kb gz)