Best JavaScript code snippet using playwright-internal
ReactFiberWorkLoop.old.js
Source:ReactFiberWorkLoop.old.js
...728 // If something threw an error, try rendering one more time. We'll729 // render synchronously to block concurrent data mutations, and we'll730 // includes all pending updates are included. If it still fails after731 // the second attempt, we'll give up and commit the resulting tree.732 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);733 if (errorRetryLanes !== NoLanes) {734 lanes = errorRetryLanes;735 exitStatus = recoverFromConcurrentError(root, errorRetryLanes);736 }737 }738 if (exitStatus === RootFatalErrored) {739 const fatalError = workInProgressRootFatalError;740 prepareFreshStack(root, NoLanes);741 markRootSuspended(root, lanes);742 ensureRootIsScheduled(root, now());743 throw fatalError;744 }745 // Check if this render may have yielded to a concurrent event, and if so,746 // confirm that any newly rendered stores are consistent.747 // TODO: It's possible that even a concurrent render may never have yielded748 // to the main thread, if it was fast enough, or if it expired. We could749 // skip the consistency check in that case, too.750 const renderWasConcurrent = !includesBlockingLane(root, lanes);751 const finishedWork: Fiber = (root.current.alternate: any);752 if (753 renderWasConcurrent &&754 !isRenderConsistentWithExternalStores(finishedWork)755 ) {756 // A store was mutated in an interleaved event. Render again,757 // synchronously, to block further mutations.758 exitStatus = renderRootSync(root, lanes);759 // We need to check again if something threw760 if (exitStatus === RootErrored) {761 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);762 if (errorRetryLanes !== NoLanes) {763 lanes = errorRetryLanes;764 exitStatus = recoverFromConcurrentError(root, errorRetryLanes);765 // We assume the tree is now consistent because we didn't yield to any766 // concurrent events.767 }768 }769 if (exitStatus === RootFatalErrored) {770 const fatalError = workInProgressRootFatalError;771 prepareFreshStack(root, NoLanes);772 markRootSuspended(root, lanes);773 ensureRootIsScheduled(root, now());774 throw fatalError;775 }776 }777 // We now have a consistent tree. The next step is either to commit it,778 // or, if something suspended, wait to commit it after a timeout.779 root.finishedWork = finishedWork;780 root.finishedLanes = lanes;781 finishConcurrentRender(root, exitStatus, lanes);782 }783 ensureRootIsScheduled(root, now());784 if (root.callbackNode === originalCallbackNode) {785 // The task node scheduled for this root is the same one that's786 // currently executed. Need to return a continuation.787 return performConcurrentWorkOnRoot.bind(null, root);788 }789 return null;790}791function recoverFromConcurrentError(root, errorRetryLanes) {792 const prevExecutionContext = executionContext;793 executionContext |= RetryAfterError;794 // If an error occurred during hydration, discard server response and fall795 // back to client side render.796 if (root.isDehydrated) {797 root.isDehydrated = false;798 if (__DEV__) {799 errorHydratingContainer(root.containerInfo);800 }801 clearContainer(root.containerInfo);802 }803 const exitStatus = renderRootSync(root, errorRetryLanes);804 executionContext = prevExecutionContext;805 return exitStatus;806}807function finishConcurrentRender(root, exitStatus, lanes) {808 switch (exitStatus) {809 case RootIncomplete:810 case RootFatalErrored: {811 invariant(false, 'Root did not complete. This is a bug in React.');812 }813 // Flow knows about invariant, so it complains if I add a break814 // statement, but eslint doesn't know about invariant, so it complains815 // if I do. eslint-disable-next-line no-fallthrough816 case RootErrored: {817 // We should have already attempted to retry this tree. If we reached818 // this point, it errored again. Commit it.819 commitRoot(root);820 break;821 }822 case RootSuspended: {823 markRootSuspended(root, lanes);824 // We have an acceptable loading state. We need to figure out if we825 // should immediately commit it or wait a bit.826 if (827 includesOnlyRetries(lanes) &&828 // do not delay if we're inside an act() scope829 !shouldForceFlushFallbacksInDEV()830 ) {831 // This render only included retries, no updates. Throttle committing832 // retries so that we don't show too many loading states too quickly.833 const msUntilTimeout =834 globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now();835 // Don't bother with a very short suspense time.836 if (msUntilTimeout > 10) {837 const nextLanes = getNextLanes(root, NoLanes);838 if (nextLanes !== NoLanes) {839 // There's additional work on this root.840 break;841 }842 const suspendedLanes = root.suspendedLanes;843 if (!isSubsetOfLanes(suspendedLanes, lanes)) {844 // We should prefer to render the fallback of at the last845 // suspended level. Ping the last suspended level to try846 // rendering it again.847 // FIXME: What if the suspended lanes are Idle? Should not restart.848 const eventTime = requestEventTime();849 markRootPinged(root, suspendedLanes, eventTime);850 break;851 }852 // The render is suspended, it hasn't timed out, and there's no853 // lower priority work to do. Instead of committing the fallback854 // immediately, wait for more data to arrive.855 root.timeoutHandle = scheduleTimeout(856 commitRoot.bind(null, root),857 msUntilTimeout,858 );859 break;860 }861 }862 // The work expired. Commit immediately.863 commitRoot(root);864 break;865 }866 case RootSuspendedWithDelay: {867 markRootSuspended(root, lanes);868 if (includesOnlyTransitions(lanes)) {869 // This is a transition, so we should exit without committing a870 // placeholder and without scheduling a timeout. Delay indefinitely871 // until we receive more data.872 break;873 }874 if (!shouldForceFlushFallbacksInDEV()) {875 // This is not a transition, but we did trigger an avoided state.876 // Schedule a placeholder to display after a short delay, using the Just877 // Noticeable Difference.878 // TODO: Is the JND optimization worth the added complexity? If this is879 // the only reason we track the event time, then probably not.880 // Consider removing.881 const mostRecentEventTime = getMostRecentEventTime(root, lanes);882 const eventTimeMs = mostRecentEventTime;883 const timeElapsedMs = now() - eventTimeMs;884 const msUntilTimeout = jnd(timeElapsedMs) - timeElapsedMs;885 // Don't bother with a very short suspense time.886 if (msUntilTimeout > 10) {887 // Instead of committing the fallback immediately, wait for more data888 // to arrive.889 root.timeoutHandle = scheduleTimeout(890 commitRoot.bind(null, root),891 msUntilTimeout,892 );893 break;894 }895 }896 // Commit the placeholder.897 commitRoot(root);898 break;899 }900 case RootCompleted: {901 // The work completed. Ready to commit.902 commitRoot(root);903 break;904 }905 default: {906 invariant(false, 'Unknown root exit status.');907 }908 }909}910function isRenderConsistentWithExternalStores(finishedWork: Fiber): boolean {911 // Search the rendered tree for external store reads, and check whether the912 // stores were mutated in a concurrent event. Intentionally using a iterative913 // loop instead of recursion so we can exit early.914 let node: Fiber = finishedWork;915 while (true) {916 if (node.flags & StoreConsistency) {917 const updateQueue: FunctionComponentUpdateQueue | null = (node.updateQueue: any);918 if (updateQueue !== null) {919 const checks = updateQueue.stores;920 if (checks !== null) {921 for (let i = 0; i < checks.length; i++) {922 const check = checks[i];923 const getSnapshot = check.getSnapshot;924 const renderedValue = check.value;925 try {926 if (!is(getSnapshot(), renderedValue)) {927 // Found an inconsistent store.928 return false;929 }930 } catch (error) {931 // If `getSnapshot` throws, return `false`. This will schedule932 // a re-render, and the error will be rethrown during render.933 return false;934 }935 }936 }937 }938 }939 const child = node.child;940 if (node.subtreeFlags & StoreConsistency && child !== null) {941 child.return = node;942 node = child;943 continue;944 }945 if (node === finishedWork) {946 return true;947 }948 while (node.sibling === null) {949 if (node.return === null || node.return === finishedWork) {950 return true;951 }952 node = node.return;953 }954 node.sibling.return = node.return;955 node = node.sibling;956 }957 // Flow doesn't know this is unreachable, but eslint does958 // eslint-disable-next-line no-unreachable959 return true;960}961function markRootSuspended(root, suspendedLanes) {962 // When suspending, we should always exclude lanes that were pinged or (more963 // rarely, since we try to avoid it) updated during the render phase.964 // TODO: Lol maybe there's a better way to factor this besides this965 // obnoxiously named function :)966 suspendedLanes = removeLanes(suspendedLanes, workInProgressRootPingedLanes);967 suspendedLanes = removeLanes(suspendedLanes, workInProgressRootUpdatedLanes);968 markRootSuspended_dontCallThisOneDirectly(root, suspendedLanes);969}970// This is the entry point for synchronous tasks that don't go971// through Scheduler972function performSyncWorkOnRoot(root) {973 if (enableProfilerTimer && enableProfilerNestedUpdatePhase) {974 syncNestedUpdateFlag();975 }976 invariant(977 (executionContext & (RenderContext | CommitContext)) === NoContext,978 'Should not already be working.',979 );980 flushPassiveEffects();981 let lanes = getNextLanes(root, NoLanes);982 if (!includesSomeLane(lanes, SyncLane)) {983 // There's no remaining sync work left.984 ensureRootIsScheduled(root, now());985 return null;986 }987 let exitStatus = renderRootSync(root, lanes);988 if (root.tag !== LegacyRoot && exitStatus === RootErrored) {989 const prevExecutionContext = executionContext;990 executionContext |= RetryAfterError;991 // If an error occurred during hydration,992 // discard server response and fall back to client side render.993 if (root.isDehydrated) {994 root.isDehydrated = false;995 if (__DEV__) {996 errorHydratingContainer(root.containerInfo);997 }998 clearContainer(root.containerInfo);999 }1000 // If something threw an error, try rendering one more time. We'll render1001 // synchronously to block concurrent data mutations, and we'll includes1002 // all pending updates are included. If it still fails after the second1003 // attempt, we'll give up and commit the resulting tree.1004 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);1005 if (errorRetryLanes !== NoLanes) {1006 lanes = errorRetryLanes;1007 exitStatus = renderRootSync(root, lanes);1008 }1009 executionContext = prevExecutionContext;1010 }1011 if (exitStatus === RootFatalErrored) {1012 const fatalError = workInProgressRootFatalError;1013 prepareFreshStack(root, NoLanes);1014 markRootSuspended(root, lanes);1015 ensureRootIsScheduled(root, now());1016 throw fatalError;1017 }1018 // We now have a consistent tree. Because this is a sync render, we...
ReactFiberWorkLoop.new.js
Source:ReactFiberWorkLoop.new.js
...728 // If something threw an error, try rendering one more time. We'll729 // render synchronously to block concurrent data mutations, and we'll730 // includes all pending updates are included. If it still fails after731 // the second attempt, we'll give up and commit the resulting tree.732 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);733 if (errorRetryLanes !== NoLanes) {734 lanes = errorRetryLanes;735 exitStatus = recoverFromConcurrentError(root, errorRetryLanes);736 }737 }738 if (exitStatus === RootFatalErrored) {739 const fatalError = workInProgressRootFatalError;740 prepareFreshStack(root, NoLanes);741 markRootSuspended(root, lanes);742 ensureRootIsScheduled(root, now());743 throw fatalError;744 }745 // Check if this render may have yielded to a concurrent event, and if so,746 // confirm that any newly rendered stores are consistent.747 // TODO: It's possible that even a concurrent render may never have yielded748 // to the main thread, if it was fast enough, or if it expired. We could749 // skip the consistency check in that case, too.750 const renderWasConcurrent = !includesBlockingLane(root, lanes);751 const finishedWork: Fiber = (root.current.alternate: any);752 if (753 renderWasConcurrent &&754 !isRenderConsistentWithExternalStores(finishedWork)755 ) {756 // A store was mutated in an interleaved event. Render again,757 // synchronously, to block further mutations.758 exitStatus = renderRootSync(root, lanes);759 // We need to check again if something threw760 if (exitStatus === RootErrored) {761 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);762 if (errorRetryLanes !== NoLanes) {763 lanes = errorRetryLanes;764 exitStatus = recoverFromConcurrentError(root, errorRetryLanes);765 // We assume the tree is now consistent because we didn't yield to any766 // concurrent events.767 }768 }769 if (exitStatus === RootFatalErrored) {770 const fatalError = workInProgressRootFatalError;771 prepareFreshStack(root, NoLanes);772 markRootSuspended(root, lanes);773 ensureRootIsScheduled(root, now());774 throw fatalError;775 }776 }777 // We now have a consistent tree. The next step is either to commit it,778 // or, if something suspended, wait to commit it after a timeout.779 root.finishedWork = finishedWork;780 root.finishedLanes = lanes;781 finishConcurrentRender(root, exitStatus, lanes);782 }783 ensureRootIsScheduled(root, now());784 if (root.callbackNode === originalCallbackNode) {785 // The task node scheduled for this root is the same one that's786 // currently executed. Need to return a continuation.787 return performConcurrentWorkOnRoot.bind(null, root);788 }789 return null;790}791function recoverFromConcurrentError(root, errorRetryLanes) {792 const prevExecutionContext = executionContext;793 executionContext |= RetryAfterError;794 // If an error occurred during hydration, discard server response and fall795 // back to client side render.796 if (root.isDehydrated) {797 root.isDehydrated = false;798 if (__DEV__) {799 errorHydratingContainer(root.containerInfo);800 }801 clearContainer(root.containerInfo);802 }803 const exitStatus = renderRootSync(root, errorRetryLanes);804 executionContext = prevExecutionContext;805 return exitStatus;806}807function finishConcurrentRender(root, exitStatus, lanes) {808 switch (exitStatus) {809 case RootIncomplete:810 case RootFatalErrored: {811 invariant(false, 'Root did not complete. This is a bug in React.');812 }813 // Flow knows about invariant, so it complains if I add a break814 // statement, but eslint doesn't know about invariant, so it complains815 // if I do. eslint-disable-next-line no-fallthrough816 case RootErrored: {817 // We should have already attempted to retry this tree. If we reached818 // this point, it errored again. Commit it.819 commitRoot(root);820 break;821 }822 case RootSuspended: {823 markRootSuspended(root, lanes);824 // We have an acceptable loading state. We need to figure out if we825 // should immediately commit it or wait a bit.826 if (827 includesOnlyRetries(lanes) &&828 // do not delay if we're inside an act() scope829 !shouldForceFlushFallbacksInDEV()830 ) {831 // This render only included retries, no updates. Throttle committing832 // retries so that we don't show too many loading states too quickly.833 const msUntilTimeout =834 globalMostRecentFallbackTime + FALLBACK_THROTTLE_MS - now();835 // Don't bother with a very short suspense time.836 if (msUntilTimeout > 10) {837 const nextLanes = getNextLanes(root, NoLanes);838 if (nextLanes !== NoLanes) {839 // There's additional work on this root.840 break;841 }842 const suspendedLanes = root.suspendedLanes;843 if (!isSubsetOfLanes(suspendedLanes, lanes)) {844 // We should prefer to render the fallback of at the last845 // suspended level. Ping the last suspended level to try846 // rendering it again.847 // FIXME: What if the suspended lanes are Idle? Should not restart.848 const eventTime = requestEventTime();849 markRootPinged(root, suspendedLanes, eventTime);850 break;851 }852 // The render is suspended, it hasn't timed out, and there's no853 // lower priority work to do. Instead of committing the fallback854 // immediately, wait for more data to arrive.855 root.timeoutHandle = scheduleTimeout(856 commitRoot.bind(null, root),857 msUntilTimeout,858 );859 break;860 }861 }862 // The work expired. Commit immediately.863 commitRoot(root);864 break;865 }866 case RootSuspendedWithDelay: {867 markRootSuspended(root, lanes);868 if (includesOnlyTransitions(lanes)) {869 // This is a transition, so we should exit without committing a870 // placeholder and without scheduling a timeout. Delay indefinitely871 // until we receive more data.872 break;873 }874 if (!shouldForceFlushFallbacksInDEV()) {875 // This is not a transition, but we did trigger an avoided state.876 // Schedule a placeholder to display after a short delay, using the Just877 // Noticeable Difference.878 // TODO: Is the JND optimization worth the added complexity? If this is879 // the only reason we track the event time, then probably not.880 // Consider removing.881 const mostRecentEventTime = getMostRecentEventTime(root, lanes);882 const eventTimeMs = mostRecentEventTime;883 const timeElapsedMs = now() - eventTimeMs;884 const msUntilTimeout = jnd(timeElapsedMs) - timeElapsedMs;885 // Don't bother with a very short suspense time.886 if (msUntilTimeout > 10) {887 // Instead of committing the fallback immediately, wait for more data888 // to arrive.889 root.timeoutHandle = scheduleTimeout(890 commitRoot.bind(null, root),891 msUntilTimeout,892 );893 break;894 }895 }896 // Commit the placeholder.897 commitRoot(root);898 break;899 }900 case RootCompleted: {901 // The work completed. Ready to commit.902 commitRoot(root);903 break;904 }905 default: {906 invariant(false, 'Unknown root exit status.');907 }908 }909}910function isRenderConsistentWithExternalStores(finishedWork: Fiber): boolean {911 // Search the rendered tree for external store reads, and check whether the912 // stores were mutated in a concurrent event. Intentionally using a iterative913 // loop instead of recursion so we can exit early.914 let node: Fiber = finishedWork;915 while (true) {916 if (node.flags & StoreConsistency) {917 const updateQueue: FunctionComponentUpdateQueue | null = (node.updateQueue: any);918 if (updateQueue !== null) {919 const checks = updateQueue.stores;920 if (checks !== null) {921 for (let i = 0; i < checks.length; i++) {922 const check = checks[i];923 const getSnapshot = check.getSnapshot;924 const renderedValue = check.value;925 try {926 if (!is(getSnapshot(), renderedValue)) {927 // Found an inconsistent store.928 return false;929 }930 } catch (error) {931 // If `getSnapshot` throws, return `false`. This will schedule932 // a re-render, and the error will be rethrown during render.933 return false;934 }935 }936 }937 }938 }939 const child = node.child;940 if (node.subtreeFlags & StoreConsistency && child !== null) {941 child.return = node;942 node = child;943 continue;944 }945 if (node === finishedWork) {946 return true;947 }948 while (node.sibling === null) {949 if (node.return === null || node.return === finishedWork) {950 return true;951 }952 node = node.return;953 }954 node.sibling.return = node.return;955 node = node.sibling;956 }957 // Flow doesn't know this is unreachable, but eslint does958 // eslint-disable-next-line no-unreachable959 return true;960}961function markRootSuspended(root, suspendedLanes) {962 // When suspending, we should always exclude lanes that were pinged or (more963 // rarely, since we try to avoid it) updated during the render phase.964 // TODO: Lol maybe there's a better way to factor this besides this965 // obnoxiously named function :)966 suspendedLanes = removeLanes(suspendedLanes, workInProgressRootPingedLanes);967 suspendedLanes = removeLanes(suspendedLanes, workInProgressRootUpdatedLanes);968 markRootSuspended_dontCallThisOneDirectly(root, suspendedLanes);969}970// This is the entry point for synchronous tasks that don't go971// through Scheduler972function performSyncWorkOnRoot(root) {973 if (enableProfilerTimer && enableProfilerNestedUpdatePhase) {974 syncNestedUpdateFlag();975 }976 invariant(977 (executionContext & (RenderContext | CommitContext)) === NoContext,978 'Should not already be working.',979 );980 flushPassiveEffects();981 let lanes = getNextLanes(root, NoLanes);982 if (!includesSomeLane(lanes, SyncLane)) {983 // There's no remaining sync work left.984 ensureRootIsScheduled(root, now());985 return null;986 }987 let exitStatus = renderRootSync(root, lanes);988 if (root.tag !== LegacyRoot && exitStatus === RootErrored) {989 const prevExecutionContext = executionContext;990 executionContext |= RetryAfterError;991 // If an error occurred during hydration,992 // discard server response and fall back to client side render.993 if (root.isDehydrated) {994 root.isDehydrated = false;995 if (__DEV__) {996 errorHydratingContainer(root.containerInfo);997 }998 clearContainer(root.containerInfo);999 }1000 // If something threw an error, try rendering one more time. We'll render1001 // synchronously to block concurrent data mutations, and we'll includes1002 // all pending updates are included. If it still fails after the second1003 // attempt, we'll give up and commit the resulting tree.1004 const errorRetryLanes = getLanesToRetrySynchronouslyOnError(root);1005 if (errorRetryLanes !== NoLanes) {1006 lanes = errorRetryLanes;1007 exitStatus = renderRootSync(root, lanes);1008 }1009 executionContext = prevExecutionContext;1010 }1011 if (exitStatus === RootFatalErrored) {1012 const fatalError = workInProgressRootFatalError;1013 prepareFreshStack(root, NoLanes);1014 markRootSuspended(root, lanes);1015 ensureRootIsScheduled(root, now());1016 throw fatalError;1017 }1018 // We now have a consistent tree. Because this is a sync render, we...
ReactFiberLane.old.js
Source:ReactFiberLane.old.js
...391// are suspended.392export function getHighestPriorityPendingLanes(root: FiberRoot) {393 return getHighestPriorityLanes(root.pendingLanes);394}395export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {396 const everythingButOffscreen = root.pendingLanes & ~OffscreenLane;397 if (everythingButOffscreen !== NoLanes) {398 return everythingButOffscreen;399 }400 if (everythingButOffscreen & OffscreenLane) {401 return OffscreenLane;402 }403 return NoLanes;404}405export function includesNonIdleWork(lanes: Lanes) {406 return (lanes & NonIdleLanes) !== NoLanes;407}408export function includesOnlyRetries(lanes: Lanes) {409 return (lanes & RetryLanes) === lanes;...
ReactFiberLane.new.js
Source:ReactFiberLane.new.js
...391// are suspended.392export function getHighestPriorityPendingLanes(root: FiberRoot) {393 return getHighestPriorityLanes(root.pendingLanes);394}395export function getLanesToRetrySynchronouslyOnError(root: FiberRoot): Lanes {396 const everythingButOffscreen = root.pendingLanes & ~OffscreenLane;397 if (everythingButOffscreen !== NoLanes) {398 return everythingButOffscreen;399 }400 if (everythingButOffscreen & OffscreenLane) {401 return OffscreenLane;402 }403 return NoLanes;404}405export function includesNonIdleWork(lanes: Lanes) {406 return (lanes & NonIdleLanes) !== NoLanes;407}408export function includesOnlyRetries(lanes: Lanes) {409 return (lanes & RetryLanes) === lanes;...
ReactFiberLane.js
Source:ReactFiberLane.js
...371 // are suspended.372 function getHighestPriorityPendingLanes(root) {373 return getHighestPriorityLanes(root.pendingLanes);374 }375 function getLanesToRetrySynchronouslyOnError(root) {376 var everythingButOffscreen = root.pendingLanes & ~OffscreenLane;377 if (everythingButOffscreen !== NoLanes) {378 return everythingButOffscreen;379 }380 if (everythingButOffscreen & OffscreenLane) {381 return OffscreenLane;382 }383 return NoLanes;384 }385 function returnNextLanesPriority() {386 return return_highestLanePriority;387 }388 function includesNonIdleWork(lanes) {389 return (lanes & NonIdleLanes) !== NoLanes;...
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!!