diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index 728f775adf5..35c39fb80fd 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -550,51 +550,36 @@ function legacyRenderSubtreeIntoContainer( // TODO: Without `any` type, Flow says "Property cannot be accessed on any // member of intersection type." Whyyyyyy. let root: Root = (container._reactRootContainer: any); + let exec = function(cb){ + cb(); + } + let instance = null; if (!root) { // Initial mount root = container._reactRootContainer = legacyCreateRootFromDOMContainer( container, forceHydrate, ); - if (typeof callback === 'function') { - const originalCallback = callback; - callback = function() { - const instance = getPublicRootInstance(root._internalRoot); - originalCallback.call(instance); - }; - } - // Initial mount should not be batched. - unbatchedUpdates(() => { - if (parentComponent != null) { + exec = unbatchedUpdates; + } + function getInstance(){ + if (__DEV__) { + warnOnInvalidCallback(callback, 'render'); + } + instance = getPublicRootInstance(root._internalRoot); + if (typeof callback === 'function') { + callback.call(instance); + } + } + + exec(() => { root.legacy_renderSubtreeIntoContainer( - parentComponent, + parentComponent || null, children, - callback, + getInstance, ); - } else { - root.render(children, callback); - } }); - } else { - if (typeof callback === 'function') { - const originalCallback = callback; - callback = function() { - const instance = getPublicRootInstance(root._internalRoot); - originalCallback.call(instance); - }; - } - // Update - if (parentComponent != null) { - root.legacy_renderSubtreeIntoContainer( - parentComponent, - children, - callback, - ); - } else { - root.render(children, callback); - } - } - return getPublicRootInstance(root._internalRoot); + return instance; } function createPortal(