-
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
Allow custom attributes by default #7311
Conversation
Oh interesting. Looks like |
74d3eed
to
eda7235
Compare
Okay. I believe I've got this. I just had to downcase unrecognized properties during server rendering. Thoughts? |
eda7235
to
1f4108e
Compare
1f4108e
to
59800e6
Compare
59800e6
to
1d1b1ec
Compare
1d1b1ec
to
77aaa0e
Compare
I can't PR against another PR for the sake of review, but I've done the exact same thing for custom events: I think this might be all of the outstanding work for stripping away nearly all of the attribute whitelist. |
AFAIK the biggest blocker on this is internal callsites. We need to find places in FB code that still cause "unknown prop" warnings and clean them up. @spicyj Is that correct? |
Tagging just so we remember to go back to this and decide on it. |
Okay, awesome! Thanks for the update! |
77aaa0e
to
ddaf7ed
Compare
Yes, I think so. |
887f728
to
e0de616
Compare
Sorry to bug you on weekend, but is there any chance you could write up a summary of possible solutions with pros and cons of each? It’s still a bit hard for me to understand all the constraints involved here. The invariants I care about, in the order of importance:
Which solutions satisfy them, and what are the tradeoffs of each? |
No problem! Thanks for sticking with me too! To me, this boils down to whether or not we want to prevent attributes from being written on incorrect casing, or simply warn. From doing some research it looks like the browser doesn't care about case sensitivity. Enforcing casing is not protecting users from the DOM, it is protecting users from passing multiple properties within the same object, and deviating from community conventions. Regardless of the approach, as long as we are okay with custom aria attributes showing up in the DOM, we can remove the ARIA whitelist and make it a developer-only warning. So the approaches are: enforce a whitelist in production React or only as developer warnings. 1. Strictly enforce a whitelist in production ReactWe maintain a list of all "acceptable" attributes in React. When an attribute is missing from that list, only write it if it is all lower case. This means custom attributes, or attributes we don't know about, can only be lower case.
Pros
Cons
Other notes
2. Enforce certain attributes, like
|
Thanks, this is helpful. Are there any differences in these two approaches concerning custom elements? |
I don't believe there is any difference for custom elements. They get whatever attributes we send them, regardless of casing. For example: https://github.com/facebook/react/pull/7311/files#diff-b9a8e245b3916a2e61eb0431d868a6a3R662 |
I have a few questions about this approach.
Finally, does the current code in this PR represent the second approach fully? |
Slightly confusing yes. Would it be less confusing to allow mis-cased aliased attributes like
In this PR, https://github.com/facebook/react/pull/7311/files#diff-320a1076e356380287a6e67f7c894dbfR228
Yes. We have to deal with this for both approaches unless we disallowed dashes. I would rather just stop adding aliases and start to talk about the feasibility of removing everything but Still, I think the community would adapt quickly. SVG properties are a good example. I am curious about how many users are passing things like
I believe this PR represents the first approach. It would invalidate my other PR where the whitelist is significantly reduced (#10385) |
If we go with the second approach, yes, that would make sense to me. From user’s point of view, there is no expected semantic difference between them.
I don’t fully understand the second sentence, and the relationship between this PR and #10385. If this PR represents the first approach, does #10385 represent the second one? Is it meant to be applied on top of this PR, or as an alternative? Are both breaking changes? If we pick this PR now, does that make taking the other PR later harder? We are coming close to the point where we can’t make breaking changes to 16, and from that point any massive changes will have to wait another 6 months or so. I’m trying to figure out which changes we can make right now. I see two distinct goals:
Let’s imagine two worlds. In one world we want to go ahead with 1st scenario. In other world we want to go ahead with 2nd scenario. Which PRs, in which order, would we need to take before releasing 16, in these worlds? Note that for 2nd scenario, the weight loss doesn’t have to be immediate (can happen anytime during 16.x cycle) as long as the pieces that make it a minor rather than major change are already in place. |
#10385 removes most of the whitelist. Examples include I apologize for being confusing, I meant to say that it is a next step if we go with approach no. 2.
Until I added the validation to prevent uppercased custom attributes, it was meant to be applied on top, based on prior conversation (#7311 (comment)).
Scenario 1
Scenario 2
|
Can you remind me why this is necessary with approach (1)?
Can you remind me what makes ARIA attributes special (rather than automatically becoming “supported” as if they were custom properties if we remove them from whitelist)? |
😨. I don't remember. Jeez. I might have taken "maybe we should also force people to specify custom attributes as lowercase?" too far from #7311 (review) (the reply #7311 (comment)). Thinking on it again. I don't have a reason why we couldn't allow case sensitive custom attributes. I wish I could recall why I thought this. 😨. We just need to be sure something like So then the big difference between approach 1 and 2 is if we allow badly cased attributes to be written to the page. If we allow it, we can remove most of the attribute whitelist. If we don't, we have to keep it.
We just need to figure out what to do with the ARIA dev hook. This prevents assignment of "invalid" ARIA attributes via a white list. So if we allow custom attributes, that means custom ARIA attributes too. This whitelist is dead weight. |
If we allow custom attributes with uppercase letters, we just need to make sure the SSR diffing process is case-insensitive. Otherwise they will report as all lower-case, but the property will have upper case letters, so a mismatch will fire. |
Can you reorganize two PRs so that this one implements scenario (1), and the second one is purely additive on top (it’s fine to duplicate same commits) and implements scenario (2)? Then it would be easier to pick and decide which one gets in. |
I’m fine with refactoring the hooks in any way. E.g. if merging them would solve the problem. Or if ARIA hook is no longer necessary. |
Based on discussion in #7744 I think it might still be a good idea to warn about anything starting with |
eb2e759
to
82e05e0
Compare
Cool. In 82e05e0 I've allowed uppercase letters for custom attributes. I also added some tests to cover all of the different name aliasing types across different casing. Aside from the ARIA stuff, this covers scenario (1). I'll start on scenario (2). |
Done, though I'm going to circle back tomorrow morning with fresh eyes. I'll also update the descriptions and titles. Scenario 1: Scenario 2: Scenario two covers what I see as the necessary steps for moving over the ARIA dev warnings. I'll work on moving it over to the first PR (this one) tomorrow morning. |
I'm going to send another PR for this branch with a description of scenario one to keep discussion focused to that specific implementation. Also this PR has like 150 comments. It might be easier to talk. |
New PRs are up: Scenario 1: #10397
Scenario 2: #10385
Both entries make ARIA enforcement DEV only. |
Nice, thanks! Mind measuring sizes in both? |
Done. For production ReactDOM specifically: Scenario 1: 116.33 KB (37.01 KB gz) (-2%) Scenario 2 also cuts Edit: A screenshot of the readout has been attached to each PR. |
Closing this out in favor of #10385 |
What is the reason for not passing boolean props to the DOM? For instance, currently Sorry for commenting on an old PR (and probably a dumb question), but after digging through the codebase and trying to figure it out this seemed like the most appropriate place to ask. [Edit: sorry, I meant to write this over in #10564 -- too many open tabs! Left it here to reduce noise, but I can also comment there] |
You can do this explicitly: <div custom="true" /> Unfortunately, browsers can be wonky about booleans, so we decided we can't really "know" how to correctly set it if we don't know the attribute/property. For example, |
This was closed in favor of #10385
This is a resubmission of pull request #6459. Just to recap...
The addition of the unsupported property warning (#6800) reminded my old PR (#6459) and I was curious about reopening it... So here we are.
This pull request configures DOMPropertyOperations to allow all attributes to pass through. It maintains the whitelist only for attributes that need special behavior, such as boolean props and name translations (like
className
).While I was at it, I also eliminated the duplicated list of "reserved props" between
ReactDOMUnknownPropertyDevtool
andReactDOMComponent
through a newisReservedProp
method onDOMProperty
.Related Issues: