mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Remove hydrate() warning about empty container (#10345)
* 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
This commit is contained in:
@@ -525,7 +525,6 @@ ReactGenericBatching.injection.injectFiberBatchedUpdates(
|
||||
);
|
||||
|
||||
var warnedAboutHydrateAPI = false;
|
||||
var warnedAboutEmptyContainer = false;
|
||||
|
||||
function renderSubtreeIntoContainer(
|
||||
parentComponent: ?ReactComponent<any, any, any>,
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user