Skip to content

Remove hydrate() warning about empty container #10345

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Aug 2, 2017
Merged
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
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

This just checks a complex component structure of no-render values? Pretty neat that this can just be data.

});
}
});

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