Skip to content

Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist.#10385

Merged
flarnie merged 49 commits into
masterfrom
nh-gut-whitelist
Aug 15, 2017
Merged

Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist.#10385
flarnie merged 49 commits into
masterfrom
nh-gut-whitelist

Conversation

@nhunzaker

@nhunzaker nhunzaker commented Aug 4, 2017

Copy link
Copy Markdown
Contributor

Follow-up work from #7311. This PR implements scenario 2 for custom attributes, as described in #7311 (comment).

  1. Badly cased attribute names still write to the DOM.
  2. Cases like classname, htmlfor, and arabicform, do not alias. They write as classname, htmlfor, and arabicform.
  3. All attribute whitelist entries that enforce a specific casing have been removed.
  4. The ARIA whitelist has been moved to a developer-only enforcement (but the logic is the same as master)

Build size:

react-dom.production.min.js: 109.01kb (34.40kb gz)

screen shot 2017-08-07 at 10 33 16 am

@gaearon

gaearon commented Aug 4, 2017

Copy link
Copy Markdown
Collaborator

: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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: explicitly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

srcLang: 0,
srcSet: 0,
// Style must be explicitely set in the attribute list. React components
// expect a style object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes! Yes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3a50c07

@gaearon

gaearon commented Aug 4, 2017

Copy link
Copy Markdown
Collaborator

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.)

@nhunzaker

Copy link
Copy Markdown
Contributor Author

My testing could be more exhaustive. I'll make a test page.

label: 0,
lang: 0,
list: 0,
loop: HAS_BOOLEAN_VALUE,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything special about it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack! This is a mistake 😢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added back in a218130

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is still missing in the latest version here, unless I'm missing something?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent questions. I will verify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now we're okay with doing whatever we used to be doing.

@nhunzaker nhunzaker changed the title Remove remaining entries in whitelist that are only needed for developer warnings Custom Attributes Scenario 2 Aug 7, 2017
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: implements

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man I need a git commit hook for impliments. Every. Single. Time. Fixed in aaafa7f

@nhunzaker nhunzaker changed the title Custom Attributes Scenario 2 Custom Attributes Scenario 1: Write badly cased attributes. Remove most of whitelist. Aug 7, 2017
@nhunzaker nhunzaker changed the title Custom Attributes Scenario 1: Write badly cased attributes. Remove most of whitelist. Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. Aug 7, 2017

return DOMProperty.properties.hasOwnProperty(lowerCased)
? DOMProperty.properties[lowerCased]
: null;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I want to try it. I'll take 5.


if (DOMPropertyNames.hasOwnProperty(propName)) {
propertyInfo.propertyName = DOMPropertyNames[propName];
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOMPropertyNames is not used by any injection.

gaearon
gaearon previously requested changes Aug 7, 2017

@gaearon gaearon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out if this is a boolean attribute or not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just discovered this page. True life saver.

ascent: 0,
attributeName: 'attributeName',
attributeType: 'attributeType',
autoReverse: 'autoReverse',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one either.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not in the spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh fun.

hanging: 0,
horizAdvX: 'horiz-adv-x',
horizOriginX: 'horiz-origin-x',
ideographic: 0,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a value for dominantBaseline, and I can't find a description of it anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha :-) It's a bit tough to find.

@gaearon

gaearon commented Aug 8, 2017

Copy link
Copy Markdown
Collaborator

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.

@nhunzaker

nhunzaker commented Aug 8, 2017

Copy link
Copy Markdown
Contributor Author

@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
  • externalResourcesRequired
  • preserveAlpha

autoReverse is technically from SMIL. I'll browse through and see if we aren't missing anything.

@nhunzaker

Copy link
Copy Markdown
Contributor Author

SMIL state module defines a few more:
https://www.w3.org/TR/smil/smil-DTD.html

  • 'skipContent'
  • 'external'
  • 'syncMaster'

I think that's it.

@gaearon
gaearon deleted the nh-gut-whitelist branch October 6, 2017 21:57
mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants