Skip to content
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

Warn when an empty string is passed to a DOM boolean prop #13404

Closed
wants to merge 1 commit into from
Closed

Warn when an empty string is passed to a DOM boolean prop #13404

wants to merge 1 commit into from

Conversation

motiz88
Copy link
Contributor

@motiz88 motiz88 commented Aug 15, 2018

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_STRING and OVERLOADED_BOOLEAN props (see DOMProperty.js for 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 accommodate OVERLOADED_BOOLEAN.

The one wrinkle here (that would also affect the other approach) is that I had to special-case value and exclude it from the warning, since it's somewhat oddly modelled as a BOOLEANISH_STRING, making legitimate uses of value="" warn under my initial implementation. This raises a separate question, though: when is value ever legitimately a boolean? (<param>? That's a bit tenuous; value is certainly not specced as a boolean there.) However, we can't just remove it from the whitelist, as that would break current behaviour.

expect(el.hasAttribute('hidden')).toBe(false);
});

it('warns on the ambiguous string value "" when it means true', function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@pull-bot
Copy link

Details of bundled changes.

Comparing: 69e2a0d...0b21723

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 644.7 KB 645.35 KB 151.78 KB 151.94 KB UMD_DEV
react-dom.development.js +0.1% +0.1% 640.83 KB 641.49 KB 150.63 KB 150.8 KB NODE_DEV
react-dom-server.browser.development.js +0.6% +0.6% 103.7 KB 104.36 KB 27.7 KB 27.88 KB UMD_DEV
react-dom-server.browser.development.js +0.7% +0.6% 99.83 KB 100.49 KB 26.73 KB 26.89 KB NODE_DEV
react-dom-server.node.development.js +0.6% +0.6% 101.76 KB 102.41 KB 27.26 KB 27.42 KB NODE_DEV
ReactDOM-dev.js +0.1% +0.1% 646.99 KB 647.75 KB 148.57 KB 148.74 KB FB_WWW_DEV
ReactDOMServer-dev.js +0.8% +0.7% 100.97 KB 101.74 KB 26.42 KB 26.6 KB FB_WWW_DEV

Generated by 🚫 dangerJS

@motiz88
Copy link
Contributor Author

motiz88 commented May 24, 2019

@gaearon I hope you don't mind me pinging you on this, as you're the last person who responded to #13400. Any interest in getting this merged? I'd be happy to bring it up to date, obviously.

@stale
Copy link

stale bot commented Jan 10, 2020

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.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

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!

@stale stale bot closed this Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boolean DOM properties coerce empty string to false, contrary to HTML standard
3 participants