@samitouri / QOS-React-2 / commits / 868cf67aa4

Removed findCurrentFiberUsingSlowPath() in favor of findCurrentFiberUsingSlowPathById()

Brian Vaughn committed May 3, 2019 at 07:56 UTC 868cf67aa48d9089151c8f00b95d75ca21269d94
1 file changed +15 -29
src/backend/renderer.js
+15 -29
@@ -1351,15 +1351,15 @@ export function attach(
1351 currentRootID = -1;
1352 }
1353
1354 - function findAllCurrentHostFibers(parent: Fiber): $ReadOnlyArray<Fiber> {
1354 + function findAllCurrentHostFibers(id: number): $ReadOnlyArray<Fiber> {
1355 const fibers = [];
1356 - const currentParent = findCurrentFiberUsingSlowPath(parent);
1357 - if (!currentParent) {
1356 + const fiber = findCurrentFiberUsingSlowPathById(id);
1357 + if (!fiber) {
1358 return fibers;
1359 }
1360
1361 // Next we'll drill down this component to find all HostComponent/Text.
1362 - let node: Fiber = currentParent;
1362 + let node: Fiber = fiber;
1363 while (true) {
1364 if (node.tag === HostComponent || node.tag === HostText) {
1365 fibers.push(node);
@@ -1368,11 +1368,11 @@ export function attach(
1368 node = node.child;
1369 continue;
1370 }
1371 - if (node === currentParent) {
1371 + if (node === fiber) {
1372 return fibers;
1373 }
1374 while (!node.sibling) {
1375 - if (!node.return || node.return === currentParent) {
1375 + if (!node.return || node.return === fiber) {
1376 return fibers;
1377 }
1378 node = node.return;
@@ -1402,7 +1402,7 @@ export function attach(
1402 fiber = maybeFallbackFiber;
1403 }
1404 }
1405 - const hostFibers = findAllCurrentHostFibers(fiber);
1405 + const hostFibers = findAllCurrentHostFibers(id);
1406 return hostFibers.map(hostFiber => hostFiber.stateNode).filter(Boolean);
1407 } catch (err) {
1408 // The fiber might have unmounted by now.
@@ -1465,7 +1465,13 @@ export function attach(
1465 // https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberTreeReflection.js
1466 // It would be nice if we updated React to inject this function directly (vs just indirectly via findDOMNode).
1467 // BEGIN copied code
1468 - function findCurrentFiberUsingSlowPath(fiber: Fiber): Fiber | null {
1468 + function findCurrentFiberUsingSlowPathById(id: number): Fiber | null {
1469 + const fiber = idToFiberMap.get(id);
1470 + if (fiber == null) {
1471 + console.warn(`Could not find Fiber with id "${id}"`);
1472 + return null;
1473 + }
1474 +
1475 let alternate = fiber.alternate;
1476 if (!alternate) {
1477 // If there is no alternate, then we only need to check if it is mounted.
@@ -1611,7 +1617,6 @@ export function attach(
1617
1618 function selectElement(id: number): void {
1619 let fiber = idToFiberMap.get(id);
1614 -
1620 if (fiber == null) {
1621 console.warn(`Could not find Fiber with id "${id}"`);
1622 return;
@@ -1645,7 +1650,6 @@ export function attach(
1650
1651 function prepareViewElementSource(id: number): void {
1652 let fiber = idToFiberMap.get(id);
1648 -
1653 if (fiber == null) {
1654 console.warn(`Could not find Fiber with id "${id}"`);
1655 return;
@@ -1668,18 +1672,8 @@ export function attach(
1672 }
1673
1674 function inspectElementRaw(id: number): InspectedElement | null {
1671 - let fiber = idToFiberMap.get(id);
1672 -
1675 + let fiber = findCurrentFiberUsingSlowPathById(id);
1676 if (fiber == null) {
1674 - console.warn(`Could not find Fiber with id "${id}"`);
1675 - return null;
1676 - }
1677 -
1678 - // Find the currently mounted version of this fiber (so we don't show the wrong props and state).
1679 - fiber = findCurrentFiberUsingSlowPath(fiber);
1680 -
1681 - if (fiber == null) {
1682 - console.warn(`Could not find Fiber with id "${id}"`);
1677 return null;
1678 }
1679
@@ -1862,14 +1856,6 @@ export function attach(
1856 }
1857 }
1858
1865 - function findCurrentFiberUsingSlowPathById(id: number): Fiber | null {
1866 - const fiber = idToFiberMap.get(id);
1867 - if (fiber) {
1868 - return findCurrentFiberUsingSlowPath(fiber);
1869 - }
1870 - return null;
1871 - }
1872 -
1859 function setInHook(
1860 id: number,
1861 index: number,