Skip to content

Commit

Permalink
Remove hydrate() warning about empty container (#10345)
Browse files Browse the repository at this point in the history
* Remove hydrate() warning about empty container

It used to have false positives for cases where we legitimately don't render anything.

* Use existing constant

* Test empty string case using its parent
  • Loading branch information
gaearon authored Aug 2, 2017
1 parent a43ba26 commit 35e3133
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
9 changes: 0 additions & 9 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ ReactGenericBatching.injection.injectFiberBatchedUpdates(
);

var warnedAboutHydrateAPI = false;
var warnedAboutEmptyContainer = false;

function renderSubtreeIntoContainer(
parentComponent: ?ReactComponent<any, any, any>,
Expand Down Expand Up @@ -617,14 +616,6 @@ function renderSubtreeIntoContainer(
'with ReactDOM.hydrate() if you want React to attach to the server HTML.',
);
}
if (forceHydrate && !container.firstChild && !warnedAboutEmptyContainer) {
warnedAboutEmptyContainer = true;
warning(
false,
'hydrate(): Expected to hydrate from server-rendered markup, but the passed ' +
'DOM container node was empty. React will create the DOM from scratch.',
);
}
}
const newRoot = DOMRenderer.createContainer(container);
root = container._reactRootContainer = newRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,22 @@ describe('ReactDOMServerIntegration', () => {
expect(parent.childNodes[1].tagName).toBe('DIV');
expect(parent.childNodes[2].tagName).toBe('DIV');
});

itRenders('emptyish values', async render => {
let e = await render(0);
expect(e.nodeType).toBe(TEXT_NODE_TYPE);
expect(e.nodeValue).toMatch('0');

// Empty string is special because client renders a node
// but server returns empty HTML. So we compare parent text.
expect((await render(<div>{''}</div>)).textContent).toBe('');

expect(await render([])).toBe(null);
expect(await render(false)).toBe(null);
expect(await render(true)).toBe(null);
expect(await render(undefined)).toBe(null);
expect(await render([[[false]], undefined])).toBe(null);
});
}
});

Expand Down
11 changes: 0 additions & 11 deletions src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,6 @@ describe('rendering React components at document', () => {

if (ReactDOMFeatureFlags.useFiber) {
describe('with new explicit hydration API', () => {
it('warns if there is no server rendered markup to hydrate', () => {
spyOn(console, 'error');
const container = document.createElement('div');
ReactDOM.hydrate(<div />, container);
expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'hydrate(): Expected to hydrate from server-rendered markup, but the passed ' +
'DOM container node was empty. React will create the DOM from scratch.',
);
});

it('should be able to adopt server markup', () => {
class Root extends React.Component {
render() {
Expand Down

0 comments on commit 35e3133

Please sign in to comment.