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.
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. |
…st of whitelist. (react#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
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)