How to use checkDepsAreArrayDev method in Playwright Internal

Best JavaScript code snippet using playwright-internal

ReactFiberHooks.js

Source:ReactFiberHooks.js Github

copy

Full Screen

...180 }181 }182 }183}184function checkDepsAreArrayDev(deps: mixed) {185 if (__DEV__) {186 if (deps !== undefined && deps !== null && !Array.isArray(deps)) {187 // Verify deps, but only on mount to avoid extra checks.188 // It's unlikely their type would change as usually you define them inline.189 warning(190 false,191 '%s received a final argument that is not an array (instead, received `%s`). When ' +192 'specified, the final argument must be an array.',193 currentHookNameInDev,194 typeof deps,195 );196 }197 }198}199function warnOnHookMismatchInDev(currentHookName: HookType) {200 if (__DEV__) {201 const componentName = getComponentName(202 ((currentlyRenderingFiber: any): Fiber).type,203 );204 if (!didWarnAboutMismatchedHooksForComponent.has(componentName)) {205 didWarnAboutMismatchedHooksForComponent.add(componentName);206 if (hookTypesDev !== null) {207 let table = '';208 const secondColumnStart = 30;209 for (let i = 0; i <= ((hookTypesUpdateIndexDev: any): number); i++) {210 const oldHookName = hookTypesDev[i];211 const newHookName =212 i === ((hookTypesUpdateIndexDev: any): number)213 ? currentHookName214 : oldHookName;215 let row = `${i + 1}. ${oldHookName}`;216 // Extra space so second column lines up217 // lol @ IE not supporting String#repeat218 while (row.length < secondColumnStart) {219 row += ' ';220 }221 row += newHookName + '\n';222 table += row;223 }224 warning(225 false,226 'React has detected a change in the order of Hooks called by %s. ' +227 'This will lead to bugs and errors if not fixed. ' +228 'For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks\n\n' +229 ' Previous render Next render\n' +230 ' ------------------------------------------------------\n' +231 '%s' +232 ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n',233 componentName,234 table,235 );236 }237 }238 }239}240function throwInvalidHookError() {241 invariant(242 false,243 'Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' +244 ' one of the following reasons:\n' +245 '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' +246 '2. You might be breaking the Rules of Hooks\n' +247 '3. You might have more than one copy of React in the same app\n' +248 'See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.',249 );250}251function areHookInputsEqual(252 nextDeps: Array<mixed>,253 prevDeps: Array<mixed> | null,254) {255 if (prevDeps === null) {256 if (__DEV__) {257 warning(258 false,259 '%s received a final argument during this render, but not during ' +260 'the previous render. Even though the final argument is optional, ' +261 'its type cannot change between renders.',262 currentHookNameInDev,263 );264 }265 return false;266 }267 if (__DEV__) {268 // Don't bother comparing lengths in prod because these arrays should be269 // passed inline.270 if (nextDeps.length !== prevDeps.length) {271 warning(272 false,273 'The final argument passed to %s changed size between renders. The ' +274 'order and size of this array must remain constant.\n\n' +275 'Previous: %s\n' +276 'Incoming: %s',277 currentHookNameInDev,278 `[${prevDeps.join(', ')}]`,279 `[${nextDeps.join(', ')}]`,280 );281 }282 }283 for (let i = 0; i < prevDeps.length && i < nextDeps.length; i++) {284 if (is(nextDeps[i], prevDeps[i])) {285 continue;286 }287 return false;288 }289 return true;290}291export function renderWithHooks(292 current: Fiber | null,293 workInProgress: Fiber,294 Component: any,295 props: any,296 refOrContext: any,297 nextRenderExpirationTime: ExpirationTime,298): any {299 renderExpirationTime = nextRenderExpirationTime;300 currentlyRenderingFiber = workInProgress;301 nextCurrentHook = current !== null ? current.memoizedState : null;302 if (__DEV__) {303 hookTypesDev =304 current !== null305 ? ((current._debugHookTypes: any): Array<HookType>)306 : null;307 hookTypesUpdateIndexDev = -1;308 }309 // The following should have already been reset310 // currentHook = null;311 // workInProgressHook = null;312 // remainingExpirationTime = NoWork;313 // componentUpdateQueue = null;314 // didScheduleRenderPhaseUpdate = false;315 // renderPhaseUpdates = null;316 // numberOfReRenders = 0;317 // sideEffectTag = 0;318 // TODO Warn if no hooks are used at all during mount, then some are used during update.319 // Currently we will identify the update render as a mount because nextCurrentHook === null.320 // This is tricky because it's valid for certain types of components (e.g. React.lazy)321 // Using nextCurrentHook to differentiate between mount/update only works if at least one stateful hook is used.322 // Non-stateful hooks (e.g. context) don't get added to memoizedState,323 // so nextCurrentHook would be null during updates and mounts.324 if (__DEV__) {325 if (nextCurrentHook !== null) {326 ReactCurrentDispatcher.current = HooksDispatcherOnUpdateInDEV;327 } else if (hookTypesDev !== null) {328 // This dispatcher handles an edge case where a component is updating,329 // but no stateful hooks have been used.330 // We want to match the production code behavior (which will use HooksDispatcherOnMount),331 // but with the extra DEV validation to ensure hooks ordering hasn't changed.332 // This dispatcher does that.333 ReactCurrentDispatcher.current = HooksDispatcherOnMountWithHookTypesInDEV;334 } else {335 ReactCurrentDispatcher.current = HooksDispatcherOnMountInDEV;336 }337 } else {338 ReactCurrentDispatcher.current =339 nextCurrentHook === null340 ? HooksDispatcherOnMount341 : HooksDispatcherOnUpdate;342 }343 let children = Component(props, refOrContext);344 if (didScheduleRenderPhaseUpdate) {345 do {346 didScheduleRenderPhaseUpdate = false;347 numberOfReRenders += 1;348 // Start over from the beginning of the list349 nextCurrentHook = current !== null ? current.memoizedState : null;350 nextWorkInProgressHook = firstWorkInProgressHook;351 currentHook = null;352 workInProgressHook = null;353 componentUpdateQueue = null;354 if (__DEV__) {355 // Also validate hook order for cascading updates.356 hookTypesUpdateIndexDev = -1;357 }358 ReactCurrentDispatcher.current = __DEV__359 ? HooksDispatcherOnUpdateInDEV360 : HooksDispatcherOnUpdate;361 children = Component(props, refOrContext);362 } while (didScheduleRenderPhaseUpdate);363 renderPhaseUpdates = null;364 numberOfReRenders = 0;365 }366 // We can assume the previous dispatcher is always this one, since we set it367 // at the beginning of the render phase and there's no re-entrancy.368 ReactCurrentDispatcher.current = ContextOnlyDispatcher;369 const renderedWork: Fiber = (currentlyRenderingFiber: any);370 renderedWork.memoizedState = firstWorkInProgressHook;371 renderedWork.expirationTime = remainingExpirationTime;372 renderedWork.updateQueue = (componentUpdateQueue: any);373 renderedWork.effectTag |= sideEffectTag;374 if (__DEV__) {375 renderedWork._debugHookTypes = hookTypesDev;376 }377 // This check uses currentHook so that it works the same in DEV and prod bundles.378 // hookTypesDev could catch more cases (e.g. context) but only in DEV bundles.379 const didRenderTooFewHooks =380 currentHook !== null && currentHook.next !== null;381 renderExpirationTime = NoWork;382 currentlyRenderingFiber = null;383 currentHook = null;384 nextCurrentHook = null;385 firstWorkInProgressHook = null;386 workInProgressHook = null;387 nextWorkInProgressHook = null;388 if (__DEV__) {389 currentHookNameInDev = null;390 hookTypesDev = null;391 hookTypesUpdateIndexDev = -1;392 }393 remainingExpirationTime = NoWork;394 componentUpdateQueue = null;395 sideEffectTag = 0;396 // These were reset above397 // didScheduleRenderPhaseUpdate = false;398 // renderPhaseUpdates = null;399 // numberOfReRenders = 0;400 invariant(401 !didRenderTooFewHooks,402 'Rendered fewer hooks than expected. This may be caused by an accidental ' +403 'early return statement.',404 );405 return children;406}407export function bailoutHooks(408 current: Fiber,409 workInProgress: Fiber,410 expirationTime: ExpirationTime,411) {412 workInProgress.updateQueue = current.updateQueue;413 workInProgress.effectTag &= ~(PassiveEffect | UpdateEffect);414 if (current.expirationTime <= expirationTime) {415 current.expirationTime = NoWork;416 }417}418export function resetHooks(): void {419 // We can assume the previous dispatcher is always this one, since we set it420 // at the beginning of the render phase and there's no re-entrancy.421 ReactCurrentDispatcher.current = ContextOnlyDispatcher;422 // This is used to reset the state of this module when a component throws.423 // It's also called inside mountIndeterminateComponent if we determine the424 // component is a module-style component.425 renderExpirationTime = NoWork;426 currentlyRenderingFiber = null;427 currentHook = null;428 nextCurrentHook = null;429 firstWorkInProgressHook = null;430 workInProgressHook = null;431 nextWorkInProgressHook = null;432 if (__DEV__) {433 hookTypesDev = null;434 hookTypesUpdateIndexDev = -1;435 currentHookNameInDev = null;436 }437 remainingExpirationTime = NoWork;438 componentUpdateQueue = null;439 sideEffectTag = 0;440 didScheduleRenderPhaseUpdate = false;441 renderPhaseUpdates = null;442 numberOfReRenders = 0;443}444function mountWorkInProgressHook(): Hook {445 const hook: Hook = {446 memoizedState: null,447 baseState: null,448 queue: null,449 baseUpdate: null,450 next: null,451 };452 if (workInProgressHook === null) {453 // This is the first hook in the list454 firstWorkInProgressHook = workInProgressHook = hook;455 } else {456 // Append to the end of the list457 workInProgressHook = workInProgressHook.next = hook;458 }459 return workInProgressHook;460}461function updateWorkInProgressHook(): Hook {462 // This function is used both for updates and for re-renders triggered by a463 // render phase update. It assumes there is either a current hook we can464 // clone, or a work-in-progress hook from a previous render pass that we can465 // use as a base. When we reach the end of the base list, we must switch to466 // the dispatcher used for mounts.467 if (nextWorkInProgressHook !== null) {468 // There's already a work-in-progress. Reuse it.469 workInProgressHook = nextWorkInProgressHook;470 nextWorkInProgressHook = workInProgressHook.next;471 currentHook = nextCurrentHook;472 nextCurrentHook = currentHook !== null ? currentHook.next : null;473 } else {474 // Clone from the current hook.475 invariant(476 nextCurrentHook !== null,477 'Rendered more hooks than during the previous render.',478 );479 currentHook = nextCurrentHook;480 const newHook: Hook = {481 memoizedState: currentHook.memoizedState,482 baseState: currentHook.baseState,483 queue: currentHook.queue,484 baseUpdate: currentHook.baseUpdate,485 next: null,486 };487 if (workInProgressHook === null) {488 // This is the first hook in the list.489 workInProgressHook = firstWorkInProgressHook = newHook;490 } else {491 // Append to the end of the list.492 workInProgressHook = workInProgressHook.next = newHook;493 }494 nextCurrentHook = currentHook.next;495 }496 return workInProgressHook;497}498function createFunctionComponentUpdateQueue(): FunctionComponentUpdateQueue {499 return {500 lastEffect: null,501 };502}503function basicStateReducer<S>(state: S, action: BasicStateAction<S>): S {504 return typeof action === 'function' ? action(state) : action;505}506function mountReducer<S, I, A>(507 reducer: (S, A) => S,508 initialArg: I,509 init?: I => S,510): [S, Dispatch<A>] {511 const hook = mountWorkInProgressHook();512 let initialState;513 if (init !== undefined) {514 initialState = init(initialArg);515 } else {516 initialState = ((initialArg: any): S);517 }518 hook.memoizedState = hook.baseState = initialState;519 const queue = (hook.queue = {520 last: null,521 dispatch: null,522 lastRenderedReducer: reducer,523 lastRenderedState: (initialState: any),524 });525 const dispatch: Dispatch<A> = (queue.dispatch = (dispatchAction.bind(526 null,527 // Flow doesn't know this is non-null, but we do.528 ((currentlyRenderingFiber: any): Fiber),529 queue,530 ): any));531 return [hook.memoizedState, dispatch];532}533function updateReducer<S, I, A>(534 reducer: (S, A) => S,535 initialArg: I,536 init?: I => S,537): [S, Dispatch<A>] {538 const hook = updateWorkInProgressHook();539 const queue = hook.queue;540 invariant(541 queue !== null,542 'Should have a queue. This is likely a bug in React. Please file an issue.',543 );544 queue.lastRenderedReducer = reducer;545 if (numberOfReRenders > 0) {546 // This is a re-render. Apply the new render phase updates to the previous547 // work-in-progress hook.548 const dispatch: Dispatch<A> = (queue.dispatch: any);549 if (renderPhaseUpdates !== null) {550 // Render phase updates are stored in a map of queue -> linked list551 const firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);552 if (firstRenderPhaseUpdate !== undefined) {553 renderPhaseUpdates.delete(queue);554 let newState = hook.memoizedState;555 let update = firstRenderPhaseUpdate;556 do {557 // Process this render phase update. We don't have to check the558 // priority because it will always be the same as the current559 // render's.560 const action = update.action;561 newState = reducer(newState, action);562 update = update.next;563 } while (update !== null);564 // Mark that the fiber performed work, but only if the new state is565 // different from the current state.566 if (!is(newState, hook.memoizedState)) {567 markWorkInProgressReceivedUpdate();568 }569 hook.memoizedState = newState;570 // Don't persist the state accumlated from the render phase updates to571 // the base state unless the queue is empty.572 // TODO: Not sure if this is the desired semantics, but it's what we573 // do for gDSFP. I can't remember why.574 if (hook.baseUpdate === queue.last) {575 hook.baseState = newState;576 }577 queue.lastRenderedState = newState;578 return [newState, dispatch];579 }580 }581 return [hook.memoizedState, dispatch];582 }583 // The last update in the entire queue584 const last = queue.last;585 // The last update that is part of the base state.586 const baseUpdate = hook.baseUpdate;587 const baseState = hook.baseState;588 // Find the first unprocessed update.589 let first;590 if (baseUpdate !== null) {591 if (last !== null) {592 // For the first update, the queue is a circular linked list where593 // `queue.last.next = queue.first`. Once the first update commits, and594 // the `baseUpdate` is no longer empty, we can unravel the list.595 last.next = null;596 }597 first = baseUpdate.next;598 } else {599 first = last !== null ? last.next : null;600 }601 if (first !== null) {602 let newState = baseState;603 let newBaseState = null;604 let newBaseUpdate = null;605 let prevUpdate = baseUpdate;606 let update = first;607 let didSkip = false;608 do {609 const updateExpirationTime = update.expirationTime;610 if (updateExpirationTime < renderExpirationTime) {611 // Priority is insufficient. Skip this update. If this is the first612 // skipped update, the previous update/state is the new base613 // update/state.614 if (!didSkip) {615 didSkip = true;616 newBaseUpdate = prevUpdate;617 newBaseState = newState;618 }619 // Update the remaining priority in the queue.620 if (updateExpirationTime > remainingExpirationTime) {621 remainingExpirationTime = updateExpirationTime;622 }623 } else {624 // This update does have sufficient priority.625 // Mark the event time of this update as relevant to this render pass.626 // TODO: This should ideally use the true event time of this update rather than627 // its priority which is a derived and not reverseable value.628 // TODO: We should skip this update if it was already committed but currently629 // we have no way of detecting the difference between a committed and suspended630 // update here.631 markRenderEventTime(updateExpirationTime);632 // Process this update.633 if (update.eagerReducer === reducer) {634 // If this update was processed eagerly, and its reducer matches the635 // current reducer, we can use the eagerly computed state.636 newState = ((update.eagerState: any): S);637 } else {638 const action = update.action;639 newState = reducer(newState, action);640 }641 }642 prevUpdate = update;643 update = update.next;644 } while (update !== null && update !== first);645 if (!didSkip) {646 newBaseUpdate = prevUpdate;647 newBaseState = newState;648 }649 // Mark that the fiber performed work, but only if the new state is650 // different from the current state.651 if (!is(newState, hook.memoizedState)) {652 markWorkInProgressReceivedUpdate();653 }654 hook.memoizedState = newState;655 hook.baseUpdate = newBaseUpdate;656 hook.baseState = newBaseState;657 queue.lastRenderedState = newState;658 }659 const dispatch: Dispatch<A> = (queue.dispatch: any);660 return [hook.memoizedState, dispatch];661}662function mountState<S>(663 initialState: (() => S) | S,664): [S, Dispatch<BasicStateAction<S>>] {665 const hook = mountWorkInProgressHook();666 if (typeof initialState === 'function') {667 initialState = initialState();668 }669 hook.memoizedState = hook.baseState = initialState;670 const queue = (hook.queue = {671 last: null,672 dispatch: null,673 lastRenderedReducer: basicStateReducer,674 lastRenderedState: (initialState: any),675 });676 const dispatch: Dispatch<677 BasicStateAction<S>,678 > = (queue.dispatch = (dispatchAction.bind(679 null,680 // Flow doesn't know this is non-null, but we do.681 ((currentlyRenderingFiber: any): Fiber),682 queue,683 ): any));684 return [hook.memoizedState, dispatch];685}686function updateState<S>(687 initialState: (() => S) | S,688): [S, Dispatch<BasicStateAction<S>>] {689 return updateReducer(basicStateReducer, (initialState: any));690}691function pushEffect(tag, create, destroy, deps) {692 const effect: Effect = {693 tag,694 create,695 destroy,696 deps,697 // Circular698 next: (null: any),699 };700 if (componentUpdateQueue === null) {701 componentUpdateQueue = createFunctionComponentUpdateQueue();702 componentUpdateQueue.lastEffect = effect.next = effect;703 } else {704 const lastEffect = componentUpdateQueue.lastEffect;705 if (lastEffect === null) {706 componentUpdateQueue.lastEffect = effect.next = effect;707 } else {708 const firstEffect = lastEffect.next;709 lastEffect.next = effect;710 effect.next = firstEffect;711 componentUpdateQueue.lastEffect = effect;712 }713 }714 return effect;715}716function mountRef<T>(initialValue: T): {current: T} {717 const hook = mountWorkInProgressHook();718 const ref = {current: initialValue};719 if (__DEV__) {720 Object.seal(ref);721 }722 hook.memoizedState = ref;723 return ref;724}725function updateRef<T>(initialValue: T): {current: T} {726 const hook = updateWorkInProgressHook();727 return hook.memoizedState;728}729function mountEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {730 const hook = mountWorkInProgressHook();731 const nextDeps = deps === undefined ? null : deps;732 sideEffectTag |= fiberEffectTag;733 hook.memoizedState = pushEffect(hookEffectTag, create, undefined, nextDeps);734}735function updateEffectImpl(fiberEffectTag, hookEffectTag, create, deps): void {736 const hook = updateWorkInProgressHook();737 const nextDeps = deps === undefined ? null : deps;738 let destroy = undefined;739 if (currentHook !== null) {740 const prevEffect = currentHook.memoizedState;741 destroy = prevEffect.destroy;742 if (nextDeps !== null) {743 const prevDeps = prevEffect.deps;744 if (areHookInputsEqual(nextDeps, prevDeps)) {745 pushEffect(NoHookEffect, create, destroy, nextDeps);746 return;747 }748 }749 }750 sideEffectTag |= fiberEffectTag;751 hook.memoizedState = pushEffect(hookEffectTag, create, destroy, nextDeps);752}753function mountEffect(754 create: () => (() => void) | void,755 deps: Array<mixed> | void | null,756): void {757 return mountEffectImpl(758 UpdateEffect | PassiveEffect,759 UnmountPassive | MountPassive,760 create,761 deps,762 );763}764function updateEffect(765 create: () => (() => void) | void,766 deps: Array<mixed> | void | null,767): void {768 return updateEffectImpl(769 UpdateEffect | PassiveEffect,770 UnmountPassive | MountPassive,771 create,772 deps,773 );774}775function mountLayoutEffect(776 create: () => (() => void) | void,777 deps: Array<mixed> | void | null,778): void {779 return mountEffectImpl(780 UpdateEffect,781 UnmountMutation | MountLayout,782 create,783 deps,784 );785}786function updateLayoutEffect(787 create: () => (() => void) | void,788 deps: Array<mixed> | void | null,789): void {790 return updateEffectImpl(791 UpdateEffect,792 UnmountMutation | MountLayout,793 create,794 deps,795 );796}797function imperativeHandleEffect<T>(798 create: () => T,799 ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,800) {801 if (typeof ref === 'function') {802 const refCallback = ref;803 const inst = create();804 refCallback(inst);805 return () => {806 refCallback(null);807 };808 } else if (ref !== null && ref !== undefined) {809 const refObject = ref;810 if (__DEV__) {811 warning(812 refObject.hasOwnProperty('current'),813 'Expected useImperativeHandle() first argument to either be a ' +814 'ref callback or React.createRef() object. Instead received: %s.',815 'an object with keys {' + Object.keys(refObject).join(', ') + '}',816 );817 }818 const inst = create();819 refObject.current = inst;820 return () => {821 refObject.current = null;822 };823 }824}825function mountImperativeHandle<T>(826 ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,827 create: () => T,828 deps: Array<mixed> | void | null,829): void {830 if (__DEV__) {831 warning(832 typeof create === 'function',833 'Expected useImperativeHandle() second argument to be a function ' +834 'that creates a handle. Instead received: %s.',835 create !== null ? typeof create : 'null',836 );837 }838 // TODO: If deps are provided, should we skip comparing the ref itself?839 const effectDeps =840 deps !== null && deps !== undefined ? deps.concat([ref]) : null;841 return mountEffectImpl(842 UpdateEffect,843 UnmountMutation | MountLayout,844 imperativeHandleEffect.bind(null, create, ref),845 effectDeps,846 );847}848function updateImperativeHandle<T>(849 ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,850 create: () => T,851 deps: Array<mixed> | void | null,852): void {853 if (__DEV__) {854 warning(855 typeof create === 'function',856 'Expected useImperativeHandle() second argument to be a function ' +857 'that creates a handle. Instead received: %s.',858 create !== null ? typeof create : 'null',859 );860 }861 // TODO: If deps are provided, should we skip comparing the ref itself?862 const effectDeps =863 deps !== null && deps !== undefined ? deps.concat([ref]) : null;864 return updateEffectImpl(865 UpdateEffect,866 UnmountMutation | MountLayout,867 imperativeHandleEffect.bind(null, create, ref),868 effectDeps,869 );870}871function mountDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void {872 // This hook is normally a no-op.873 // The react-debug-hooks package injects its own implementation874 // so that e.g. DevTools can display custom hook values.875}876const updateDebugValue = mountDebugValue;877function mountCallback<T>(callback: T, deps: Array<mixed> | void | null): T {878 const hook = mountWorkInProgressHook();879 const nextDeps = deps === undefined ? null : deps;880 hook.memoizedState = [callback, nextDeps];881 return callback;882}883function updateCallback<T>(callback: T, deps: Array<mixed> | void | null): T {884 const hook = updateWorkInProgressHook();885 const nextDeps = deps === undefined ? null : deps;886 const prevState = hook.memoizedState;887 if (prevState !== null) {888 if (nextDeps !== null) {889 const prevDeps: Array<mixed> | null = prevState[1];890 if (areHookInputsEqual(nextDeps, prevDeps)) {891 return prevState[0];892 }893 }894 }895 hook.memoizedState = [callback, nextDeps];896 return callback;897}898function mountMemo<T>(899 nextCreate: () => T,900 deps: Array<mixed> | void | null,901): T {902 const hook = mountWorkInProgressHook();903 const nextDeps = deps === undefined ? null : deps;904 const nextValue = nextCreate();905 hook.memoizedState = [nextValue, nextDeps];906 return nextValue;907}908function updateMemo<T>(909 nextCreate: () => T,910 deps: Array<mixed> | void | null,911): T {912 const hook = updateWorkInProgressHook();913 const nextDeps = deps === undefined ? null : deps;914 const prevState = hook.memoizedState;915 if (prevState !== null) {916 // Assume these are defined. If they're not, areHookInputsEqual will warn.917 if (nextDeps !== null) {918 const prevDeps: Array<mixed> | null = prevState[1];919 if (areHookInputsEqual(nextDeps, prevDeps)) {920 return prevState[0];921 }922 }923 }924 const nextValue = nextCreate();925 hook.memoizedState = [nextValue, nextDeps];926 return nextValue;927}928function dispatchAction<S, A>(929 fiber: Fiber,930 queue: UpdateQueue<S, A>,931 action: A,932) {933 invariant(934 numberOfReRenders < RE_RENDER_LIMIT,935 'Too many re-renders. React limits the number of renders to prevent ' +936 'an infinite loop.',937 );938 if (__DEV__) {939 warning(940 arguments.length <= 3,941 "State updates from the useState() and useReducer() Hooks don't support the " +942 'second callback argument. To execute a side effect after ' +943 'rendering, declare it in the component body with useEffect().',944 );945 }946 const alternate = fiber.alternate;947 if (948 fiber === currentlyRenderingFiber ||949 (alternate !== null && alternate === currentlyRenderingFiber)950 ) {951 // This is a render phase update. Stash it in a lazily-created map of952 // queue -> linked list of updates. After this render pass, we'll restart953 // and apply the stashed updates on top of the work-in-progress hook.954 didScheduleRenderPhaseUpdate = true;955 const update: Update<S, A> = {956 expirationTime: renderExpirationTime,957 action,958 eagerReducer: null,959 eagerState: null,960 next: null,961 };962 if (renderPhaseUpdates === null) {963 renderPhaseUpdates = new Map();964 }965 const firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);966 if (firstRenderPhaseUpdate === undefined) {967 renderPhaseUpdates.set(queue, update);968 } else {969 // Append the update to the end of the list.970 let lastRenderPhaseUpdate = firstRenderPhaseUpdate;971 while (lastRenderPhaseUpdate.next !== null) {972 lastRenderPhaseUpdate = lastRenderPhaseUpdate.next;973 }974 lastRenderPhaseUpdate.next = update;975 }976 } else {977 flushPassiveEffects();978 const currentTime = requestCurrentTime();979 const expirationTime = computeExpirationForFiber(currentTime, fiber);980 const update: Update<S, A> = {981 expirationTime,982 action,983 eagerReducer: null,984 eagerState: null,985 next: null,986 };987 // Append the update to the end of the list.988 const last = queue.last;989 if (last === null) {990 // This is the first update. Create a circular list.991 update.next = update;992 } else {993 const first = last.next;994 if (first !== null) {995 // Still circular.996 update.next = first;997 }998 last.next = update;999 }1000 queue.last = update;1001 if (1002 fiber.expirationTime === NoWork &&1003 (alternate === null || alternate.expirationTime === NoWork)1004 ) {1005 // The queue is currently empty, which means we can eagerly compute the1006 // next state before entering the render phase. If the new state is the1007 // same as the current state, we may be able to bail out entirely.1008 const lastRenderedReducer = queue.lastRenderedReducer;1009 if (lastRenderedReducer !== null) {1010 let prevDispatcher;1011 if (__DEV__) {1012 prevDispatcher = ReactCurrentDispatcher.current;1013 ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnUpdateInDEV;1014 }1015 try {1016 const currentState: S = (queue.lastRenderedState: any);1017 const eagerState = lastRenderedReducer(currentState, action);1018 // Stash the eagerly computed state, and the reducer used to compute1019 // it, on the update object. If the reducer hasn't changed by the1020 // time we enter the render phase, then the eager state can be used1021 // without calling the reducer again.1022 update.eagerReducer = lastRenderedReducer;1023 update.eagerState = eagerState;1024 if (is(eagerState, currentState)) {1025 // Fast path. We can bail out without scheduling React to re-render.1026 // It's still possible that we'll need to rebase this update later,1027 // if the component re-renders for a different reason and by that1028 // time the reducer has changed.1029 return;1030 }1031 } catch (error) {1032 // Suppress the error. It will throw again in the render phase.1033 } finally {1034 if (__DEV__) {1035 ReactCurrentDispatcher.current = prevDispatcher;1036 }1037 }1038 }1039 }1040 if (__DEV__) {1041 // jest isn't a 'global', it's just exposed to tests via a wrapped function1042 // further, this isn't a test file, so flow doesn't recognize the symbol. So...1043 // $FlowExpectedError - because requirements don't give a damn about your type sigs.1044 if ('undefined' !== typeof jest) {1045 warnIfNotCurrentlyActingUpdatesInDev(fiber);1046 }1047 }1048 scheduleWork(fiber, expirationTime);1049 }1050}1051export const ContextOnlyDispatcher: Dispatcher = {1052 readContext,1053 useCallback: throwInvalidHookError,1054 useContext: throwInvalidHookError,1055 useEffect: throwInvalidHookError,1056 useImperativeHandle: throwInvalidHookError,1057 useLayoutEffect: throwInvalidHookError,1058 useMemo: throwInvalidHookError,1059 useReducer: throwInvalidHookError,1060 useRef: throwInvalidHookError,1061 useState: throwInvalidHookError,1062 useDebugValue: throwInvalidHookError,1063};1064const HooksDispatcherOnMount: Dispatcher = {1065 readContext,1066 useCallback: mountCallback,1067 useContext: readContext,1068 useEffect: mountEffect,1069 useImperativeHandle: mountImperativeHandle,1070 useLayoutEffect: mountLayoutEffect,1071 useMemo: mountMemo,1072 useReducer: mountReducer,1073 useRef: mountRef,1074 useState: mountState,1075 useDebugValue: mountDebugValue,1076};1077const HooksDispatcherOnUpdate: Dispatcher = {1078 readContext,1079 useCallback: updateCallback,1080 useContext: readContext,1081 useEffect: updateEffect,1082 useImperativeHandle: updateImperativeHandle,1083 useLayoutEffect: updateLayoutEffect,1084 useMemo: updateMemo,1085 useReducer: updateReducer,1086 useRef: updateRef,1087 useState: updateState,1088 useDebugValue: updateDebugValue,1089};1090let HooksDispatcherOnMountInDEV: Dispatcher | null = null;1091let HooksDispatcherOnMountWithHookTypesInDEV: Dispatcher | null = null;1092let HooksDispatcherOnUpdateInDEV: Dispatcher | null = null;1093let InvalidNestedHooksDispatcherOnMountInDEV: Dispatcher | null = null;1094let InvalidNestedHooksDispatcherOnUpdateInDEV: Dispatcher | null = null;1095if (__DEV__) {1096 const warnInvalidContextAccess = () => {1097 warning(1098 false,1099 'Context can only be read while React is rendering. ' +1100 'In classes, you can read it in the render method or getDerivedStateFromProps. ' +1101 'In function components, you can read it directly in the function body, but not ' +1102 'inside Hooks like useReducer() or useMemo().',1103 );1104 };1105 const warnInvalidHookAccess = () => {1106 warning(1107 false,1108 'Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. ' +1109 'You can only call Hooks at the top level of your React function. ' +1110 'For more information, see ' +1111 'https://fb.me/rules-of-hooks',1112 );1113 };1114 HooksDispatcherOnMountInDEV = {1115 readContext<T>(1116 context: ReactContext<T>,1117 observedBits: void | number | boolean,1118 ): T {1119 return readContext(context, observedBits);1120 },1121 useCallback<T>(callback: T, deps: Array<mixed> | void | null): T {1122 currentHookNameInDev = 'useCallback';1123 mountHookTypesDev();1124 checkDepsAreArrayDev(deps);1125 return mountCallback(callback, deps);1126 },1127 useContext<T>(1128 context: ReactContext<T>,1129 observedBits: void | number | boolean,1130 ): T {1131 currentHookNameInDev = 'useContext';1132 mountHookTypesDev();1133 return readContext(context, observedBits);1134 },1135 useEffect(1136 create: () => (() => void) | void,1137 deps: Array<mixed> | void | null,1138 ): void {1139 currentHookNameInDev = 'useEffect';1140 mountHookTypesDev();1141 checkDepsAreArrayDev(deps);1142 return mountEffect(create, deps);1143 },1144 useImperativeHandle<T>(1145 ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,1146 create: () => T,1147 deps: Array<mixed> | void | null,1148 ): void {1149 currentHookNameInDev = 'useImperativeHandle';1150 mountHookTypesDev();1151 checkDepsAreArrayDev(deps);1152 return mountImperativeHandle(ref, create, deps);1153 },1154 useLayoutEffect(1155 create: () => (() => void) | void,1156 deps: Array<mixed> | void | null,1157 ): void {1158 currentHookNameInDev = 'useLayoutEffect';1159 mountHookTypesDev();1160 checkDepsAreArrayDev(deps);1161 return mountLayoutEffect(create, deps);1162 },1163 useMemo<T>(create: () => T, deps: Array<mixed> | void | null): T {1164 currentHookNameInDev = 'useMemo';1165 mountHookTypesDev();1166 checkDepsAreArrayDev(deps);1167 const prevDispatcher = ReactCurrentDispatcher.current;1168 ReactCurrentDispatcher.current = InvalidNestedHooksDispatcherOnMountInDEV;1169 try {1170 return mountMemo(create, deps);1171 } finally {1172 ReactCurrentDispatcher.current = prevDispatcher;1173 }1174 },1175 useReducer<S, I, A>(1176 reducer: (S, A) => S,1177 initialArg: I,1178 init?: I => S,1179 ): [S, Dispatch<A>] {1180 currentHookNameInDev = 'useReducer';...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const { checkDepsAreArrayDev } = playwright;3checkDepsAreArrayDev(['a', 'b']);4const playwright = require('playwright');5const { checkDepsAreArrayDev } = playwright;6checkDepsAreArrayDev(['a', 'b']);7const playwright = require('playwright');8const { checkDepsAreArrayDev } = playwright;9checkDepsAreArrayDev(['a', 'b']);10const playwright = require('playwright');11const { checkDepsAreArrayDev } = playwright;12checkDepsAreArrayDev(['a', 'b']);13const playwright = require('playwright');14const { checkDepsAreArrayDev } = playwright;15checkDepsAreArrayDev(['a', 'b']);16const playwright = require('playwright');17const { checkDepsAreArrayDev } = playwright;18checkDepsAreArrayDev(['a', 'b']);19const playwright = require('playwright');20const { checkDepsAreArrayDev } = playwright;21checkDepsAreArrayDev(['a', 'b']);22const playwright = require('playwright');23const { checkDepsAreArrayDev } = playwright;24checkDepsAreArrayDev(['a', 'b']);25const playwright = require('playwright');26const { checkDepsAreArrayDev } = playwright;27checkDepsAreArrayDev(['a', 'b']);28const playwright = require('playwright');29const { checkD

Full Screen

Using AI Code Generation

copy

Full Screen

1const { checkDepsAreArrayDev } = require('@playwright/test/lib/utils/deps');2const { expect } = require('chai');3const { describe, it } = require('mocha');4describe('test', () => {5 it('test', () => {6 expect(checkDepsAreArrayDev(['puppeteer'])).to.be.true;7 });8});9{10 "scripts": {11 },12 "devDependencies": {13 }14}15const { checkDepsAreArrayDev } = require('@playwright/test/lib/utils/deps');16const { expect } = require('chai');17const { describe, it } = require('mocha');18describe('test', () => {19 it('test', () => {20 expect(checkDepsAreArrayDev(['puppeteer'])).to.be.true;21 });22});23{24 "scripts": {25 },26 "devDependencies": {27 }28}

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));3const playwright = require('playwright');4console.log(playwright.checkDepsAreArrayDev(['foo', 'bar']));5const playwright = require('playwright');6console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));7const playwright = require('playwright');8console.log(playwright.checkDepsAreArrayDev(['foo', 'bar']));9const playwright = require('playwright');10console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));11const playwright = require('playwright');12console.log(playwright.checkDepsAreArrayDev(['foo', 'bar']));13const playwright = require('playwright');14console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));15const playwright = require('playwright');16console.log(playwright.checkDepsAreArrayDev(['foo', 'bar']));17const playwright = require('playwright');18console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));19const playwright = require('playwright');20console.log(playwright.checkDepsAreArrayDev(['foo', 'bar']));21const playwright = require('playwright');22console.log(playwright.internal.checkDepsAreArrayDev(['foo', 'bar']));23const playwright = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {checkDepsAreArrayDev} = require('playwright/lib/utils/utils');2const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);3console.log(deps);4const {checkDepsAreArrayDev} = require('playwright');5const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);6console.log(deps);7const {checkDepsAreArrayDev} = require('playwright');8const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);9console.log(deps);10const {checkDepsAreArrayDev} = require('playwright');11const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);12console.log(deps);13const {checkDepsAreArrayDev} = require('playwright');14const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);15console.log(deps);16const {checkDepsAreArrayDev} = require('playwright');17const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);18console.log(deps);19const {checkDepsAreArrayDev} = require('playwright');20const deps = checkDepsAreArrayDev(['chromium', 'firefox', 'webkit']);21console.log(deps);22const {checkDepsAreArrayDev} = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { checkDepsAreArrayDev } = require('@playwright/test');2const deps = ['fs', 'path', 'os'];3checkDepsAreArrayDev(deps);4 at checkDepsAreArrayDev (D:\work\playwright\packages\playwright-test\src\installDeps.ts:9:11)5 at Object.<anonymous> (D:\work\playwright\test.js:5:1)6 at Module._compile (internal/modules/cjs/loader.js:1137:30)7 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)8 at Module.load (internal/modules/cjs/loader.js:985:32)9 at Function.Module._load (internal/modules/cjs/loader.js:878:14)10 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful