@samitouri / QOS-React-2 / commits / ffbb86b361

Wrap top-level mount and unmount in syncUpdates

For legacy purposes. Only enabled in the DOM renderer. We can remove this in a future release when we enable incremental-by-default. This change is unobservable because syncUpdates actually schedules Task updates when it is called from inside another batch. The correct behavior is to recursively begin another batch of work. We will fix it in a subsequent commit.

Andrew Clark committed Dec 28, 2016 at 20:41 UTC ffbb86b361e5cfec0c3c5dcc2f5ab829e7f54527
1 file changed +13 -4
src/renderers/dom/fiber/ReactDOMFiber.js
+13 -4
@@ -322,9 +322,15 @@ function renderSubtreeIntoContainer(parentComponent : ?ReactComponent<any, any,
322 while (container.lastChild) {
323 container.removeChild(container.lastChild);
324 }
325 - root = container._reactRootContainer = DOMRenderer.createContainer(container);
325 + const newRoot = DOMRenderer.createContainer(container);
326 + root = container._reactRootContainer = newRoot;
327 + // Initial mount is always sync, even if we're in a batch.
328 + DOMRenderer.syncUpdates(() => {
329 + DOMRenderer.updateContainer(children, newRoot, parentComponent, callback);
330 + });
331 + } else {
332 + DOMRenderer.updateContainer(children, root, parentComponent, callback);
333 }
327 - DOMRenderer.updateContainer(children, root, parentComponent, callback);
334 return DOMRenderer.getPublicRootInstance(root);
335 }
336
@@ -346,8 +352,11 @@ var ReactDOM = {
352 unmountComponentAtNode(container : DOMContainerElement) {
353 warnAboutUnstableUse();
354 if (container._reactRootContainer) {
349 - return renderSubtreeIntoContainer(null, null, container, () => {
350 - container._reactRootContainer = null;
355 + // Unmount is always sync, even if we're in a batch.
356 + return DOMRenderer.syncUpdates(() => {
357 + return renderSubtreeIntoContainer(null, null, container, () => {
358 + container._reactRootContainer = null;
359 + });
360 });
361 }
362 },