-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
WIP: Custom Attribute and Preferring Attribute Names over Properties Spike #10229
Conversation
@@ -1,2 +1 @@ | |||
src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js | |||
* gives source code refs for unknown prop warning for exact elements in composition (ssr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey look, I fixed the final Fiber warning. 🙄
9b4f03d
to
551bf47
Compare
scripts/fiber/tests-passing.txt
Outdated
* renders unknown attributes with server stream render | ||
* renders unknown attributes with clean client render | ||
* renders unknown attributes with client render on top of good server markup | ||
* renders unknown attributes with client render on top of bad server markup | ||
* renders unknown data- attributes with server string render | ||
* renders unknown data- attributes with server stream render | ||
* renders unknown data- attributes with clean client render |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is misleading. I've skipped some tests related to the unknown attribute list and ARIA rules. I think we could enable these again by moving the attributes we eliminate from the whitelist over to the attribute warning hooks.
@@ -22,189 +22,48 @@ var HAS_OVERLOADED_BOOLEAN_VALUE = | |||
DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE; | |||
|
|||
var HTMLDOMPropertyConfig = { | |||
isCustomAttribute: RegExp.prototype.test.bind( | |||
new RegExp('^(data|aria)-[' + DOMProperty.ATTRIBUTE_NAME_CHAR + ']*$'), | |||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about the performance difference with this gone.
security: 0, | ||
// IE-only attribute that controls focus behavior | ||
unselectable: 0, | ||
value: 0, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As small as this list is now: I can't help but wonder if we could manually write out the property info listings instead of enumerating over them on boot. In particular:
- What does this look like post gzip?
- How does this improve initial bootup?
55dd067
to
d7674b1
Compare
An interesting side effect of this is you no longer get helpful errors about attributes being spelt wrong yeah? I've always quite enjoyed that react does that especially for weirdness like |
@jquense WIP! I think it would be great to maintain a manifest of all HTML attributes that we require inside I've also pushed a new update:
All in all, even if we manually specify all configuration options for every single attribute, the GZIP size ends up being rough the same (or a bit lower) than enumerating over individual lists. |
Please don't run the record-tests script. For... reasons. |
ac08795
to
befc818
Compare
xmlspace: 'xmlSpace', | ||
ychannelselector: 'yChannelSelector', | ||
zoomandpan: 'zoomAndPan' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jquense I think this should take care of attribute warning helpers. Though I'm going to work on ways to make this more concise :)
Hmm. Server tests fail, I think, because we removed the event plugins from server rendering, so they don't know what attribute names are events. Now that there's no whitelist to stop So this check is out of date: @gaearon I think I'm getting those lovey warnings you just added. Would you consider this a separate bug? It looks like that condition is checking for no reason. I'll do some more digging and possibly file an issue |
Which warnings? |
@gaearon I'm possibly wrong, sorry for the noise if so:
|
Configures DOMPropertyOperations to allow all attributes to pass through. It maintains the whitelist only for attributes that need special behavior. - Lowercase props during static markup generation - Remove ARIA property config - Migrate over a few more SVG properties to the warning list - Migrate over rules for DOM Fiber. Update tests - Address test failure after rebase - Move event filter to top level condition in property loop - Handle newer fiber and server test updates - Add complete original whitelist to UnknownDOMPropertyHook - Use default warning count for SSR property warning tests - Prevent warnings for property names that are already correct - Add full SVG property list to ReactDOMUnknownPropertyHook Revert property lists, add custom attribute feature flag Turns out I had this backwards. This commit reverts the slash and burn of the property configs and replaces the custom attribute checks with a new predicate on DOMProperty that determines if an attribute may be written. - Properly control for custom attributes in ReactDOMFiberComponent
- Removes the entire ARIA config - Ignores ARIA tests - Ignores some missing attribute tests - Ignores DOM feature flag tests - Consolidate property configs. - Eliminate the need to enumerate over property lists - Simplify operations
befc818
to
af60ced
Compare
Build passes with minor modifications to the test suite for custom attributes. I'm happy with this as a proof of concept. Next I'll do some analysis (I've also updated the description with an outline and initial thoughts). |
|
// Do not assign reserved properties or functions. Event handlers should | ||
// not exist in markup. | ||
isWriteable(name, value) { | ||
return !DOMProperty.isReservedProp(name) && typeof value !== 'function'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof value === 'function'
prevents properties with a function value type from being written to markup. Chances are that this isn't great. I'm working through how we might better track allowed event handlers and omit them for server renders (this could probably be PR'ed separately to master if someone else doesn't get to it first)
Do not merge this PR.
This is a work in progress PR to investigate the outcome of aggressively removing entries in the attributes lists and moving over to preferring attribute names over properties. My goals are:
className
andclass
)I'm probably missing a few more, but I thought it might be neat to track this progression on Github.
Performance improvements (still TBD)
There are two factors I see: startup time and attribute generation time.
This PR avoids enumerating over a big list of properties at startup, but that process is pretty fast. More time is actually spent enumerating over the event list in SimpleEventPlugin. I'm seeing DOM property injection take from 1.5 to 2 milliseconds. Cutting 2ms isn't huge, but I'll try to get some better numbers.
Build size differences
Even with manually listing out the properties that we need special behavior for, there's still some savings:
ReactDOM his -6% gzipped. Pretty healthy cut. The server build drops by 30% in size, which isn't all that grand but fun to say at least 😄.
Improvement to authoring
TBD
Edge cases
TBD
Migration path for libraries
TBD