Best JavaScript code snippet using playwright-internal
ReactFiberCommitWork.new.js
Source:ReactFiberCommitWork.new.js
...197 ref.current = null;198 }199 }200}201export function safelyCallDestroy(202 current: Fiber,203 nearestMountedAncestor: Fiber | null,204 destroy: () => void,205) {206 if (__DEV__) {207 invokeGuardedCallback(null, destroy, null);208 if (hasCaughtError()) {209 const error = clearCaughtError();210 captureCommitPhaseError(current, nearestMountedAncestor, error);211 }212 } else {213 try {214 destroy();215 } catch (error) {216 captureCommitPhaseError(current, nearestMountedAncestor, error);217 }218 }219}220function commitBeforeMutationLifeCycles(221 current: Fiber | null,222 finishedWork: Fiber,223): void {224 switch (finishedWork.tag) {225 case FunctionComponent:226 case ForwardRef:227 case SimpleMemoComponent:228 case Block: {229 return;230 }231 case ClassComponent: {232 if (finishedWork.flags & Snapshot) {233 if (current !== null) {234 const prevProps = current.memoizedProps;235 const prevState = current.memoizedState;236 const instance = finishedWork.stateNode;237 // We could update instance props and state here,238 // but instead we rely on them being set during last render.239 // TODO: revisit this when we implement resuming.240 if (__DEV__) {241 if (242 finishedWork.type === finishedWork.elementType &&243 !didWarnAboutReassigningProps244 ) {245 if (instance.props !== finishedWork.memoizedProps) {246 console.error(247 'Expected %s props to match memoized props before ' +248 'getSnapshotBeforeUpdate. ' +249 'This might either be because of a bug in React, or because ' +250 'a component reassigns its own `this.props`. ' +251 'Please file an issue.',252 getComponentName(finishedWork.type) || 'instance',253 );254 }255 if (instance.state !== finishedWork.memoizedState) {256 console.error(257 'Expected %s state to match memoized state before ' +258 'getSnapshotBeforeUpdate. ' +259 'This might either be because of a bug in React, or because ' +260 'a component reassigns its own `this.state`. ' +261 'Please file an issue.',262 getComponentName(finishedWork.type) || 'instance',263 );264 }265 }266 }267 const snapshot = instance.getSnapshotBeforeUpdate(268 finishedWork.elementType === finishedWork.type269 ? prevProps270 : resolveDefaultProps(finishedWork.type, prevProps),271 prevState,272 );273 if (__DEV__) {274 const didWarnSet = ((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set<mixed>);275 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {276 didWarnSet.add(finishedWork.type);277 console.error(278 '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +279 'must be returned. You have returned undefined.',280 getComponentName(finishedWork.type),281 );282 }283 }284 instance.__reactInternalSnapshotBeforeUpdate = snapshot;285 }286 }287 return;288 }289 case HostRoot: {290 if (supportsMutation) {291 if (finishedWork.flags & Snapshot) {292 const root = finishedWork.stateNode;293 clearContainer(root.containerInfo);294 }295 }296 return;297 }298 case HostComponent:299 case HostText:300 case HostPortal:301 case IncompleteClassComponent:302 // Nothing to do for these component types303 return;304 }305 invariant(306 false,307 'This unit of work tag should not have side-effects. This error is ' +308 'likely caused by a bug in React. Please file an issue.',309 );310}311function commitHookEffectListUnmount(312 tag: HookFlags,313 finishedWork: Fiber,314 nearestMountedAncestor: Fiber | null,315) {316 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);317 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;318 if (lastEffect !== null) {319 const firstEffect = lastEffect.next;320 let effect = firstEffect;321 do {322 if ((effect.tag & tag) === tag) {323 // Unmount324 const destroy = effect.destroy;325 effect.destroy = undefined;326 if (destroy !== undefined) {327 safelyCallDestroy(finishedWork, nearestMountedAncestor, destroy);328 }329 }330 effect = effect.next;331 } while (effect !== firstEffect);332 }333}334// TODO: Remove this duplication.335function commitHookEffectListUnmount2(336 // Tags to check for when deciding whether to unmount. e.g. to skip over layout effects337 hookFlags: HookFlags,338 fiber: Fiber,339 nearestMountedAncestor: Fiber | null,340): void {341 const updateQueue: FunctionComponentUpdateQueue | null = (fiber.updateQueue: any);342 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;343 if (lastEffect !== null) {344 const firstEffect = lastEffect.next;345 let effect = firstEffect;346 do {347 const {next, tag} = effect;348 if ((tag & hookFlags) === hookFlags) {349 const destroy = effect.destroy;350 if (destroy !== undefined) {351 effect.destroy = undefined;352 if (353 enableProfilerTimer &&354 enableProfilerCommitHooks &&355 fiber.mode & ProfileMode356 ) {357 startPassiveEffectTimer();358 safelyCallDestroy(fiber, nearestMountedAncestor, destroy);359 recordPassiveEffectDuration(fiber);360 } else {361 safelyCallDestroy(fiber, nearestMountedAncestor, destroy);362 }363 }364 }365 effect = next;366 } while (effect !== firstEffect);367 }368}369function commitHookEffectListMount(tag: HookFlags, finishedWork: Fiber) {370 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);371 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;372 if (lastEffect !== null) {373 const firstEffect = lastEffect.next;374 let effect = firstEffect;375 do {376 if ((effect.tag & tag) === tag) {377 // Mount378 const create = effect.create;379 effect.destroy = create();380 if (__DEV__) {381 const destroy = effect.destroy;382 if (destroy !== undefined && typeof destroy !== 'function') {383 let addendum;384 if (destroy === null) {385 addendum =386 ' You returned null. If your effect does not require clean ' +387 'up, return undefined (or nothing).';388 } else if (typeof destroy.then === 'function') {389 addendum =390 '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' +391 'Instead, write the async function inside your effect ' +392 'and call it immediately:\n\n' +393 'useEffect(() => {\n' +394 ' async function fetchData() {\n' +395 ' // You can await here\n' +396 ' const response = await MyAPI.getData(someId);\n' +397 ' // ...\n' +398 ' }\n' +399 ' fetchData();\n' +400 `}, [someId]); // Or [] if effect doesn't need props or state\n\n` +401 'Learn more about data fetching with Hooks: https://reactjs.org/link/hooks-data-fetching';402 } else {403 addendum = ' You returned: ' + destroy;404 }405 console.error(406 'An effect function must not return anything besides a function, ' +407 'which is used for clean-up.%s',408 addendum,409 );410 }411 }412 }413 effect = effect.next;414 } while (effect !== firstEffect);415 }416}417function invokePassiveEffectCreate(effect: HookEffect): void {418 const create = effect.create;419 effect.destroy = create();420}421// TODO: Remove this duplication.422function commitHookEffectListMount2(fiber: Fiber): void {423 const updateQueue: FunctionComponentUpdateQueue | null = (fiber.updateQueue: any);424 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;425 if (lastEffect !== null) {426 const firstEffect = lastEffect.next;427 let effect = firstEffect;428 do {429 const {next, tag} = effect;430 if (431 (tag & HookPassive) !== NoHookEffect &&432 (tag & HookHasEffect) !== NoHookEffect433 ) {434 if (__DEV__) {435 if (436 enableProfilerTimer &&437 enableProfilerCommitHooks &&438 fiber.mode & ProfileMode439 ) {440 startPassiveEffectTimer();441 invokeGuardedCallback(442 null,443 invokePassiveEffectCreate,444 null,445 effect,446 );447 recordPassiveEffectDuration(fiber);448 } else {449 invokeGuardedCallback(450 null,451 invokePassiveEffectCreate,452 null,453 effect,454 );455 }456 if (hasCaughtError()) {457 invariant(fiber !== null, 'Should be working on an effect.');458 const error = clearCaughtError();459 captureCommitPhaseError(fiber, fiber.return, error);460 }461 } else {462 try {463 const create = effect.create;464 if (465 enableProfilerTimer &&466 enableProfilerCommitHooks &&467 fiber.mode & ProfileMode468 ) {469 try {470 startPassiveEffectTimer();471 effect.destroy = create();472 } finally {473 recordPassiveEffectDuration(fiber);474 }475 } else {476 effect.destroy = create();477 }478 // TODO: This is missing the warning that exists in commitHookEffectListMount.479 // The warning refers to useEffect but only applies to useLayoutEffect.480 } catch (error) {481 invariant(fiber !== null, 'Should be working on an effect.');482 captureCommitPhaseError(fiber, fiber.return, error);483 }484 }485 }486 effect = next;487 } while (effect !== firstEffect);488 }489}490function commitProfilerPassiveEffect(491 finishedRoot: FiberRoot,492 finishedWork: Fiber,493): void {494 if (enableProfilerTimer && enableProfilerCommitHooks) {495 switch (finishedWork.tag) {496 case Profiler: {497 const {passiveEffectDuration} = finishedWork.stateNode;498 const {id, onPostCommit} = finishedWork.memoizedProps;499 // This value will still reflect the previous commit phase.500 // It does not get reset until the start of the next commit phase.501 const commitTime = getCommitTime();502 if (typeof onPostCommit === 'function') {503 if (enableSchedulerTracing) {504 onPostCommit(505 id,506 finishedWork.alternate === null ? 'mount' : 'update',507 passiveEffectDuration,508 commitTime,509 finishedRoot.memoizedInteractions,510 );511 } else {512 onPostCommit(513 id,514 finishedWork.alternate === null ? 'mount' : 'update',515 passiveEffectDuration,516 commitTime,517 );518 }519 }520 // Bubble times to the next nearest ancestor Profiler.521 // After we process that Profiler, we'll bubble further up.522 // TODO: Use JS Stack instead523 let parentFiber = finishedWork.return;524 while (parentFiber !== null) {525 if (parentFiber.tag === Profiler) {526 const parentStateNode = parentFiber.stateNode;527 parentStateNode.passiveEffectDuration += passiveEffectDuration;528 break;529 }530 parentFiber = parentFiber.return;531 }532 break;533 }534 default:535 break;536 }537 }538}539function commitLifeCycles(540 finishedRoot: FiberRoot,541 current: Fiber | null,542 finishedWork: Fiber,543 committedLanes: Lanes,544): void {545 switch (finishedWork.tag) {546 case FunctionComponent:547 case ForwardRef:548 case SimpleMemoComponent:549 case Block: {550 // At this point layout effects have already been destroyed (during mutation phase).551 // This is done to prevent sibling component effects from interfering with each other,552 // e.g. a destroy function in one component should never override a ref set553 // by a create function in another component during the same commit.554 if (555 enableProfilerTimer &&556 enableProfilerCommitHooks &&557 finishedWork.mode & ProfileMode558 ) {559 try {560 startLayoutEffectTimer();561 commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);562 } finally {563 recordLayoutEffectDuration(finishedWork);564 }565 } else {566 commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);567 }568 if ((finishedWork.subtreeFlags & PassiveMask) !== NoFlags) {569 schedulePassiveEffectCallback();570 }571 return;572 }573 case ClassComponent: {574 const instance = finishedWork.stateNode;575 if (finishedWork.flags & Update) {576 if (current === null) {577 // We could update instance props and state here,578 // but instead we rely on them being set during last render.579 // TODO: revisit this when we implement resuming.580 if (__DEV__) {581 if (582 finishedWork.type === finishedWork.elementType &&583 !didWarnAboutReassigningProps584 ) {585 if (instance.props !== finishedWork.memoizedProps) {586 console.error(587 'Expected %s props to match memoized props before ' +588 'componentDidMount. ' +589 'This might either be because of a bug in React, or because ' +590 'a component reassigns its own `this.props`. ' +591 'Please file an issue.',592 getComponentName(finishedWork.type) || 'instance',593 );594 }595 if (instance.state !== finishedWork.memoizedState) {596 console.error(597 'Expected %s state to match memoized state before ' +598 'componentDidMount. ' +599 'This might either be because of a bug in React, or because ' +600 'a component reassigns its own `this.state`. ' +601 'Please file an issue.',602 getComponentName(finishedWork.type) || 'instance',603 );604 }605 }606 }607 if (608 enableProfilerTimer &&609 enableProfilerCommitHooks &&610 finishedWork.mode & ProfileMode611 ) {612 try {613 startLayoutEffectTimer();614 instance.componentDidMount();615 } finally {616 recordLayoutEffectDuration(finishedWork);617 }618 } else {619 instance.componentDidMount();620 }621 } else {622 const prevProps =623 finishedWork.elementType === finishedWork.type624 ? current.memoizedProps625 : resolveDefaultProps(finishedWork.type, current.memoizedProps);626 const prevState = current.memoizedState;627 // We could update instance props and state here,628 // but instead we rely on them being set during last render.629 // TODO: revisit this when we implement resuming.630 if (__DEV__) {631 if (632 finishedWork.type === finishedWork.elementType &&633 !didWarnAboutReassigningProps634 ) {635 if (instance.props !== finishedWork.memoizedProps) {636 console.error(637 'Expected %s props to match memoized props before ' +638 'componentDidUpdate. ' +639 'This might either be because of a bug in React, or because ' +640 'a component reassigns its own `this.props`. ' +641 'Please file an issue.',642 getComponentName(finishedWork.type) || 'instance',643 );644 }645 if (instance.state !== finishedWork.memoizedState) {646 console.error(647 'Expected %s state to match memoized state before ' +648 'componentDidUpdate. ' +649 'This might either be because of a bug in React, or because ' +650 'a component reassigns its own `this.state`. ' +651 'Please file an issue.',652 getComponentName(finishedWork.type) || 'instance',653 );654 }655 }656 }657 if (658 enableProfilerTimer &&659 enableProfilerCommitHooks &&660 finishedWork.mode & ProfileMode661 ) {662 try {663 startLayoutEffectTimer();664 instance.componentDidUpdate(665 prevProps,666 prevState,667 instance.__reactInternalSnapshotBeforeUpdate,668 );669 } finally {670 recordLayoutEffectDuration(finishedWork);671 }672 } else {673 instance.componentDidUpdate(674 prevProps,675 prevState,676 instance.__reactInternalSnapshotBeforeUpdate,677 );678 }679 }680 }681 // TODO: I think this is now always non-null by the time it reaches the682 // commit phase. Consider removing the type check.683 const updateQueue: UpdateQueue<684 *,685 > | null = (finishedWork.updateQueue: any);686 if (updateQueue !== null) {687 if (__DEV__) {688 if (689 finishedWork.type === finishedWork.elementType &&690 !didWarnAboutReassigningProps691 ) {692 if (instance.props !== finishedWork.memoizedProps) {693 console.error(694 'Expected %s props to match memoized props before ' +695 'processing the update queue. ' +696 'This might either be because of a bug in React, or because ' +697 'a component reassigns its own `this.props`. ' +698 'Please file an issue.',699 getComponentName(finishedWork.type) || 'instance',700 );701 }702 if (instance.state !== finishedWork.memoizedState) {703 console.error(704 'Expected %s state to match memoized state before ' +705 'processing the update queue. ' +706 'This might either be because of a bug in React, or because ' +707 'a component reassigns its own `this.state`. ' +708 'Please file an issue.',709 getComponentName(finishedWork.type) || 'instance',710 );711 }712 }713 }714 // We could update instance props and state here,715 // but instead we rely on them being set during last render.716 // TODO: revisit this when we implement resuming.717 commitUpdateQueue(finishedWork, updateQueue, instance);718 }719 return;720 }721 case HostRoot: {722 // TODO: I think this is now always non-null by the time it reaches the723 // commit phase. Consider removing the type check.724 const updateQueue: UpdateQueue<725 *,726 > | null = (finishedWork.updateQueue: any);727 if (updateQueue !== null) {728 let instance = null;729 if (finishedWork.child !== null) {730 switch (finishedWork.child.tag) {731 case HostComponent:732 instance = getPublicInstance(finishedWork.child.stateNode);733 break;734 case ClassComponent:735 instance = finishedWork.child.stateNode;736 break;737 }738 }739 commitUpdateQueue(finishedWork, updateQueue, instance);740 }741 return;742 }743 case HostComponent: {744 const instance: Instance = finishedWork.stateNode;745 // Renderers may schedule work to be done after host components are mounted746 // (eg DOM renderer may schedule auto-focus for inputs and form controls).747 // These effects should only be committed when components are first mounted,748 // aka when there is no current/alternate.749 if (current === null && finishedWork.flags & Update) {750 const type = finishedWork.type;751 const props = finishedWork.memoizedProps;752 commitMount(instance, type, props, finishedWork);753 }754 return;755 }756 case HostText: {757 // We have no life-cycles associated with text.758 return;759 }760 case HostPortal: {761 // We have no life-cycles associated with portals.762 return;763 }764 case Profiler: {765 if (enableProfilerTimer) {766 const {onCommit, onRender} = finishedWork.memoizedProps;767 const {effectDuration} = finishedWork.stateNode;768 const commitTime = getCommitTime();769 if (typeof onRender === 'function') {770 if (enableSchedulerTracing) {771 onRender(772 finishedWork.memoizedProps.id,773 current === null ? 'mount' : 'update',774 finishedWork.actualDuration,775 finishedWork.treeBaseDuration,776 finishedWork.actualStartTime,777 commitTime,778 finishedRoot.memoizedInteractions,779 );780 } else {781 onRender(782 finishedWork.memoizedProps.id,783 current === null ? 'mount' : 'update',784 finishedWork.actualDuration,785 finishedWork.treeBaseDuration,786 finishedWork.actualStartTime,787 commitTime,788 );789 }790 }791 if (enableProfilerCommitHooks) {792 if (typeof onCommit === 'function') {793 if (enableSchedulerTracing) {794 onCommit(795 finishedWork.memoizedProps.id,796 current === null ? 'mount' : 'update',797 effectDuration,798 commitTime,799 finishedRoot.memoizedInteractions,800 );801 } else {802 onCommit(803 finishedWork.memoizedProps.id,804 current === null ? 'mount' : 'update',805 effectDuration,806 commitTime,807 );808 }809 }810 // Propagate layout effect durations to the next nearest Profiler ancestor.811 // Do not reset these values until the next render so DevTools has a chance to read them first.812 // TODO: Use JS Stack instead813 let parentFiber = finishedWork.return;814 while (parentFiber !== null) {815 if (parentFiber.tag === Profiler) {816 const parentStateNode = parentFiber.stateNode;817 parentStateNode.effectDuration += effectDuration;818 break;819 }820 parentFiber = parentFiber.return;821 }822 }823 }824 return;825 }826 case SuspenseComponent: {827 commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);828 return;829 }830 case SuspenseListComponent:831 case IncompleteClassComponent:832 case FundamentalComponent:833 case ScopeComponent:834 case OffscreenComponent:835 case LegacyHiddenComponent:836 return;837 }838 invariant(839 false,840 'This unit of work tag should not have side-effects. This error is ' +841 'likely caused by a bug in React. Please file an issue.',842 );843}844function hideOrUnhideAllChildren(finishedWork, isHidden) {845 if (supportsMutation) {846 // We only have the top Fiber that was inserted but we need to recurse down its847 // children to find all the terminal nodes.848 let node: Fiber = finishedWork;849 while (true) {850 if (node.tag === HostComponent) {851 const instance = node.stateNode;852 if (isHidden) {853 hideInstance(instance);854 } else {855 unhideInstance(node.stateNode, node.memoizedProps);856 }857 } else if (node.tag === HostText) {858 const instance = node.stateNode;859 if (isHidden) {860 hideTextInstance(instance);861 } else {862 unhideTextInstance(instance, node.memoizedProps);863 }864 } else if (865 (node.tag === OffscreenComponent ||866 node.tag === LegacyHiddenComponent) &&867 (node.memoizedState: OffscreenState) !== null &&868 node !== finishedWork869 ) {870 // Found a nested Offscreen component that is hidden. Don't search871 // any deeper. This tree should remain hidden.872 } else if (node.child !== null) {873 node.child.return = node;874 node = node.child;875 continue;876 }877 if (node === finishedWork) {878 return;879 }880 while (node.sibling === null) {881 if (node.return === null || node.return === finishedWork) {882 return;883 }884 node = node.return;885 }886 node.sibling.return = node.return;887 node = node.sibling;888 }889 }890}891function commitAttachRef(finishedWork: Fiber) {892 const ref = finishedWork.ref;893 if (ref !== null) {894 const instance = finishedWork.stateNode;895 let instanceToUse;896 switch (finishedWork.tag) {897 case HostComponent:898 instanceToUse = getPublicInstance(instance);899 break;900 default:901 instanceToUse = instance;902 }903 // Moved outside to ensure DCE works with this flag904 if (enableScopeAPI && finishedWork.tag === ScopeComponent) {905 instanceToUse = instance;906 }907 if (typeof ref === 'function') {908 ref(instanceToUse);909 } else {910 if (__DEV__) {911 if (!ref.hasOwnProperty('current')) {912 console.error(913 'Unexpected ref object provided for %s. ' +914 'Use either a ref-setter function or React.createRef().',915 getComponentName(finishedWork.type),916 );917 }918 }919 ref.current = instanceToUse;920 }921 }922}923function commitDetachRef(current: Fiber) {924 const currentRef = current.ref;925 if (currentRef !== null) {926 if (typeof currentRef === 'function') {927 currentRef(null);928 } else {929 currentRef.current = null;930 }931 }932}933// User-originating errors (lifecycles and refs) should not interrupt934// deletion, so don't let them throw. Host-originating errors should935// interrupt deletion, so it's okay936function commitUnmount(937 finishedRoot: FiberRoot,938 current: Fiber,939 nearestMountedAncestor: Fiber,940 renderPriorityLevel: ReactPriorityLevel,941): void {942 onCommitUnmount(current);943 switch (current.tag) {944 case FunctionComponent:945 case ForwardRef:946 case MemoComponent:947 case SimpleMemoComponent:948 case Block: {949 const updateQueue: FunctionComponentUpdateQueue | null = (current.updateQueue: any);950 if (updateQueue !== null) {951 const lastEffect = updateQueue.lastEffect;952 if (lastEffect !== null) {953 const firstEffect = lastEffect.next;954 let effect = firstEffect;955 do {956 const {destroy, tag} = effect;957 if (destroy !== undefined) {958 if ((tag & HookLayout) !== NoHookEffect) {959 if (960 enableProfilerTimer &&961 enableProfilerCommitHooks &&962 current.mode & ProfileMode963 ) {964 startLayoutEffectTimer();965 safelyCallDestroy(current, nearestMountedAncestor, destroy);966 recordLayoutEffectDuration(current);967 } else {968 safelyCallDestroy(current, nearestMountedAncestor, destroy);969 }970 }971 }972 effect = effect.next;973 } while (effect !== firstEffect);974 }975 }976 return;977 }978 case ClassComponent: {979 safelyDetachRef(current, nearestMountedAncestor);980 const instance = current.stateNode;981 if (typeof instance.componentWillUnmount === 'function') {982 safelyCallComponentWillUnmount(...
ReactFiberCommitWork.old.js
Source:ReactFiberCommitWork.old.js
...200 ref.current = null;201 }202 }203}204function safelyCallDestroy(current, destroy) {205 if (__DEV__) {206 invokeGuardedCallback(null, destroy, null);207 if (hasCaughtError()) {208 const error = clearCaughtError();209 captureCommitPhaseError(current, error);210 }211 } else {212 try {213 destroy();214 } catch (error) {215 captureCommitPhaseError(current, error);216 }217 }218}219function commitBeforeMutationLifeCycles(220 current: Fiber | null,221 finishedWork: Fiber,222): void {223 switch (finishedWork.tag) {224 case FunctionComponent:225 case ForwardRef:226 case SimpleMemoComponent:227 case Block: {228 return;229 }230 case ClassComponent: {231 if (finishedWork.effectTag & Snapshot) {232 if (current !== null) {233 const prevProps = current.memoizedProps;234 const prevState = current.memoizedState;235 const instance = finishedWork.stateNode;236 // We could update instance props and state here,237 // but instead we rely on them being set during last render.238 // TODO: revisit this when we implement resuming.239 if (__DEV__) {240 if (241 finishedWork.type === finishedWork.elementType &&242 !didWarnAboutReassigningProps243 ) {244 if (instance.props !== finishedWork.memoizedProps) {245 console.error(246 'Expected %s props to match memoized props before ' +247 'getSnapshotBeforeUpdate. ' +248 'This might either be because of a bug in React, or because ' +249 'a component reassigns its own `this.props`. ' +250 'Please file an issue.',251 getComponentName(finishedWork.type) || 'instance',252 );253 }254 if (instance.state !== finishedWork.memoizedState) {255 console.error(256 'Expected %s state to match memoized state before ' +257 'getSnapshotBeforeUpdate. ' +258 'This might either be because of a bug in React, or because ' +259 'a component reassigns its own `this.state`. ' +260 'Please file an issue.',261 getComponentName(finishedWork.type) || 'instance',262 );263 }264 }265 }266 const snapshot = instance.getSnapshotBeforeUpdate(267 finishedWork.elementType === finishedWork.type268 ? prevProps269 : resolveDefaultProps(finishedWork.type, prevProps),270 prevState,271 );272 if (__DEV__) {273 const didWarnSet = ((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set<mixed>);274 if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {275 didWarnSet.add(finishedWork.type);276 console.error(277 '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +278 'must be returned. You have returned undefined.',279 getComponentName(finishedWork.type),280 );281 }282 }283 instance.__reactInternalSnapshotBeforeUpdate = snapshot;284 }285 }286 return;287 }288 case HostRoot:289 case HostComponent:290 case HostText:291 case HostPortal:292 case IncompleteClassComponent:293 // Nothing to do for these component types294 return;295 }296 invariant(297 false,298 'This unit of work tag should not have side-effects. This error is ' +299 'likely caused by a bug in React. Please file an issue.',300 );301}302function commitHookEffectListUnmount(tag: number, finishedWork: Fiber) {303 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);304 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;305 if (lastEffect !== null) {306 const firstEffect = lastEffect.next;307 let effect = firstEffect;308 do {309 if ((effect.tag & tag) === tag) {310 // Unmount311 const destroy = effect.destroy;312 effect.destroy = undefined;313 if (destroy !== undefined) {314 destroy();315 }316 }317 effect = effect.next;318 } while (effect !== firstEffect);319 }320}321function commitHookEffectListMount(tag: number, finishedWork: Fiber) {322 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);323 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;324 if (lastEffect !== null) {325 const firstEffect = lastEffect.next;326 let effect = firstEffect;327 do {328 if ((effect.tag & tag) === tag) {329 // Mount330 const create = effect.create;331 effect.destroy = create();332 if (__DEV__) {333 const destroy = effect.destroy;334 if (destroy !== undefined && typeof destroy !== 'function') {335 let addendum;336 if (destroy === null) {337 addendum =338 ' You returned null. If your effect does not require clean ' +339 'up, return undefined (or nothing).';340 } else if (typeof destroy.then === 'function') {341 addendum =342 '\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' +343 'Instead, write the async function inside your effect ' +344 'and call it immediately:\n\n' +345 'useEffect(() => {\n' +346 ' async function fetchData() {\n' +347 ' // You can await here\n' +348 ' const response = await MyAPI.getData(someId);\n' +349 ' // ...\n' +350 ' }\n' +351 ' fetchData();\n' +352 `}, [someId]); // Or [] if effect doesn't need props or state\n\n` +353 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching';354 } else {355 addendum = ' You returned: ' + destroy;356 }357 console.error(358 'An effect function must not return anything besides a function, ' +359 'which is used for clean-up.%s%s',360 addendum,361 getStackByFiberInDevAndProd(finishedWork),362 );363 }364 }365 }366 effect = effect.next;367 } while (effect !== firstEffect);368 }369}370function schedulePassiveEffects(finishedWork: Fiber) {371 if (runAllPassiveEffectDestroysBeforeCreates) {372 const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);373 const lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;374 if (lastEffect !== null) {375 const firstEffect = lastEffect.next;376 let effect = firstEffect;377 do {378 const {next, tag} = effect;379 if (380 (tag & HookPassive) !== NoHookEffect &&381 (tag & HookHasEffect) !== NoHookEffect382 ) {383 enqueuePendingPassiveHookEffectUnmount(finishedWork, effect);384 enqueuePendingPassiveHookEffectMount(finishedWork, effect);385 }386 effect = next;387 } while (effect !== firstEffect);388 }389 }390}391export function commitPassiveHookEffects(finishedWork: Fiber): void {392 if ((finishedWork.effectTag & Passive) !== NoEffect) {393 switch (finishedWork.tag) {394 case FunctionComponent:395 case ForwardRef:396 case SimpleMemoComponent:397 case Block: {398 // TODO (#17945) We should call all passive destroy functions (for all fibers)399 // before calling any create functions. The current approach only serializes400 // these for a single fiber.401 if (402 enableProfilerTimer &&403 enableProfilerCommitHooks &&404 finishedWork.mode & ProfileMode405 ) {406 try {407 startPassiveEffectTimer();408 commitHookEffectListUnmount(409 HookPassive | HookHasEffect,410 finishedWork,411 );412 commitHookEffectListMount(413 HookPassive | HookHasEffect,414 finishedWork,415 );416 } finally {417 recordPassiveEffectDuration(finishedWork);418 }419 } else {420 commitHookEffectListUnmount(421 HookPassive | HookHasEffect,422 finishedWork,423 );424 commitHookEffectListMount(HookPassive | HookHasEffect, finishedWork);425 }426 break;427 }428 default:429 break;430 }431 }432}433export function commitPassiveEffectDurations(434 finishedRoot: FiberRoot,435 finishedWork: Fiber,436): void {437 if (enableProfilerTimer && enableProfilerCommitHooks) {438 // Only Profilers with work in their subtree will have an Update effect scheduled.439 if ((finishedWork.effectTag & Update) !== NoEffect) {440 switch (finishedWork.tag) {441 case Profiler: {442 const {passiveEffectDuration} = finishedWork.stateNode;443 const {id, onPostCommit} = finishedWork.memoizedProps;444 // This value will still reflect the previous commit phase.445 // It does not get reset until the start of the next commit phase.446 const commitTime = getCommitTime();447 if (typeof onPostCommit === 'function') {448 if (enableSchedulerTracing) {449 onPostCommit(450 id,451 finishedWork.alternate === null ? 'mount' : 'update',452 passiveEffectDuration,453 commitTime,454 finishedRoot.memoizedInteractions,455 );456 } else {457 onPostCommit(458 id,459 finishedWork.alternate === null ? 'mount' : 'update',460 passiveEffectDuration,461 commitTime,462 );463 }464 }465 // Bubble times to the next nearest ancestor Profiler.466 // After we process that Profiler, we'll bubble further up.467 let parentFiber = finishedWork.return;468 while (parentFiber !== null) {469 if (parentFiber.tag === Profiler) {470 const parentStateNode = parentFiber.stateNode;471 parentStateNode.passiveEffectDuration += passiveEffectDuration;472 break;473 }474 parentFiber = parentFiber.return;475 }476 break;477 }478 default:479 break;480 }481 }482 }483}484function commitLifeCycles(485 finishedRoot: FiberRoot,486 current: Fiber | null,487 finishedWork: Fiber,488 committedExpirationTime: ExpirationTime,489): void {490 switch (finishedWork.tag) {491 case FunctionComponent:492 case ForwardRef:493 case SimpleMemoComponent:494 case Block: {495 // At this point layout effects have already been destroyed (during mutation phase).496 // This is done to prevent sibling component effects from interfering with each other,497 // e.g. a destroy function in one component should never override a ref set498 // by a create function in another component during the same commit.499 if (500 enableProfilerTimer &&501 enableProfilerCommitHooks &&502 finishedWork.mode & ProfileMode503 ) {504 try {505 startLayoutEffectTimer();506 commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);507 } finally {508 recordLayoutEffectDuration(finishedWork);509 }510 } else {511 commitHookEffectListMount(HookLayout | HookHasEffect, finishedWork);512 }513 if (runAllPassiveEffectDestroysBeforeCreates) {514 schedulePassiveEffects(finishedWork);515 }516 return;517 }518 case ClassComponent: {519 const instance = finishedWork.stateNode;520 if (finishedWork.effectTag & Update) {521 if (current === null) {522 // We could update instance props and state here,523 // but instead we rely on them being set during last render.524 // TODO: revisit this when we implement resuming.525 if (__DEV__) {526 if (527 finishedWork.type === finishedWork.elementType &&528 !didWarnAboutReassigningProps529 ) {530 if (instance.props !== finishedWork.memoizedProps) {531 console.error(532 'Expected %s props to match memoized props before ' +533 'componentDidMount. ' +534 'This might either be because of a bug in React, or because ' +535 'a component reassigns its own `this.props`. ' +536 'Please file an issue.',537 getComponentName(finishedWork.type) || 'instance',538 );539 }540 if (instance.state !== finishedWork.memoizedState) {541 console.error(542 'Expected %s state to match memoized state before ' +543 'componentDidMount. ' +544 'This might either be because of a bug in React, or because ' +545 'a component reassigns its own `this.state`. ' +546 'Please file an issue.',547 getComponentName(finishedWork.type) || 'instance',548 );549 }550 }551 }552 if (553 enableProfilerTimer &&554 enableProfilerCommitHooks &&555 finishedWork.mode & ProfileMode556 ) {557 try {558 startLayoutEffectTimer();559 instance.componentDidMount();560 } finally {561 recordLayoutEffectDuration(finishedWork);562 }563 } else {564 instance.componentDidMount();565 }566 } else {567 const prevProps =568 finishedWork.elementType === finishedWork.type569 ? current.memoizedProps570 : resolveDefaultProps(finishedWork.type, current.memoizedProps);571 const prevState = current.memoizedState;572 // We could update instance props and state here,573 // but instead we rely on them being set during last render.574 // TODO: revisit this when we implement resuming.575 if (__DEV__) {576 if (577 finishedWork.type === finishedWork.elementType &&578 !didWarnAboutReassigningProps579 ) {580 if (instance.props !== finishedWork.memoizedProps) {581 console.error(582 'Expected %s props to match memoized props before ' +583 'componentDidUpdate. ' +584 'This might either be because of a bug in React, or because ' +585 'a component reassigns its own `this.props`. ' +586 'Please file an issue.',587 getComponentName(finishedWork.type) || 'instance',588 );589 }590 if (instance.state !== finishedWork.memoizedState) {591 console.error(592 'Expected %s state to match memoized state before ' +593 'componentDidUpdate. ' +594 'This might either be because of a bug in React, or because ' +595 'a component reassigns its own `this.state`. ' +596 'Please file an issue.',597 getComponentName(finishedWork.type) || 'instance',598 );599 }600 }601 }602 if (603 enableProfilerTimer &&604 enableProfilerCommitHooks &&605 finishedWork.mode & ProfileMode606 ) {607 try {608 startLayoutEffectTimer();609 instance.componentDidUpdate(610 prevProps,611 prevState,612 instance.__reactInternalSnapshotBeforeUpdate,613 );614 } finally {615 recordLayoutEffectDuration(finishedWork);616 }617 } else {618 instance.componentDidUpdate(619 prevProps,620 prevState,621 instance.__reactInternalSnapshotBeforeUpdate,622 );623 }624 }625 }626 // TODO: I think this is now always non-null by the time it reaches the627 // commit phase. Consider removing the type check.628 const updateQueue: UpdateQueue<629 *,630 > | null = (finishedWork.updateQueue: any);631 if (updateQueue !== null) {632 if (__DEV__) {633 if (634 finishedWork.type === finishedWork.elementType &&635 !didWarnAboutReassigningProps636 ) {637 if (instance.props !== finishedWork.memoizedProps) {638 console.error(639 'Expected %s props to match memoized props before ' +640 'processing the update queue. ' +641 'This might either be because of a bug in React, or because ' +642 'a component reassigns its own `this.props`. ' +643 'Please file an issue.',644 getComponentName(finishedWork.type) || 'instance',645 );646 }647 if (instance.state !== finishedWork.memoizedState) {648 console.error(649 'Expected %s state to match memoized state before ' +650 'processing the update queue. ' +651 'This might either be because of a bug in React, or because ' +652 'a component reassigns its own `this.state`. ' +653 'Please file an issue.',654 getComponentName(finishedWork.type) || 'instance',655 );656 }657 }658 }659 // We could update instance props and state here,660 // but instead we rely on them being set during last render.661 // TODO: revisit this when we implement resuming.662 commitUpdateQueue(finishedWork, updateQueue, instance);663 }664 return;665 }666 case HostRoot: {667 // TODO: I think this is now always non-null by the time it reaches the668 // commit phase. Consider removing the type check.669 const updateQueue: UpdateQueue<670 *,671 > | null = (finishedWork.updateQueue: any);672 if (updateQueue !== null) {673 let instance = null;674 if (finishedWork.child !== null) {675 switch (finishedWork.child.tag) {676 case HostComponent:677 instance = getPublicInstance(finishedWork.child.stateNode);678 break;679 case ClassComponent:680 instance = finishedWork.child.stateNode;681 break;682 }683 }684 commitUpdateQueue(finishedWork, updateQueue, instance);685 }686 return;687 }688 case HostComponent: {689 const instance: Instance = finishedWork.stateNode;690 // Renderers may schedule work to be done after host components are mounted691 // (eg DOM renderer may schedule auto-focus for inputs and form controls).692 // These effects should only be committed when components are first mounted,693 // aka when there is no current/alternate.694 if (current === null && finishedWork.effectTag & Update) {695 const type = finishedWork.type;696 const props = finishedWork.memoizedProps;697 commitMount(instance, type, props, finishedWork);698 }699 return;700 }701 case HostText: {702 // We have no life-cycles associated with text.703 return;704 }705 case HostPortal: {706 // We have no life-cycles associated with portals.707 return;708 }709 case Profiler: {710 if (enableProfilerTimer) {711 const {onCommit, onRender} = finishedWork.memoizedProps;712 const {effectDuration} = finishedWork.stateNode;713 const commitTime = getCommitTime();714 if (typeof onRender === 'function') {715 if (enableSchedulerTracing) {716 onRender(717 finishedWork.memoizedProps.id,718 current === null ? 'mount' : 'update',719 finishedWork.actualDuration,720 finishedWork.treeBaseDuration,721 finishedWork.actualStartTime,722 commitTime,723 finishedRoot.memoizedInteractions,724 );725 } else {726 onRender(727 finishedWork.memoizedProps.id,728 current === null ? 'mount' : 'update',729 finishedWork.actualDuration,730 finishedWork.treeBaseDuration,731 finishedWork.actualStartTime,732 commitTime,733 );734 }735 }736 if (enableProfilerCommitHooks) {737 if (typeof onCommit === 'function') {738 if (enableSchedulerTracing) {739 onCommit(740 finishedWork.memoizedProps.id,741 current === null ? 'mount' : 'update',742 effectDuration,743 commitTime,744 finishedRoot.memoizedInteractions,745 );746 } else {747 onCommit(748 finishedWork.memoizedProps.id,749 current === null ? 'mount' : 'update',750 effectDuration,751 commitTime,752 );753 }754 }755 // Schedule a passive effect for this Profiler to call onPostCommit hooks.756 // This effect should be scheduled even if there is no onPostCommit callback for this Profiler,757 // because the effect is also where times bubble to parent Profilers.758 enqueuePendingPassiveProfilerEffect(finishedWork);759 // Propagate layout effect durations to the next nearest Profiler ancestor.760 // Do not reset these values until the next render so DevTools has a chance to read them first.761 let parentFiber = finishedWork.return;762 while (parentFiber !== null) {763 if (parentFiber.tag === Profiler) {764 const parentStateNode = parentFiber.stateNode;765 parentStateNode.effectDuration += effectDuration;766 break;767 }768 parentFiber = parentFiber.return;769 }770 }771 }772 return;773 }774 case SuspenseComponent: {775 commitSuspenseHydrationCallbacks(finishedRoot, finishedWork);776 return;777 }778 case SuspenseListComponent:779 case IncompleteClassComponent:780 case FundamentalComponent:781 case ScopeComponent:782 return;783 }784 invariant(785 false,786 'This unit of work tag should not have side-effects. This error is ' +787 'likely caused by a bug in React. Please file an issue.',788 );789}790function hideOrUnhideAllChildren(finishedWork, isHidden) {791 if (supportsMutation) {792 // We only have the top Fiber that was inserted but we need to recurse down its793 // children to find all the terminal nodes.794 let node: Fiber = finishedWork;795 while (true) {796 if (node.tag === HostComponent) {797 const instance = node.stateNode;798 if (isHidden) {799 hideInstance(instance);800 } else {801 unhideInstance(node.stateNode, node.memoizedProps);802 }803 } else if (node.tag === HostText) {804 const instance = node.stateNode;805 if (isHidden) {806 hideTextInstance(instance);807 } else {808 unhideTextInstance(instance, node.memoizedProps);809 }810 } else if (811 node.tag === SuspenseComponent &&812 node.memoizedState !== null &&813 node.memoizedState.dehydrated === null814 ) {815 // Found a nested Suspense component that timed out. Skip over the816 // primary child fragment, which should remain hidden.817 const fallbackChildFragment: Fiber = (node.child: any).sibling;818 fallbackChildFragment.return = node;819 node = fallbackChildFragment;820 continue;821 } else if (node.child !== null) {822 node.child.return = node;823 node = node.child;824 continue;825 }826 if (node === finishedWork) {827 return;828 }829 while (node.sibling === null) {830 if (node.return === null || node.return === finishedWork) {831 return;832 }833 node = node.return;834 }835 node.sibling.return = node.return;836 node = node.sibling;837 }838 }839}840function commitAttachRef(finishedWork: Fiber) {841 const ref = finishedWork.ref;842 if (ref !== null) {843 const instance = finishedWork.stateNode;844 let instanceToUse;845 switch (finishedWork.tag) {846 case HostComponent:847 instanceToUse = getPublicInstance(instance);848 break;849 default:850 instanceToUse = instance;851 }852 // Moved outside to ensure DCE works with this flag853 if (enableScopeAPI && finishedWork.tag === ScopeComponent) {854 instanceToUse = instance.methods;855 }856 if (typeof ref === 'function') {857 ref(instanceToUse);858 } else {859 if (__DEV__) {860 if (!ref.hasOwnProperty('current')) {861 console.error(862 'Unexpected ref object provided for %s. ' +863 'Use either a ref-setter function or React.createRef().%s',864 getComponentName(finishedWork.type),865 getStackByFiberInDevAndProd(finishedWork),866 );867 }868 }869 ref.current = instanceToUse;870 }871 }872}873function commitDetachRef(current: Fiber) {874 const currentRef = current.ref;875 if (currentRef !== null) {876 if (typeof currentRef === 'function') {877 currentRef(null);878 } else {879 currentRef.current = null;880 }881 }882}883// User-originating errors (lifecycles and refs) should not interrupt884// deletion, so don't let them throw. Host-originating errors should885// interrupt deletion, so it's okay886function commitUnmount(887 finishedRoot: FiberRoot,888 current: Fiber,889 renderPriorityLevel: ReactPriorityLevel,890): void {891 onCommitUnmount(current);892 switch (current.tag) {893 case FunctionComponent:894 case ForwardRef:895 case MemoComponent:896 case SimpleMemoComponent:897 case Block: {898 const updateQueue: FunctionComponentUpdateQueue | null = (current.updateQueue: any);899 if (updateQueue !== null) {900 const lastEffect = updateQueue.lastEffect;901 if (lastEffect !== null) {902 const firstEffect = lastEffect.next;903 if (904 deferPassiveEffectCleanupDuringUnmount &&905 runAllPassiveEffectDestroysBeforeCreates906 ) {907 let effect = firstEffect;908 do {909 const {destroy, tag} = effect;910 if (destroy !== undefined) {911 if ((tag & HookPassive) !== NoHookEffect) {912 enqueuePendingPassiveHookEffectUnmount(current, effect);913 } else {914 if (915 enableProfilerTimer &&916 enableProfilerCommitHooks &&917 current.mode & ProfileMode918 ) {919 startLayoutEffectTimer();920 safelyCallDestroy(current, destroy);921 recordLayoutEffectDuration(current);922 } else {923 safelyCallDestroy(current, destroy);924 }925 }926 }927 effect = effect.next;928 } while (effect !== firstEffect);929 } else {930 // When the owner fiber is deleted, the destroy function of a passive931 // effect hook is called during the synchronous commit phase. This is932 // a concession to implementation complexity. Calling it in the933 // passive effect phase (like they usually are, when dependencies934 // change during an update) would require either traversing the935 // children of the deleted fiber again, or including unmount effects936 // as part of the fiber effect list.937 //938 // Because this is during the sync commit phase, we need to change939 // the priority.940 //941 // TODO: Reconsider this implementation trade off.942 const priorityLevel =943 renderPriorityLevel > NormalPriority944 ? NormalPriority945 : renderPriorityLevel;946 runWithPriority(priorityLevel, () => {947 let effect = firstEffect;948 do {949 const {destroy, tag} = effect;950 if (destroy !== undefined) {951 if (952 enableProfilerTimer &&953 enableProfilerCommitHooks &&954 current.mode & ProfileMode955 ) {956 if ((tag & HookPassive) !== NoHookEffect) {957 safelyCallDestroy(current, destroy);958 } else {959 startLayoutEffectTimer();960 safelyCallDestroy(current, destroy);961 recordLayoutEffectDuration(current);962 }963 } else {964 safelyCallDestroy(current, destroy);965 }966 }967 effect = effect.next;968 } while (effect !== firstEffect);969 });970 }971 }972 }973 return;974 }975 case ClassComponent: {976 safelyDetachRef(current);977 const instance = current.stateNode;978 if (typeof instance.componentWillUnmount === 'function') {...
ReactFiberCommitWork.js
Source:ReactFiberCommitWork.js
...92 // Unmount93 const destroy = effect.destroy;94 effect.destroy = undefined;95 if (destroy !== undefined) {96 safelyCallDestroy(finishedWork, nearestMountedAncestor)97 }98 }99 effect = effect.next;100 } while (effect !== firstEffect)101 }...
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.close();7 await context.close();8 await browser.close();9 await browser._initializer.safelyCallDestroy();10})();
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 browser.safelyCallDestroy();7})();
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.screenshot({ path: 'google.png' });7 await page.close();8 await context.close();9 await browser.close();10})();11const { chromium } = require('playwright');12const { Internal } = require('playwright/lib/internal');13const browser = await chromium.launch();14const context = await browser.newContext();15const page = await context.newPage();16await page.screenshot({ path: 'google.png' });17Internal.safelyCallDestroy(browser);18Internal.safelyCallDestroy(context);19Internal.safelyCallDestroy(page);20Internal.safelyCallDestroy(browser);21Internal.safelyCallDestroy(context);22Internal.safelyCallDestroy(page);
Using AI Code Generation
1const { Internal } = require('playwright/lib/server/frames');2const { BrowserContext } = require('playwright/lib/server/browserContext');3const { Browser } = require('playwright/lib/server/browser');4const { Page } = require('playwright/lib/server/page');5const { Frame } = require('playwright/lib/server/frames');6const context = new BrowserContext(new Browser('chromium', null, null), {});7const page = new Page(context, null, null, null, null, null, null, null, null, null);8const frame = new Frame(page, null, null, null, null, null, null, null, null, null, null);9const internal = new Internal(frame);10const destroyPromise = internal.safelyCallDestroy();11destroyPromise.then(() => {12 console.log('Destroyed');13});14[Apache-2.0](LICENSE)
Using AI Code Generation
1const { Internal } = require('playwright/lib/server/browserType');2const internal = new Internal();3await internal.safelyCallDestroy();4const { Internal } = require('playwright/lib/server/browserType');5const internal = new Internal();6await internal.safelyCallDestroy();
Using AI Code Generation
1import { safeCallDestroy } from "playwright/lib/server/browserType"2import { chromium } from "playwright"3const browser = await chromium.launch()4const page = await browser.newPage()5await safeCallDestroy(browser)6await safeCallDestroy(page)
Using AI Code Generation
1const { Playwright } = require('playwright');2const { Internal } = require('playwright/lib/server/supplements/playwright.js');3const playwright = new Playwright();4const internal = new Internal(playwright);5const browser = await playwright.chromium.launch();6const page = await browser.newPage();7await internal.safelyCallDestroy();8await browser.close();9const { Playwright } = require('playwright');10const { Internal } = require('playwright/lib/server/supplements/playwright.js');11const playwright = new Playwright();12const internal = new Internal(playwright);13const browser = await playwright.chromium.launch();14const page = await browser.newPage();15await internal.safelyCallDestroy();16await browser.close();17const { Playwright } = require('playwright');18const { Internal } = require('playwright/lib/server/supplements/playwright.js');19const playwright = new Playwright();20const internal = new Internal(playwright);21const browser = await playwright.chromium.launch();22const page = await browser.newPage();23await internal.safelyCallDestroy();24await browser.close();25const { Playwright } = require('playwright');26const { Internal } = require('playwright/lib/server/supplements/playwright.js');27const playwright = new Playwright();28const internal = new Internal(playwright);29const browser = await playwright.chromium.launch();30const page = await browser.newPage();31await internal.safelyCallDestroy();32await browser.close();33const { Playwright } = require('playwright');34const { Internal } = require('playwright/lib/server/supplements/playwright.js');35const playwright = new Playwright();
Using AI Code Generation
1const {safeCallDestroy} = require('playwright/lib/server/browserContext');2const {createPlaywright} = require('playwright/lib/server/playwright');3const playwright = createPlaywright();4const browser = await playwright.chromium.launch();5const context = await browser.newContext();6await safeCallDestroy(context);7await safeCallDestroy(browser);8const {createPlaywright} = require('playwright/lib/server/playwright');9const playwright = createPlaywright();10const browser = await playwright.chromium.launch();11const context = await browser.newContext();12await context._browserContext._doSlowMo();13await context.close();14await browser.close();15const {safeCallDestroy} = require('playwright/lib/server/browserContext');16const {createPlaywright} = require('playwright/lib/server/playwright');17const playwright = createPlaywright();18const browser = await playwright.chromium.launch();19const context = await browser.newContext();20await safeCallDestroy(context);21await safeCallDestroy(browser);22const {createPlaywright} = require('playwright/lib/server/playwright');23const playwright = createPlaywright();24const browser = await playwright.chromium.launch();25const context = await browser.newContext();26await context._browserContext._doSlowMo();27await context.close();28await browser.close();29const {safeCallDestroy} = require('playwright/lib/server/browserContext');30const {createPlaywright} = require('playwright/lib/server/playwright');31const playwright = createPlaywright();32const browser = await playwright.chromium.launch();33const context = await browser.newContext();34await safeCallDestroy(context);35await safeCallDestroy(browser);36const {createPlaywright} = require('playwright/lib/server/playwright');37const playwright = createPlaywright();38const browser = await playwright.chromium.launch();39const context = await browser.newContext();40await context._browserContext._doSlowMo();41await context.close();42await browser.close();43const {safeCallDestroy} = require('playwright/lib/server/browserContext');44const {createPlaywright} = require('playwright/lib/server/playwright');45const playwright = createPlaywright();46const browser = await playwright.chromium.launch();47const context = await browser.newContext();48await safeCallDestroy(context);49await safeCallDestroy(browser);50const {
Using AI Code Generation
1const {Internal} = require('playwright/lib/client/transport');2const {Playwright} = require('playwright');3const playwright = new Playwright({4 firefox: require('playwright-firefox'),5 chromium: require('playwright-chromium'),6 webkit: require('playwright-webkit')7});8const browser = await playwright.chromium.launch();9Internal.safelyCallDestroy(browser);10Internal.safelyCallDestroy(playwright);11Internal.safelyCallDestroy(browser.contexts()[0]);12Internal.safelyCallDestroy(browser.contexts()[0].pages()[0]);13Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0]);14Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame());15Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0]);16Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0].childFrames()[0]);17Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0].childFrames()[0].childFrames()[0]);18Internal.safelyCallDestroy(browser.contexts()[0]);19Internal.safelyCallDestroy(browser.contexts()[0].pages()[0]);20Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0]);21Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame());22Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0]);23Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0].childFrames()[0]);24Internal.safelyCallDestroy(browser.contexts()[0].pages()[0].frames()[0].mainFrame().childFrames()[0].childFrames()[0].childFrames()[0]);
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!!