Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only warn on exact case match for "false" in DOM boolean props
  • Loading branch information
motiz88 committed Aug 12, 2018
commit b8f83cdfe4c0499c67ee07658a3e0f1b08a1afd6
12 changes: 0 additions & 12 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2518,18 +2518,6 @@ describe('ReactDOMComponent', () => {

expect(el.getAttribute('hidden')).toBe('');
});

it('warns on the ambiguous string value "False"', function() {
let el;
expect(() => {
el = ReactTestUtils.renderIntoDocument(<div hidden="False" />);
}).toWarnDev(
'Received the string `False` for the boolean attribute `hidden`. ' +
'Did you mean hidden={false}?',
);

expect(el.getAttribute('hidden')).toBe('');
});
});

describe('Hyphenated SVG elements', function() {
Expand Down
5 changes: 2 additions & 3 deletions packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ if (__DEV__) {

// Warn when passing the string 'false' into a boolean prop
if (
value === 'false' &&
propertyInfo !== null &&
propertyInfo.type === BOOLEAN &&
typeof value === 'string' &&
value.toLowerCase() === 'false'
propertyInfo.type === BOOLEAN
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let’s make value === 'false' the first condition. Since it’s rare we won’t have to check most other conditions.

warning(
false,
Expand Down