Warn when an empty string is passed to a DOM boolean prop#13404
Closed
motiz88 wants to merge 1 commit intofacebook:masterfrom
motiz88:issue-13400-empty-string
Closed
Warn when an empty string is passed to a DOM boolean prop#13404motiz88 wants to merge 1 commit intofacebook:masterfrom motiz88:issue-13400-empty-string
motiz88 wants to merge 1 commit intofacebook:masterfrom
motiz88:issue-13400-empty-string
Conversation
motiz88
commented
Aug 15, 2018
| expect(el.hasAttribute('hidden')).toBe(false); | ||
| }); | ||
|
|
||
| it('warns on the ambiguous string value "" when it means true', function() { |
Contributor
Author
There was a problem hiding this comment.
Arguably this test belongs under String boolean attributes above, rather than here under Boolean attributes (a test category I introduced in #13372), but then again it's clearly a sibling test to the other two that do belong here. 🤷♂️ Happy to restructure this based on feedback.
Details of bundled changes.Comparing: 69e2a0d...0b21723 react-dom
Generated by 🚫 dangerJS |
9 tasks
Contributor
Author
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
|
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the more targeted of two possible approaches to resolve #13400, the other being @gaearon's suggestion of warning on any string value passed to a boolean prop (also subsuming #13372).
Apart from my other reservation regarding a blanket warning on string values, the present approach has the advantage of being applicable to
BOOLEAN,BOOLEANISH_STRINGandOVERLOADED_BOOLEANprops (seeDOMProperty.jsfor definitions). The latter do legitimately need to accept arbitrary string values alongside booleans; if we did go with a blanket warning, it would only make sense for the first two types, so we'd potentially still want a separate check for""to accommodateOVERLOADED_BOOLEAN.The one wrinkle here (that would also affect the other approach) is that I had to special-case
valueand exclude it from the warning, since it's somewhat oddly modelled as aBOOLEANISH_STRING, making legitimate uses ofvalue=""warn under my initial implementation. This raises a separate question, though: when isvalueever legitimately a boolean? (<param>? That's a bit tenuous;valueis certainly not specced as a boolean there.) However, we can't just remove it from the whitelist, as that would break current behaviour.