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

Fix confusing whitespace nesting warning #5099

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/renderers/dom/client/syntheticEvents/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ SyntheticEvent.Interface = EventInterface;
SyntheticEvent.augmentClass = function(Class, Interface) {
var Super = this;

var E = function () {};
var E = function() {};
Copy link
Author

Choose a reason for hiding this comment

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

lint fix

E.prototype = Super.prototype;
var prototype = new E();

Expand Down
4 changes: 4 additions & 0 deletions src/renderers/dom/client/validateDOMNesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ if (__DEV__) {
info +=
' Add a <tbody> to your code to match the DOM tree generated by ' +
'the browser.';
} else if (childTag === 'span') {
info +=
' Remove unnecessary whitespace inside <' + ancestorTag + '>' +
' as it is internally transformed into <span>';
}
warning(
false,
Expand Down
70 changes: 70 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,76 @@ describe('ReactDOMComponent', function() {
);
});

it('warns nicely for unnecessary whitespace in table', () => {
spyOn(console, 'error');
var body = <tbody><tr>test</tr></tbody>;
ReactTestUtils.renderIntoDocument(<table> {body} </table>);

expect(console.error.calls.length).toBe(1);
expect(console.error.calls[0].args[0]).toBe(
'Warning: validateDOMNesting(...): <span> cannot appear as a child of <table>. ' +
'See table > span. ' +
'Remove unnecessary whitespace inside <table> ' +
'as it is internally transformed into <span>'
);
});

it('warns nicely for unnecessary whitespace in tbody', () => {
spyOn(console, 'error');
var rows = <tr>test</tr>;
ReactTestUtils.renderIntoDocument(<table><tbody> {rows} </tbody></table>);

expect(console.error.calls.length).toBe(1);
expect(console.error.calls[0].args[0]).toBe(
'Warning: validateDOMNesting(...): <span> cannot appear as a child of <tbody>. ' +
'See tbody > span. ' +
'Remove unnecessary whitespace inside <tbody> ' +
'as it is internally transformed into <span>'
);
});

it('warns nicely for unnecessary whitespace in thead', () => {
spyOn(console, 'error');
var rows = <tr>test</tr>;
ReactTestUtils.renderIntoDocument(<table><thead> {rows} </thead></table>);

expect(console.error.calls.length).toBe(1);
expect(console.error.calls[0].args[0]).toBe(
'Warning: validateDOMNesting(...): <span> cannot appear as a child of <thead>. ' +
'See thead > span. ' +
'Remove unnecessary whitespace inside <thead> ' +
'as it is internally transformed into <span>'
);
});

it('warns nicely for unnecessary whitespace in tfoot', () => {
spyOn(console, 'error');
var rows = <tr>test</tr>;
ReactTestUtils.renderIntoDocument(<table><tfoot> {rows} </tfoot></table>);

expect(console.error.calls.length).toBe(1);
expect(console.error.calls[0].args[0]).toBe(
'Warning: validateDOMNesting(...): <span> cannot appear as a child of <tfoot>. ' +
'See tfoot > span. ' +
'Remove unnecessary whitespace inside <tfoot> ' +
'as it is internally transformed into <span>'
);
});

it('warns nicely for unnecessary whitespace in tr', () => {
spyOn(console, 'error');
var td = <td>test</td>;
ReactTestUtils.renderIntoDocument(<table><tbody><tr> {td} </tr></tbody></table>);

expect(console.error.calls.length).toBe(1);
expect(console.error.calls[0].args[0]).toBe(
'Warning: validateDOMNesting(...): <span> cannot appear as a child of <tr>. ' +
'See tr > span. ' +
'Remove unnecessary whitespace inside <tr> ' +
'as it is internally transformed into <span>'
);
});

it('warns on invalid nesting at root', () => {
spyOn(console, 'error');
var p = document.createElement('p');
Expand Down