Best JavaScript code snippet using playwright-internal
ReactFiberCommitWork.new.js
Source:ReactFiberCommitWork.new.js
...1029 node.sibling.return = node.return;1030 node = node.sibling;1031 }1032}1033function detachFiberMutation(fiber: Fiber) {1034 // Cut off the return pointer to disconnect it from the tree.1035 // This enables us to detect and warn against state updates on an unmounted component.1036 // It also prevents events from bubbling from within disconnected components.1037 //1038 // Ideally, we should also clear the child pointer of the parent alternate to let this1039 // get GC:ed but we don't know which for sure which parent is the current1040 // one so we'll settle for GC:ing the subtree of this child.1041 // This child itself will be GC:ed when the parent updates the next time.1042 //1043 // Note that we can't clear child or sibling pointers yet.1044 // They're needed for passive effects and for findDOMNode.1045 // We defer those fields, and all other cleanup, to the passive phase (see detachFiberAfterEffects).1046 const alternate = fiber.alternate;1047 if (alternate !== null) {1048 alternate.return = null;1049 fiber.alternate = null;1050 }1051 fiber.return = null;1052}1053export function detachFiberAfterEffects(fiber: Fiber): void {1054 // Null out fields to improve GC for references that may be lingering (e.g. DevTools).1055 // Note that we already cleared the return pointer in detachFiberMutation().1056 fiber.child = null;1057 fiber.deletions = null;1058 fiber.dependencies = null;1059 fiber.memoizedProps = null;1060 fiber.memoizedState = null;1061 fiber.pendingProps = null;1062 fiber.sibling = null;1063 fiber.stateNode = null;1064 fiber.updateQueue = null;1065 fiber.nextEffect = null;1066 fiber.firstEffect = null;1067 fiber.lastEffect = null;1068 if (__DEV__) {1069 fiber._debugOwner = null;1070 }1071}1072function emptyPortalContainer(current: Fiber) {1073 if (!supportsPersistence) {1074 return;1075 }1076 const portal: {1077 containerInfo: Container,1078 pendingChildren: ChildSet,1079 ...1080 } = current.stateNode;1081 const {containerInfo} = portal;1082 const emptyChildSet = createContainerChildSet(containerInfo);1083 replaceContainerChildren(containerInfo, emptyChildSet);1084}1085function commitContainer(finishedWork: Fiber) {1086 if (!supportsPersistence) {1087 return;1088 }1089 switch (finishedWork.tag) {1090 case ClassComponent:1091 case HostComponent:1092 case HostText:1093 case FundamentalComponent: {1094 return;1095 }1096 case HostRoot:1097 case HostPortal: {1098 const portalOrRoot: {1099 containerInfo: Container,1100 pendingChildren: ChildSet,1101 ...1102 } = finishedWork.stateNode;1103 const {containerInfo, pendingChildren} = portalOrRoot;1104 replaceContainerChildren(containerInfo, pendingChildren);1105 return;1106 }1107 }1108 invariant(1109 false,1110 'This unit of work tag should not have side-effects. This error is ' +1111 'likely caused by a bug in React. Please file an issue.',1112 );1113}1114function getHostParentFiber(fiber: Fiber): Fiber {1115 let parent = fiber.return;1116 while (parent !== null) {1117 if (isHostParent(parent)) {1118 return parent;1119 }1120 parent = parent.return;1121 }1122 invariant(1123 false,1124 'Expected to find a host parent. This error is likely caused by a bug ' +1125 'in React. Please file an issue.',1126 );1127}1128function isHostParent(fiber: Fiber): boolean {1129 return (1130 fiber.tag === HostComponent ||1131 fiber.tag === HostRoot ||1132 fiber.tag === HostPortal1133 );1134}1135function getHostSibling(fiber: Fiber): ?Instance {1136 // We're going to search forward into the tree until we find a sibling host1137 // node. Unfortunately, if multiple insertions are done in a row we have to1138 // search past them. This leads to exponential search for the next sibling.1139 // TODO: Find a more efficient way to do this.1140 let node: Fiber = fiber;1141 siblings: while (true) {1142 // If we didn't find anything, let's try the next sibling.1143 while (node.sibling === null) {1144 if (node.return === null || isHostParent(node.return)) {1145 // If we pop out of the root or hit the parent the fiber we are the1146 // last sibling.1147 return null;1148 }1149 node = node.return;1150 }1151 node.sibling.return = node.return;1152 node = node.sibling;1153 while (1154 node.tag !== HostComponent &&1155 node.tag !== HostText &&1156 node.tag !== DehydratedFragment1157 ) {1158 // If it is not host node and, we might have a host node inside it.1159 // Try to search down until we find one.1160 if (node.flags & Placement) {1161 // If we don't have a child, try the siblings instead.1162 continue siblings;1163 }1164 // If we don't have a child, try the siblings instead.1165 // We also skip portals because they are not part of this host tree.1166 if (node.child === null || node.tag === HostPortal) {1167 continue siblings;1168 } else {1169 node.child.return = node;1170 node = node.child;1171 }1172 }1173 // Check if this host node is stable or about to be placed.1174 if (!(node.flags & Placement)) {1175 // Found it!1176 return node.stateNode;1177 }1178 }1179}1180function commitPlacement(finishedWork: Fiber): void {1181 if (!supportsMutation) {1182 return;1183 }1184 // Recursively insert all host nodes into the parent.1185 const parentFiber = getHostParentFiber(finishedWork);1186 // Note: these two variables *must* always be updated together.1187 let parent;1188 let isContainer;1189 const parentStateNode = parentFiber.stateNode;1190 switch (parentFiber.tag) {1191 case HostComponent:1192 parent = parentStateNode;1193 isContainer = false;1194 break;1195 case HostRoot:1196 parent = parentStateNode.containerInfo;1197 isContainer = true;1198 break;1199 case HostPortal:1200 parent = parentStateNode.containerInfo;1201 isContainer = true;1202 break;1203 case FundamentalComponent:1204 if (enableFundamentalAPI) {1205 parent = parentStateNode.instance;1206 isContainer = false;1207 }1208 // eslint-disable-next-line-no-fallthrough1209 default:1210 invariant(1211 false,1212 'Invalid host parent fiber. This error is likely caused by a bug ' +1213 'in React. Please file an issue.',1214 );1215 }1216 if (parentFiber.flags & ContentReset) {1217 // Reset the text content of the parent before doing any insertions1218 resetTextContent(parent);1219 // Clear ContentReset from the effect tag1220 parentFiber.flags &= ~ContentReset;1221 }1222 const before = getHostSibling(finishedWork);1223 // We only have the top Fiber that was inserted but we need to recurse down its1224 // children to find all the terminal nodes.1225 if (isContainer) {1226 insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);1227 } else {1228 insertOrAppendPlacementNode(finishedWork, before, parent);1229 }1230}1231function insertOrAppendPlacementNodeIntoContainer(1232 node: Fiber,1233 before: ?Instance,1234 parent: Container,1235): void {1236 const {tag} = node;1237 const isHost = tag === HostComponent || tag === HostText;1238 if (isHost || (enableFundamentalAPI && tag === FundamentalComponent)) {1239 const stateNode = isHost ? node.stateNode : node.stateNode.instance;1240 if (before) {1241 insertInContainerBefore(parent, stateNode, before);1242 } else {1243 appendChildToContainer(parent, stateNode);1244 }1245 } else if (tag === HostPortal) {1246 // If the insertion itself is a portal, then we don't want to traverse1247 // down its children. Instead, we'll get insertions from each child in1248 // the portal directly.1249 } else {1250 const child = node.child;1251 if (child !== null) {1252 insertOrAppendPlacementNodeIntoContainer(child, before, parent);1253 let sibling = child.sibling;1254 while (sibling !== null) {1255 insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);1256 sibling = sibling.sibling;1257 }1258 }1259 }1260}1261function insertOrAppendPlacementNode(1262 node: Fiber,1263 before: ?Instance,1264 parent: Instance,1265): void {1266 const {tag} = node;1267 const isHost = tag === HostComponent || tag === HostText;1268 if (isHost || (enableFundamentalAPI && tag === FundamentalComponent)) {1269 const stateNode = isHost ? node.stateNode : node.stateNode.instance;1270 if (before) {1271 insertBefore(parent, stateNode, before);1272 } else {1273 appendChild(parent, stateNode);1274 }1275 } else if (tag === HostPortal) {1276 // If the insertion itself is a portal, then we don't want to traverse1277 // down its children. Instead, we'll get insertions from each child in1278 // the portal directly.1279 } else {1280 const child = node.child;1281 if (child !== null) {1282 insertOrAppendPlacementNode(child, before, parent);1283 let sibling = child.sibling;1284 while (sibling !== null) {1285 insertOrAppendPlacementNode(sibling, before, parent);1286 sibling = sibling.sibling;1287 }1288 }1289 }1290}1291function unmountHostComponents(1292 finishedRoot: FiberRoot,1293 current: Fiber,1294 renderPriorityLevel: ReactPriorityLevel,1295): void {1296 // We only have the top Fiber that was deleted but we need to recurse down its1297 // children to find all the terminal nodes.1298 let node: Fiber = current;1299 // Each iteration, currentParent is populated with node's host parent if not1300 // currentParentIsValid.1301 let currentParentIsValid = false;1302 // Note: these two variables *must* always be updated together.1303 let currentParent;1304 let currentParentIsContainer;1305 while (true) {1306 if (!currentParentIsValid) {1307 let parent = node.return;1308 findParent: while (true) {1309 invariant(1310 parent !== null,1311 'Expected to find a host parent. This error is likely caused by ' +1312 'a bug in React. Please file an issue.',1313 );1314 const parentStateNode = parent.stateNode;1315 switch (parent.tag) {1316 case HostComponent:1317 currentParent = parentStateNode;1318 currentParentIsContainer = false;1319 break findParent;1320 case HostRoot:1321 currentParent = parentStateNode.containerInfo;1322 currentParentIsContainer = true;1323 break findParent;1324 case HostPortal:1325 currentParent = parentStateNode.containerInfo;1326 currentParentIsContainer = true;1327 break findParent;1328 case FundamentalComponent:1329 if (enableFundamentalAPI) {1330 currentParent = parentStateNode.instance;1331 currentParentIsContainer = false;1332 }1333 }1334 parent = parent.return;1335 }1336 currentParentIsValid = true;1337 }1338 if (node.tag === HostComponent || node.tag === HostText) {1339 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel);1340 // After all the children have unmounted, it is now safe to remove the1341 // node from the tree.1342 if (currentParentIsContainer) {1343 removeChildFromContainer(1344 ((currentParent: any): Container),1345 (node.stateNode: Instance | TextInstance),1346 );1347 } else {1348 removeChild(1349 ((currentParent: any): Instance),1350 (node.stateNode: Instance | TextInstance),1351 );1352 }1353 // Don't visit children because we already visited them.1354 } else if (enableFundamentalAPI && node.tag === FundamentalComponent) {1355 const fundamentalNode = node.stateNode.instance;1356 commitNestedUnmounts(finishedRoot, node, renderPriorityLevel);1357 // After all the children have unmounted, it is now safe to remove the1358 // node from the tree.1359 if (currentParentIsContainer) {1360 removeChildFromContainer(1361 ((currentParent: any): Container),1362 (fundamentalNode: Instance),1363 );1364 } else {1365 removeChild(1366 ((currentParent: any): Instance),1367 (fundamentalNode: Instance),1368 );1369 }1370 } else if (1371 enableSuspenseServerRenderer &&1372 node.tag === DehydratedFragment1373 ) {1374 if (enableSuspenseCallback) {1375 const hydrationCallbacks = finishedRoot.hydrationCallbacks;1376 if (hydrationCallbacks !== null) {1377 const onDeleted = hydrationCallbacks.onDeleted;1378 if (onDeleted) {1379 onDeleted((node.stateNode: SuspenseInstance));1380 }1381 }1382 }1383 // Delete the dehydrated suspense boundary and all of its content.1384 if (currentParentIsContainer) {1385 clearSuspenseBoundaryFromContainer(1386 ((currentParent: any): Container),1387 (node.stateNode: SuspenseInstance),1388 );1389 } else {1390 clearSuspenseBoundary(1391 ((currentParent: any): Instance),1392 (node.stateNode: SuspenseInstance),1393 );1394 }1395 } else if (node.tag === HostPortal) {1396 if (node.child !== null) {1397 // When we go into a portal, it becomes the parent to remove from.1398 // We will reassign it back when we pop the portal on the way up.1399 currentParent = node.stateNode.containerInfo;1400 currentParentIsContainer = true;1401 // Visit children because portals might contain host components.1402 node.child.return = node;1403 node = node.child;1404 continue;1405 }1406 } else {1407 commitUnmount(finishedRoot, node, renderPriorityLevel);1408 // Visit children because we may find more host components below.1409 if (node.child !== null) {1410 node.child.return = node;1411 node = node.child;1412 continue;1413 }1414 }1415 if (node === current) {1416 return;1417 }1418 while (node.sibling === null) {1419 if (node.return === null || node.return === current) {1420 return;1421 }1422 node = node.return;1423 if (node.tag === HostPortal) {1424 // When we go out of the portal, we need to restore the parent.1425 // Since we don't keep a stack of them, we will search for it.1426 currentParentIsValid = false;1427 }1428 }1429 node.sibling.return = node.return;1430 node = node.sibling;1431 }1432}1433function commitDeletion(1434 finishedRoot: FiberRoot,1435 current: Fiber,1436 renderPriorityLevel: ReactPriorityLevel,1437): void {1438 if (supportsMutation) {1439 // Recursively delete all host nodes from the parent.1440 // Detach refs and call componentWillUnmount() on the whole subtree.1441 unmountHostComponents(finishedRoot, current, renderPriorityLevel);1442 } else {1443 // Detach refs and call componentWillUnmount() on the whole subtree.1444 commitNestedUnmounts(finishedRoot, current, renderPriorityLevel);1445 }1446 const alternate = current.alternate;1447 detachFiberMutation(current);1448 if (alternate !== null) {1449 detachFiberMutation(alternate);1450 }1451}1452function commitWork(current: Fiber | null, finishedWork: Fiber): void {1453 if (!supportsMutation) {1454 switch (finishedWork.tag) {1455 case FunctionComponent:1456 case ForwardRef:1457 case MemoComponent:1458 case SimpleMemoComponent: {1459 // Layout effects are destroyed during the mutation phase so that all1460 // destroy functions for all fibers are called before any create functions.1461 // This prevents sibling component effects from interfering with each other,1462 // e.g. a destroy function in one component should never override a ref set1463 // by a create function in another component during the same commit....
ReactFiberCommitWork.old.js
Source:ReactFiberCommitWork.old.js
...507 node.sibling.return = node.return;508 node = node.sibling;509 }510 }511 function detachFiberMutation(fiber) {512 // Cut off the return pointers to disconnect it from the tree. Ideally, we513 // should clear the child pointer of the parent alternate to let this514 // get GC:ed but we don't know which for sure which parent is the current515 // one so we'll settle for GC:ing the subtree of this child. This child516 // itself will be GC:ed when the parent updates the next time.517 // Note: we cannot null out sibling here, otherwise it can cause issues518 // with findDOMNode and how it requires the sibling field to carry out519 // traversal in a later effect. See PR #16820. We now clear the sibling520 // field after effects, see: detachFiberAfterEffects.521 //522 // Don't disconnect stateNode now; it will be detached in detachFiberAfterEffects.523 // It may be required if the current component is an error boundary,524 // and one of its descendants throws while unmounting a passive effect.525 fiber.alternate = null;526 fiber.child = null;527 fiber.dependencies = null;528 fiber.firstEffect = null;529 fiber.lastEffect = null;530 fiber.memoizedProps = null;531 fiber.memoizedState = null;532 fiber.pendingProps = null;533 fiber.return = null;534 fiber.updateQueue = null;535 {536 fiber._debugOwner = null;537 }538 }539 function getHostParentFiber(fiber) {540 var parent = fiber.return;541 while (parent !== null) {542 if (isHostParent(parent)) {543 return parent;544 }545 parent = parent.return;546 }547 {548 {549 throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );550 }551 }552 }553 function isHostParent(fiber) {554 return fiber.tag === HostComponent || fiber.tag === HostRoot || fiber.tag === HostPortal;555 }556 function getHostSibling(fiber) {557 // We're going to search forward into the tree until we find a sibling host558 // node. Unfortunately, if multiple insertions are done in a row we have to559 // search past them. This leads to exponential search for the next sibling.560 // TODO: Find a more efficient way to do this.561 var node = fiber;562 siblings: while (true) {563 // If we didn't find anything, let's try the next sibling.564 while (node.sibling === null) {565 if (node.return === null || isHostParent(node.return)) {566 // If we pop out of the root or hit the parent the fiber we are the567 // last sibling.568 return null;569 }570 node = node.return;571 }572 node.sibling.return = node.return;573 node = node.sibling;574 while (node.tag !== HostComponent && node.tag !== HostText && node.tag !== DehydratedFragment) {575 // If it is not host node and, we might have a host node inside it.576 // Try to search down until we find one.577 if (node.flags & Placement) {578 // If we don't have a child, try the siblings instead.579 continue siblings;580 } // If we don't have a child, try the siblings instead.581 // We also skip portals because they are not part of this host tree.582 if (node.child === null || node.tag === HostPortal) {583 continue siblings;584 } else {585 node.child.return = node;586 node = node.child;587 }588 } // Check if this host node is stable or about to be placed.589 if (!(node.flags & Placement)) {590 // Found it!591 return node.stateNode;592 }593 }594 }595 function commitPlacement(finishedWork) {596 var parentFiber = getHostParentFiber(finishedWork); // Note: these two variables *must* always be updated together.597 var parent;598 var isContainer;599 var parentStateNode = parentFiber.stateNode;600 switch (parentFiber.tag) {601 case HostComponent:602 parent = parentStateNode;603 isContainer = false;604 break;605 case HostRoot:606 parent = parentStateNode.containerInfo;607 isContainer = true;608 break;609 case HostPortal:610 parent = parentStateNode.containerInfo;611 isContainer = true;612 break;613 case FundamentalComponent:614 // eslint-disable-next-line-no-fallthrough615 default:616 {617 {618 throw Error( "Invalid host parent fiber. This error is likely caused by a bug in React. Please file an issue." );619 }620 }621 }622 if (parentFiber.flags & ContentReset) {623 // Reset the text content of the parent before doing any insertions624 resetTextContent(parent); // Clear ContentReset from the effect tag625 parentFiber.flags &= ~ContentReset;626 }627 var before = getHostSibling(finishedWork); // We only have the top Fiber that was inserted but we need to recurse down its628 // children to find all the terminal nodes.629 if (isContainer) {630 insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);631 } else {632 insertOrAppendPlacementNode(finishedWork, before, parent);633 }634 }635 function insertOrAppendPlacementNodeIntoContainer(node, before, parent) {636 var tag = node.tag;637 var isHost = tag === HostComponent || tag === HostText;638 if (isHost || enableFundamentalAPI ) {639 var stateNode = isHost ? node.stateNode : node.stateNode.instance;640 if (before) {641 insertInContainerBefore(parent, stateNode, before);642 } else {643 appendChildToContainer(parent, stateNode);644 }645 } else if (tag === HostPortal) ; else {646 var child = node.child;647 if (child !== null) {648 insertOrAppendPlacementNodeIntoContainer(child, before, parent);649 var sibling = child.sibling;650 while (sibling !== null) {651 insertOrAppendPlacementNodeIntoContainer(sibling, before, parent);652 sibling = sibling.sibling;653 }654 }655 }656 }657 function insertOrAppendPlacementNode(node, before, parent) {658 var tag = node.tag;659 var isHost = tag === HostComponent || tag === HostText;660 if (isHost || enableFundamentalAPI ) {661 var stateNode = isHost ? node.stateNode : node.stateNode.instance;662 if (before) {663 insertBefore(parent, stateNode, before);664 } else {665 appendChild(parent, stateNode);666 }667 } else if (tag === HostPortal) ; else {668 var child = node.child;669 if (child !== null) {670 insertOrAppendPlacementNode(child, before, parent);671 var sibling = child.sibling;672 while (sibling !== null) {673 insertOrAppendPlacementNode(sibling, before, parent);674 sibling = sibling.sibling;675 }676 }677 }678 }679 function unmountHostComponents(finishedRoot, current, renderPriorityLevel) {680 // We only have the top Fiber that was deleted but we need to recurse down its681 // children to find all the terminal nodes.682 var node = current; // Each iteration, currentParent is populated with node's host parent if not683 // currentParentIsValid.684 var currentParentIsValid = false; // Note: these two variables *must* always be updated together.685 var currentParent;686 var currentParentIsContainer;687 while (true) {688 if (!currentParentIsValid) {689 var parent = node.return;690 findParent: while (true) {691 if (!(parent !== null)) {692 {693 throw Error( "Expected to find a host parent. This error is likely caused by a bug in React. Please file an issue." );694 }695 }696 var parentStateNode = parent.stateNode;697 switch (parent.tag) {698 case HostComponent:699 currentParent = parentStateNode;700 currentParentIsContainer = false;701 break findParent;702 case HostRoot:703 currentParent = parentStateNode.containerInfo;704 currentParentIsContainer = true;705 break findParent;706 case HostPortal:707 currentParent = parentStateNode.containerInfo;708 currentParentIsContainer = true;709 break findParent;710 }711 parent = parent.return;712 }713 currentParentIsValid = true;714 }715 if (node.tag === HostComponent || node.tag === HostText) {716 commitNestedUnmounts(finishedRoot, node); // After all the children have unmounted, it is now safe to remove the717 // node from the tree.718 if (currentParentIsContainer) {719 removeChildFromContainer(currentParent, node.stateNode);720 } else {721 removeChild(currentParent, node.stateNode);722 } // Don't visit children because we already visited them.723 } else if ( node.tag === DehydratedFragment) {724 if (currentParentIsContainer) {725 clearSuspenseBoundaryFromContainer(currentParent, node.stateNode);726 } else {727 clearSuspenseBoundary(currentParent, node.stateNode);728 }729 } else if (node.tag === HostPortal) {730 if (node.child !== null) {731 // When we go into a portal, it becomes the parent to remove from.732 // We will reassign it back when we pop the portal on the way up.733 currentParent = node.stateNode.containerInfo;734 currentParentIsContainer = true; // Visit children because portals might contain host components.735 node.child.return = node;736 node = node.child;737 continue;738 }739 } else {740 commitUnmount(finishedRoot, node); // Visit children because we may find more host components below.741 if (node.child !== null) {742 node.child.return = node;743 node = node.child;744 continue;745 }746 }747 if (node === current) {748 return;749 }750 while (node.sibling === null) {751 if (node.return === null || node.return === current) {752 return;753 }754 node = node.return;755 if (node.tag === HostPortal) {756 // When we go out of the portal, we need to restore the parent.757 // Since we don't keep a stack of them, we will search for it.758 currentParentIsValid = false;759 }760 }761 node.sibling.return = node.return;762 node = node.sibling;763 }764 }765 function commitDeletion(finishedRoot, current, renderPriorityLevel) {766 {767 // Recursively delete all host nodes from the parent.768 // Detach refs and call componentWillUnmount() on the whole subtree.769 unmountHostComponents(finishedRoot, current);770 }771 var alternate = current.alternate;772 detachFiberMutation(current);773 if (alternate !== null) {774 detachFiberMutation(alternate);775 }776 }777 function commitWork(current, finishedWork) {778 switch (finishedWork.tag) {779 case FunctionComponent:780 case ForwardRef:781 case MemoComponent:782 case SimpleMemoComponent:783 case Block:784 {785 // Layout effects are destroyed during the mutation phase so that all786 // destroy functions for all fibers are called before any create functions.787 // This prevents sibling component effects from interfering with each other,788 // e.g. a destroy function in one component should never override a ref set...
FiberCommitWork.js
Source:FiberCommitWork.js
...403 node.sibling.return = node.return;404 node = node.sibling;405 }406}407function detachFiberMutation(fiber){408 const alternate = fiber.alternate;409 if (alternate !== null){410 alternate.return = null;411 }412 fiber.return = null;413}414function detachFiberAfterEffects(fiber){415 const alternate = fiber.alternate;416 if (alternate !== null){417 fiber.alternate = null;418 detachFiberAfterEffects(alternate);419 }420 fiber.child = null;421 fiber.deletions = null;422 fiber.sibling = null;423 if (fiber.tag === HostComponent){424 if(fiber.stateNode !== null){425 detachDeletedInstance(fiber.stateNode);426 }427 }428 fiber.stateNode = null;429}430function toggleAllChildren(finishedWork, isHidden){431 let hostSubtreeRoot = null;432 let node = finishedWork;433 while(true){434 if (node.tag === HostComponent){435 if(hostSubtreeRoot === null){436 hostSubtreeRoot = node;437 const instance = node.stateNode;438 if (isHidden){439 const style = instance.style;440 if(typeof style.setProperty === 'function'){441 style.setProperty('display', 'none', 'important');442 } else {443 style.display = 'none';444 }445 } else {446 instance.style.removeProperty('display');447 }448 }449 } else if (node.tag === HostText){450 if(hostSubtreeRoot === null){451 const instance = node.stateNode;452 if (isHidden){453 instance.nodeValue ='';454 } else {455 instance.nodeValue = node.memoizedProps;456 }457 }458 } else if(459 node.tag === OffscreenComponent &&460 node.memoizedState !== null &&461 node !== finishedWork462 ){463 debugger;464 } else if (node.child !== null){465 node.child.return = node;466 node = node.child;467 continue;468 }469 if (node == finishedWork){470 return;471 }472 while(node.sibling === null){473 if (node.return === null || node.return === finishedWork){474 return;475 }476 if(hostSubtreeRoot === node){477 hostSubtreeRoot = null;478 }479 node = node.return;480 }481 if(hostSubtreeRoot === node){482 hostSubtreeRoot = null;483 }484 node.sibling.return = node.return;485 node = node.sibling;486 }487}488function getHostParentFiber(fiber){489 let parent = fiber.return;490 while (parent!== null){491 if (isHostParent(parent)){492 return parent;493 }494 parent = parent.return;495 }496}497function isHostParent(fiber){498 return (499 fiber.tag === HostRoot ||500 fiber.tag === HostComponent501 );502}503function getHostSibling(fiber){504 let node = fiber;505 siblings: while (true){506 while(node.sibling === null){507 if (node.return === null || isHostParent(node.return)){508 return null;509 }510 node = node.return;511 }512 node.sibling.return = node.return;513 node = node.sibling;514 while (515 node.tag !== HostComponent &&516 node.tag !== HostText517 ){518 if (node.flags & Placement){519 continue siblings;520 }521 if (node.child === null){522 continue siblings;523 } else {524 node.child.return = node;525 node = node.child;526 }527 }528 if (!(node.flags & Placement)){529 return node.stateNode;530 }531 }532}533function commitPlacement(finishedWork){534 const parentFiber = getHostParentFiber(finishedWork);535 let parent;536 let isContainer;537 const parentStateNode = parentFiber.stateNode;538 switch(parentFiber.tag){539 case HostComponent:540 parent = parentStateNode;541 isContainer = false;542 break;543 case HostRoot:544 parent = parentStateNode.container;545 isContainer = true;546 break;547 default:548 console.error('Unknown parentFiber', parentFiber.tag);549 }550 const before = getHostSibling(finishedWork);551 if(isContainer){552 insertOrAppendPlacementNodeIntoContainer(finishedWork, before, parent);553 } else {554 insertOrAppendPlacementNode(finishedWork, before, parent);555 }556}557function insertOrAppendPlacementNodeIntoContainer(node, before, parent){558 const tag = node.tag;559 const isHost = tag === HostComponent || tag === HostText;560 if (isHost){561 const stateNode =node.stateNode;562 if (before){563 parent.insertBefore(stateNode, before)564 } else {565 parent.append(stateNode);566 }567 } else {568 const child = node.child;569 if (child !== null){570 insertOrAppendPlacementNodeIntoContainer(child, before, parent);571 let sibling = child.sibling;572 while (sibling !== null ){573 insertOrAppendPlacementNodeIntoContainer(574 sibling, 575 before, 576 parent);577 sibling = sibling.sibling;578 }579 }580 }581}582function insertOrAppendPlacementNode(node, before, parent){583 const tag = node.tag;584 const isHost = tag === HostComponent || tag === HostText;585 if (isHost){586 const stateNode = node.stateNode;587 if (before){588 parent.insertBefore(stateNode, before);589 } else {590 parent.append(stateNode);591 }592 } else {593 const child = node.child;594 if(child !== null){595 insertOrAppendPlacementNode(child, before, parent);596 let sibling = child.sibling;597 while(sibling !== null){598 insertOrAppendPlacementNode(sibling, before, parent);599 sibling = sibling.sibling;600 }601 }602 }603}604function unmountHostComponents(finishedRoot, current, nearestMountedAncestor){605 let node = current;606 let currentParentIsValid = false;607 let currentParent;608 let currentParentIsContainer;609 while(true){610 if (!currentParentIsValid){611 let parent = node.return;612 findParent: while(true){613 const parentStateNode = parent.stateNode;614 switch(parent.tag){615 case HostComponent:616 currentParent = parentStateNode;617 currentParentIsContainer = false;618 break findParent;619 case HostRoot:620 currentParent = parentStateNode.container;621 currentParentIsContainer = true;622 break findParent;623 }624 parent = parent.return;625 }626 currentParentIsValid = true;627 }628 if (node.tag === HostComponent || node.tag === HostText){629 commitNestedUnmounts(finishedRoot, node, nearestMountedAncestor);630 currentParent.removeChild(node.stateNode);631 } else {632 commitUnmount(finishedRoot, node, nearestMountedAncestor);633 if (node.child !== null){634 node.child.return = node;635 node = node.child;636 continue;637 }638 }639 if (node === current){640 return;641 }642 while (node.sibling === null){643 if (node.return === null || node.return === current){644 return;645 }646 node = node.return;647 }648 node.sibling.return = node.return;649 node = node.sibling;650 }651}652function commitDeletion(finishedRoot, current, nearestMountedAncestor){653 unmountHostComponents(finishedRoot, current, nearestMountedAncestor);654 detachFiberMutation(current);655}656function commitWork(current, finishedWork){657 switch(finishedWork.tag){658 case HostComponent:{659 const instance = finishedWork.stateNode;660 if (instance !== null){661 const newProps = finishedWork.memoizedProps;662 const oldProps = current !== null ? current.memoizedProps : newProps;663 const type = finishedWork.type;664 const updatePayload = finishedWork.updateQueue;665 finishedWork.updateQueue = null;666 if (updatePayload !== null){667 commitUpdate(668 instance,...
ReactFiberCommitWork.js
Source:ReactFiberCommitWork.js
...355};356const commitDeletion = (finishedRoot, current, renderPriorityLevel) => {357 unmountHostComponents(finishedRoot, current, renderPriorityLevel);358 const alternate = current.alternate;359 detachFiberMutation(current);360 if (alternate !== null) {361 detachFiberMutation(alternate);362 }363};364export {365 isSuspenseBoundaryBeingHidden,366 commitBeforeMutationLifeCycles,367 commitResetTextContent,368 commitDetachRef,369 commitPlacement,370 commitWork,371 commitDeletion,...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('input[title="Search"]', 'Playwright');7 await page.click('text=Google Search');8 await page.waitForSelector('text=Playwright');9 const elementHandle = await page.$('text=Playwright');10 const element = await elementHandle._client.send('DOM.describeNode', { objectId: elementHandle._remoteObject.objectId });11 await page._delegate._connection._session.send('DOM.detachFiberMutation', { nodeId: element.nodeId });12 await page.click('text=Playwright');13 await page.waitForSelector('text=Playwright');14 await page.waitForTimeout(5000);15 await page.close();16 await context.close();17 await browser.close();18})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('text=Get started');7 await page.click('text=Get started');8 await page.waitForSelector('text=API reference');9 const element = await page.$('text=API reference');10 await element._delegate.detachFiberMutation();11 await page.waitForSelector('text=API reference');12 await browser.close();13})();
Using AI Code Generation
1const playwright = require("playwright");2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const elementHandle = await page.$("text=Docs");7 await elementHandle.evaluate((element) => {8 element.detachFiberMutation();9 });10 await page.screenshot({ path: "example.png" });11 await browser.close();12})();13const { devices } = require("playwright");14module.exports = {15 {16 use: {17 viewport: { width: 1920, height: 1080 },18 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36",19 },20 },21 {22 use: {23 },24 },25};26{27 "scripts": {28 },29 "devDependencies": {30 }31}32const playwright = require("playwright");33(async () => {34 const browser = await playwright.chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 const elementHandle = await page.$("text=Docs");38 await elementHandle.evaluate((element) => {39 element.detachFiberMutation();40 });41 await page.screenshot({ path: "example.png" });42 await browser.close();43})();44const { devices } = require("playwright");45module.exports = {46 {47 use: {48 viewport: { width: 1920, height: 1080 },49 "Mozilla/5.0 (
Using AI Code Generation
1const { detachFiberMutation } = require('playwright/lib/server/fiber');2const { attachFiberMutation } = require('playwright/lib/server/fiber');3detachFiberMutation();4attachFiberMutation();5detachFiberMutation();6attachFiberMutation();7detachFiberMutation();8attachFiberMutation();9detachFiberMutation();10attachFiberMutation();11detachFiberMutation();12attachFiberMutation();13detachFiberMutation();14attachFiberMutation();15detachFiberMutation();16attachFiberMutation();17detachFiberMutation();18attachFiberMutation();19detachFiberMutation();20attachFiberMutation();21detachFiberMutation();22attachFiberMutation();23detachFiberMutation();24attachFiberMutation();
Using AI Code Generation
1const { chromium } = require('playwright');2const { detachFiberMutation } = require('playwright/lib/internal/recorder/recorderUtils');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.click('input[type="text"]', {force: true});7 await page.type('input[type="text"]', 'Hello World');8 await page.keyboard.press('Enter');9 await page.waitForSelector('text="Hello World"');10 const elementHandle = await page.$('text="Hello World"');11 await elementHandle.click();12 await page.screenshot({ path: 'screenshot.png' });13 await browser.close();14})();15const { chromium } = require('playwright');16const { detachFiberMutation } = require('playwright/lib/internal/recorder/recorderUtils');17(async () => {18 const browser = await chromium.launch();19 const page = await browser.newPage();20 await page.click('input[type="text"]', {force: true});21 await page.type('input[type="text"]', 'Hello World');22 await page.keyboard.press('Enter');23 await page.waitForSelector('text="Hello World"');24 const elementHandle = await page.$('text="Hello World"');25 await elementHandle.click();26 await page.screenshot({ path: 'screenshot.png' });27 await browser.close();28})();29const { chromium } = require('playwright');30const { detachFiberMutation } = require('playwright/lib/internal/recorder/recorderUtils');31(async () => {32 const browser = await chromium.launch();33 const page = await browser.newPage();34 await page.click('input[type="text"]', {force: true});35 await page.type('input[type="text"]', 'Hello World');36 await page.keyboard.press('Enter');37 await page.waitForSelector('text="Hello World"');38 const elementHandle = await page.$('text="Hello World"');39 await elementHandle.click();40 await page.screenshot({ path: 'screenshot
Using AI Code Generation
1const { attachFiberMutation, detachFiberMutation } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await attachFiberMutation(page);8 await detachFiberMutation(page);9 await browser.close();10})();11const { test, expect } = require('@playwright/test');12test('testing', async ({ page }) => {13 await page.evaluate(() => {14 document.querySelector('text=Get started').click();15 });16 await page.waitForSelector('text=Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API.');17 const element = await page.$('text=Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API.');18 const text = await element.evaluate(node => node.textContent);19 expect(text).toBe('Playwright is a Node library to automate Chromium, Firefox and WebKit with a single API.');20});21 Error: Protocol error (Runtime.callFunctionOn): Cannot find context with specified id undefined
Using AI Code Generation
1const { attachFiberMutation, detachFiberMutation } = require('playwright/lib/server/fiber');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForSelector('text=Learn more');8 await page.click('text=Learn more');9 await page.waitForSelector('text=Getting started');10 await page.click('text=Getting started');11 await page.waitForSelector('text=Playwright is a Node library to automate');12 await page.evaluate(() => {13 const h1 = document.querySelector('h1');14 const h2 = document.querySelector('h2');15 const h3 = document.querySelector('h3');16 const h4 = document.querySelector('h4');17 const h5 = document.querySelector('h5');18 const h6 = document.querySelector('h6');19 const p = document.querySelector('p');20 const div = document.querySelector('div');21 const span = document.querySelector('span');22 const a = document.querySelector('a');23 attachFiberMutation(h1);24 attachFiberMutation(h2);25 attachFiberMutation(h3);26 attachFiberMutation(h4);27 attachFiberMutation(h5);28 attachFiberMutation(h6);29 attachFiberMutation(p);30 attachFiberMutation(div);31 attachFiberMutation(span);32 attachFiberMutation(a);33 detachFiberMutation(h1);34 detachFiberMutation(h2);35 detachFiberMutation(h3);36 detachFiberMutation(h4);37 detachFiberMutation(h5);38 detachFiberMutation(h6);39 detachFiberMutation(p);40 detachFiberMutation(div);41 detachFiberMutation(span);42 detachFiberMutation(a);43 });44 await browser.close();45})();
Using AI Code Generation
1const { Playwright } = require('playwright');2const { detachFiberMutation } = Playwright.internal;3const { chromium } = require('playwright-chromium');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.waitForTimeout(1000);9 await detachFiberMutation();10 await page.screenshot({ path: 'example.png' });11 await browser.close();12})();13const { Playwright } = require('playwright');14const { detachFiberMutation } = Playwright.internal;15const { chromium } = require('playwright-chromium');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await page.waitForTimeout(1000);21 await detachFiberMutation();22 await page.screenshot({ path: 'example.png' });23 await browser.close();24})();25const { Playwright } = require('playwright');26const { detachFiberMutation } = Playwright.internal;27const { chromium } = require('playwright-chromium');28(async () => {29 const browser = await chromium.launch();30 const context = await browser.newContext();31 const page = await context.newPage();32 await page.waitForTimeout(1000);33 await detachFiberMutation();34 await page.screenshot({ path: 'example.png' });35 await browser.close();36})();37const { Playwright } = require('playwright');38const { detachFiberMutation } = Playwright.internal;39const { chromium } = require('playwright-chromium');40(async () => {41 const browser = await chromium.launch();42 const context = await browser.newContext();43 const page = await context.newPage();44 await page.waitForTimeout(1000);45 await detachFiberMutation();46 await page.screenshot({ path: '
Using AI Code Generation
1const { detachFiberMutation } = require('playwright/lib/utils/attachToFrames');2const { chromium } = require('playwright');3const fs = require('fs');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.waitForLoadState('domcontentloaded');9 const handle = await page.$('text="API"');10 const content = await handle.textContent();11 await page.screenshot({ path: `example.png` });12 console.log(content);13 await detachFiberMutation();14 await browser.close();15})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { detachFiberMutation } = require('playwright/lib/server/dom');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const fiber = await page.evaluateHandle(() => {8 const fiber = document.createElement('div');9 fiber.id = 'fiber';10 fiber.style.width = '100px';11 fiber.style.height = '100px';12 fiber.style.backgroundColor = 'red';13 document.body.appendChild(fiber);14 return fiber;15 });16 await page.evaluate(detachFiberMutation, fiber);17 await fiber.click();18 await browser.close();19})();20const { chromium } = require('playwright');21const { detachFiberMutation } = require('playwright/lib/server/dom');22(async () => {23 const browser = await chromium.launch();24 const context = await browser.newContext();25 const page = await context.newPage();26 const fiber = await page.evaluateHandle(() => {27 const fiber = document.createElement('div');28 fiber.id = 'fiber';29 fiber.style.width = '100px';30 fiber.style.height = '100px';31 fiber.style.backgroundColor = 'red';32 document.body.appendChild(fiber);33 return fiber;34 });35 await page.evaluate(detachFiberMutation, fiber);36 await fiber.click();37 await browser.close();38})();39const { chromium } = require('playwright');40const { detachFiberMutation } = require('playwright/lib/server/dom');41(async () => {42 const browser = await chromium.launch();43 const context = await browser.newContext();44 const page = await context.newPage();45 const fiber = await page.evaluateHandle(() => {46 const fiber = document.createElement('div');
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!