Best JavaScript code snippet using playwright-internal
runtime-core.cjs.prod.js
Source:runtime-core.cjs.prod.js  
...1984            }, parentSuspense);1985        };1986        function unmount(vnode) {1987            // reset the shapeFlag so it can be properly unmounted1988            resetShapeFlag(vnode);1989            _unmount(vnode, instance, parentSuspense);1990        }1991        function pruneCache(filter) {1992            cache.forEach((vnode, key) => {1993                const name = getComponentName(vnode.type);1994                if (name && (!filter || !filter(name))) {1995                    pruneCacheEntry(key);1996                }1997            });1998        }1999        function pruneCacheEntry(key) {2000            const cached = cache.get(key);2001            if (!current || cached.type !== current.type) {2002                unmount(cached);2003            }2004            else if (current) {2005                // current active instance should no longer be kept-alive.2006                // we can't unmount it now but it might be later, so reset its flag now.2007                resetShapeFlag(current);2008            }2009            cache.delete(key);2010            keys.delete(key);2011        }2012        // prune cache on include/exclude prop change2013        watch(() => [props.include, props.exclude], ([include, exclude]) => {2014            include && pruneCache(name => matches(include, name));2015            exclude && pruneCache(name => !matches(exclude, name));2016        }, 2017        // prune post-render after `current` has been updated2018        { flush: 'post', deep: true });2019        // cache sub tree after render2020        let pendingCacheKey = null;2021        const cacheSubtree = () => {2022            // fix #1621, the pendingCacheKey could be 02023            if (pendingCacheKey != null) {2024                cache.set(pendingCacheKey, getInnerChild(instance.subTree));2025            }2026        };2027        onMounted(cacheSubtree);2028        onUpdated(cacheSubtree);2029        onBeforeUnmount(() => {2030            cache.forEach(cached => {2031                const { subTree, suspense } = instance;2032                const vnode = getInnerChild(subTree);2033                if (cached.type === vnode.type) {2034                    // current instance will be unmounted as part of keep-alive's unmount2035                    resetShapeFlag(vnode);2036                    // but invoke its deactivated hook here2037                    const da = vnode.component.da;2038                    da && queuePostRenderEffect(da, suspense);2039                    return;2040                }2041                unmount(cached);2042            });2043        });2044        return () => {2045            pendingCacheKey = null;2046            if (!slots.default) {2047                return null;2048            }2049            const children = slots.default();2050            const rawVNode = children[0];2051            if (children.length > 1) {2052                current = null;2053                return children;2054            }2055            else if (!isVNode(rawVNode) ||2056                (!(rawVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) &&2057                    !(rawVNode.shapeFlag & 128 /* SUSPENSE */))) {2058                current = null;2059                return rawVNode;2060            }2061            let vnode = getInnerChild(rawVNode);2062            const comp = vnode.type;2063            const name = getComponentName(comp);2064            const { include, exclude, max } = props;2065            if ((include && (!name || !matches(include, name))) ||2066                (exclude && name && matches(exclude, name))) {2067                current = vnode;2068                return rawVNode;2069            }2070            const key = vnode.key == null ? comp : vnode.key;2071            const cachedVNode = cache.get(key);2072            // clone vnode if it's reused because we are going to mutate it2073            if (vnode.el) {2074                vnode = cloneVNode(vnode);2075                if (rawVNode.shapeFlag & 128 /* SUSPENSE */) {2076                    rawVNode.ssContent = vnode;2077                }2078            }2079            // #1513 it's possible for the returned vnode to be cloned due to attr2080            // fallthrough or scopeId, so the vnode here may not be the final vnode2081            // that is mounted. Instead of caching it directly, we store the pending2082            // key and cache `instance.subTree` (the normalized vnode) in2083            // beforeMount/beforeUpdate hooks.2084            pendingCacheKey = key;2085            if (cachedVNode) {2086                // copy over mounted state2087                vnode.el = cachedVNode.el;2088                vnode.component = cachedVNode.component;2089                if (vnode.transition) {2090                    // recursively update transition hooks on subTree2091                    setTransitionHooks(vnode, vnode.transition);2092                }2093                // avoid vnode being mounted as fresh2094                vnode.shapeFlag |= 512 /* COMPONENT_KEPT_ALIVE */;2095                // make this key the freshest2096                keys.delete(key);2097                keys.add(key);2098            }2099            else {2100                keys.add(key);2101                // prune oldest entry2102                if (max && keys.size > parseInt(max, 10)) {2103                    pruneCacheEntry(keys.values().next().value);2104                }2105            }2106            // avoid vnode being unmounted2107            vnode.shapeFlag |= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;2108            current = vnode;2109            return rawVNode;2110        };2111    }2112};2113// export the public type for h/tsx inference2114// also to avoid inline import() in generated d.ts files2115const KeepAlive = KeepAliveImpl;2116function matches(pattern, name) {2117    if (shared.isArray(pattern)) {2118        return pattern.some((p) => matches(p, name));2119    }2120    else if (shared.isString(pattern)) {2121        return pattern.split(',').indexOf(name) > -1;2122    }2123    else if (pattern.test) {2124        return pattern.test(name);2125    }2126    /* istanbul ignore next */2127    return false;2128}2129function onActivated(hook, target) {2130    registerKeepAliveHook(hook, "a" /* ACTIVATED */, target);2131}2132function onDeactivated(hook, target) {2133    registerKeepAliveHook(hook, "da" /* DEACTIVATED */, target);2134}2135function registerKeepAliveHook(hook, type, target = currentInstance) {2136    // cache the deactivate branch check wrapper for injected hooks so the same2137    // hook can be properly deduped by the scheduler. "__wdc" stands for "with2138    // deactivation check".2139    const wrappedHook = hook.__wdc ||2140        (hook.__wdc = () => {2141            // only fire the hook if the target instance is NOT in a deactivated branch.2142            let current = target;2143            while (current) {2144                if (current.isDeactivated) {2145                    return;2146                }2147                current = current.parent;2148            }2149            hook();2150        });2151    injectHook(type, wrappedHook, target);2152    // In addition to registering it on the target instance, we walk up the parent2153    // chain and register it on all ancestor instances that are keep-alive roots.2154    // This avoids the need to walk the entire component tree when invoking these2155    // hooks, and more importantly, avoids the need to track child components in2156    // arrays.2157    if (target) {2158        let current = target.parent;2159        while (current && current.parent) {2160            if (isKeepAlive(current.parent.vnode)) {2161                injectToKeepAliveRoot(wrappedHook, type, target, current);2162            }2163            current = current.parent;2164        }2165    }2166}2167function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {2168    // injectHook wraps the original for error handling, so make sure to remove2169    // the wrapped version.2170    const injected = injectHook(type, hook, keepAliveRoot, true /* prepend */);2171    onUnmounted(() => {2172        shared.remove(keepAliveRoot[type], injected);2173    }, target);2174}2175function resetShapeFlag(vnode) {2176    let shapeFlag = vnode.shapeFlag;2177    if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {2178        shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;2179    }2180    if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {2181        shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;2182    }2183    vnode.shapeFlag = shapeFlag;2184}2185function getInnerChild(vnode) {2186    return vnode.shapeFlag & 128 /* SUSPENSE */ ? vnode.ssContent : vnode;2187}2188const isInternalKey = (key) => key[0] === '_' || key === '$stable';2189const normalizeSlotValue = (value) => shared.isArray(value)...index.js
Source:index.js  
...451        };452    453        function unmount(vnode) {454          // reset the shapeFlag so it can be properly unmounted455          resetShapeFlag(vnode);456          _unmount(vnode, instance, parentSuspense, true);457        }458    459        function pruneCache(filter) {460          cache.forEach((vnode, key) => {461            const name = getComponentName(vnode.type);462            if (name && (!filter || !filter(name))) {463              pruneCacheEntry(key);464            }465          });466        }467    468        function pruneCacheEntry(key) {469          const cached = cache.get(key);470          if (!current || cached.type !== current.type) {471            unmount(cached);472          } else if (current) {473            // current active instance should no longer be kept-alive.474            // we can't unmount it now but it might be later, so reset its flag now.475            resetShapeFlag(current);476          }477          cache.delete(key);478          keys.delete(key);479        }480    481        // core482        let router;483        {484          router = VueRouter__default["default"].useRouter();485        }486        if (!router) {487          throw new Error("router is not found! In unit test mode ,router is got from gloabl.router, otherwise VueRouter.useRouter()")488        }489        const _core = new Core({ router, pruneCacheEntry, replaceStay: props.replaceStay });490        {491          window.__core = _core;492        }493        // prune cache on include/exclude prop change494        Vue.watch(495          () => [props.include, props.exclude],496          ([include, exclude]) => {497            include && pruneCache(name => matches(include, name));498            exclude && pruneCache(name => !matches(exclude, name));499          },500          // prune post-render after `current` has been updated501          { flush: 'post', deep: true }502        );503    504        // cache sub tree after render505        let pendingCacheKey = null;506        const cacheSubtree = () => {507          // fix #1621, the pendingCacheKey could be 0508          if (pendingCacheKey != null) {509            cache.set(pendingCacheKey, getInnerChild(instance.subTree));510          }511        };512        Vue.onMounted(cacheSubtree);513        Vue.onUpdated(cacheSubtree);514    515        Vue.onBeforeUnmount(() => {516          cache.forEach(cached => {517            const { subTree, suspense } = instance;518            const vnode = getInnerChild(subTree);519            if (cached.type === vnode.type) {520              // current instance will be unmounted as part of keep-alive's unmount521              resetShapeFlag(vnode);522              // but invoke its deactivated hook here523              const da = vnode.component.da;524              da && queuePostRenderEffect(da, suspense);525              return526            }527            unmount(cached);528          });529        });530    531        return () => {532          pendingCacheKey = null;533    534          if (!slots.default) {535            return null536          }537          // generate a specific key for every vnode538          const _key = _core.genKeyForVnode();539          540          const children = slots.default({'key': _key});541          const rawVNode = children[0];542          if (children.length > 1) {543            {544              Vue.warn(`KeepAlive should contain exactly one component child.`);545            }546            current = null;547            _core.genInitialKeyNextTime();548            return children549          } else if (550            !Vue.isVNode(rawVNode) ||551            (!(rawVNode.shapeFlag === ShapeFlags.STATEFUL_COMPONENT) &&552              !(rawVNode.shapeFlag === ShapeFlags.SUSPENSE))553          ) {554            _core.genInitialKeyNextTime();555            current = null;556            return rawVNode557          }558    559          let vnode = getInnerChild(rawVNode);560          const comp = vnode.type;561          // for async components, name check should be based in its loaded562          // inner component if available563          const name = getComponentName(564            isAsyncWrapper(vnode)565              ? (vnode.type).__asyncResolved || {}566              : comp567          );568    569          const { include, exclude, max } = props;570    571          if (572            (include && (!name || !matches(include, name))) ||573            (exclude && name && matches(exclude, name))574          ) {575            current = vnode;576            return rawVNode577          }578    579          const key = vnode.key == null ? comp : vnode.key;580          const cachedVNode = cache.get(key);581          // clone vnode if it's reused because we are going to mutate it582          if (vnode.el) {583            vnode = Vue.cloneVNode(vnode);584            if (rawVNode.shapeFlag & ShapeFlags.SUSPENSE) {585              rawVNode.ssContent = vnode;586            }587          }588          // #1513 it's possible for the returned vnode to be cloned due to attr589          // fallthrough or scopeId, so the vnode here may not be the final vnode590          // that is mounted. Instead of caching it directly, we store the pending591          // key and cache `instance.subTree` (the normalized vnode) in592          // beforeMount/beforeUpdate hooks.593          pendingCacheKey = key;594          if (cachedVNode) {595            // copy over mounted state596            vnode.el = cachedVNode.el;597            vnode.component = cachedVNode.component;598            599            if (vnode.transition) {600              // recursively update transition hooks on subTree601              Vue.setTransitionHooks(vnode, vnode.transition);602            }603            // avoid vnode being mounted as fresh604            vnode.shapeFlag |= ShapeFlags.COMPONENT_KEPT_ALIVE;605            // make this key the freshest606            keys.delete(key);607            keys.add(key);608          } else {609            keys.add(key);610            // prune oldest entry611            if (max && keys.size > parseInt(max, 10)) {612              pruneCacheEntry(keys.values().next().value);613            }614          }615          // avoid vnode being unmounted616          vnode.shapeFlag |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;617    618          current = vnode;619          return rawVNode620        }621      }622    };623    624    const StackKeepAlive = StackKeepAliveImpl;625    626    function matches(pattern, name){627      if (shared.isArray(pattern)) {628        return pattern.some((p) => matches(p, name))629      } else if (shared.isString(pattern)) {630        return pattern.split(',').includes(name)631      } else if (pattern.test) {632        return pattern.test(name)633      }634      /* istanbul ignore next */635      return false636    }637    638    function resetShapeFlag(vnode) {639      let shapeFlag = vnode.shapeFlag;640      if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {641        shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;642      }643      if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {644        shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE;645      }646      vnode.shapeFlag = shapeFlag;647    }648    649    function getInnerChild(vnode) {650      return vnode.shapeFlag & ShapeFlags.SUSPENSE ? vnode.ssContent : vnode651    }652  var components = { StackKeepAlive };...library.js
Source:library.js  
...450      };451  452      function unmount(vnode) {453        // reset the shapeFlag so it can be properly unmounted454        resetShapeFlag(vnode);455        _unmount(vnode, instance, parentSuspense, true);456      }457  458      function pruneCache(filter) {459        cache.forEach((vnode, key) => {460          const name = getComponentName(vnode.type);461          if (name && (!filter || !filter(name))) {462            pruneCacheEntry(key);463          }464        });465      }466  467      function pruneCacheEntry(key) {468        const cached = cache.get(key);469        if (!current || cached.type !== current.type) {470          unmount(cached);471        } else if (current) {472          // current active instance should no longer be kept-alive.473          // we can't unmount it now but it might be later, so reset its flag now.474          resetShapeFlag(current);475        }476        cache.delete(key);477        keys.delete(key);478      }479  480      // core481      let router;482      {483        router = VueRouter__default["default"].useRouter();484      }485      if (!router) {486        throw new Error("router is not found! In unit test mode ,router is got from gloabl.router, otherwise VueRouter.useRouter()")487      }488      const _core = new Core({ router, pruneCacheEntry, replaceStay: props.replaceStay });489      {490        window.__core = _core;491      }492      // prune cache on include/exclude prop change493      Vue.watch(494        () => [props.include, props.exclude],495        ([include, exclude]) => {496          include && pruneCache(name => matches(include, name));497          exclude && pruneCache(name => !matches(exclude, name));498        },499        // prune post-render after `current` has been updated500        { flush: 'post', deep: true }501      );502  503      // cache sub tree after render504      let pendingCacheKey = null;505      const cacheSubtree = () => {506        // fix #1621, the pendingCacheKey could be 0507        if (pendingCacheKey != null) {508          cache.set(pendingCacheKey, getInnerChild(instance.subTree));509        }510      };511      Vue.onMounted(cacheSubtree);512      Vue.onUpdated(cacheSubtree);513  514      Vue.onBeforeUnmount(() => {515        cache.forEach(cached => {516          const { subTree, suspense } = instance;517          const vnode = getInnerChild(subTree);518          if (cached.type === vnode.type) {519            // current instance will be unmounted as part of keep-alive's unmount520            resetShapeFlag(vnode);521            // but invoke its deactivated hook here522            const da = vnode.component.da;523            da && queuePostRenderEffect(da, suspense);524            return525          }526          unmount(cached);527        });528      });529  530      return () => {531        pendingCacheKey = null;532  533        if (!slots.default) {534          return null535        }536        // generate a specific key for every vnode537        const _key = _core.genKeyForVnode();538        539        const children = slots.default({'key': _key});540        const rawVNode = children[0];541        if (children.length > 1) {542          {543            Vue.warn(`KeepAlive should contain exactly one component child.`);544          }545          current = null;546          _core.genInitialKeyNextTime();547          return children548        } else if (549          !Vue.isVNode(rawVNode) ||550          (!(rawVNode.shapeFlag === ShapeFlags.STATEFUL_COMPONENT) &&551            !(rawVNode.shapeFlag === ShapeFlags.SUSPENSE))552        ) {553          _core.genInitialKeyNextTime();554          current = null;555          return rawVNode556        }557  558        let vnode = getInnerChild(rawVNode);559        const comp = vnode.type;560        // for async components, name check should be based in its loaded561        // inner component if available562        const name = getComponentName(563          isAsyncWrapper(vnode)564            ? (vnode.type).__asyncResolved || {}565            : comp566        );567  568        const { include, exclude, max } = props;569  570        if (571          (include && (!name || !matches(include, name))) ||572          (exclude && name && matches(exclude, name))573        ) {574          current = vnode;575          return rawVNode576        }577  578        const key = vnode.key == null ? comp : vnode.key;579        const cachedVNode = cache.get(key);580        // clone vnode if it's reused because we are going to mutate it581        if (vnode.el) {582          vnode = Vue.cloneVNode(vnode);583          if (rawVNode.shapeFlag & ShapeFlags.SUSPENSE) {584            rawVNode.ssContent = vnode;585          }586        }587        // #1513 it's possible for the returned vnode to be cloned due to attr588        // fallthrough or scopeId, so the vnode here may not be the final vnode589        // that is mounted. Instead of caching it directly, we store the pending590        // key and cache `instance.subTree` (the normalized vnode) in591        // beforeMount/beforeUpdate hooks.592        pendingCacheKey = key;593        if (cachedVNode) {594          // copy over mounted state595          vnode.el = cachedVNode.el;596          vnode.component = cachedVNode.component;597          598          if (vnode.transition) {599            // recursively update transition hooks on subTree600            Vue.setTransitionHooks(vnode, vnode.transition);601          }602          // avoid vnode being mounted as fresh603          vnode.shapeFlag |= ShapeFlags.COMPONENT_KEPT_ALIVE;604          // make this key the freshest605          keys.delete(key);606          keys.add(key);607        } else {608          keys.add(key);609          // prune oldest entry610          if (max && keys.size > parseInt(max, 10)) {611            pruneCacheEntry(keys.values().next().value);612          }613        }614        // avoid vnode being unmounted615        vnode.shapeFlag |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;616  617        current = vnode;618        return rawVNode619      }620    }621  };622  623  const StackKeepAlive = StackKeepAliveImpl;624  625  function matches(pattern, name){626    if (shared.isArray(pattern)) {627      return pattern.some((p) => matches(p, name))628    } else if (shared.isString(pattern)) {629      return pattern.split(',').includes(name)630    } else if (pattern.test) {631      return pattern.test(name)632    }633    /* istanbul ignore next */634    return false635  }636  637  function resetShapeFlag(vnode) {638    let shapeFlag = vnode.shapeFlag;639    if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {640      shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;641    }642    if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {643      shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE;644    }645    vnode.shapeFlag = shapeFlag;646  }647  648  function getInnerChild(vnode) {649    return vnode.shapeFlag & ShapeFlags.SUSPENSE ? vnode.ssContent : vnode650  }651var components = { StackKeepAlive };...library.mjs
Source:library.mjs  
...447      };448  449      function unmount(vnode) {450        // reset the shapeFlag so it can be properly unmounted451        resetShapeFlag(vnode);452        _unmount(vnode, instance, parentSuspense, true);453      }454  455      function pruneCache(filter) {456        cache.forEach((vnode, key) => {457          const name = getComponentName(vnode.type);458          if (name && (!filter || !filter(name))) {459            pruneCacheEntry(key);460          }461        });462      }463  464      function pruneCacheEntry(key) {465        const cached = cache.get(key);466        if (!current || cached.type !== current.type) {467          unmount(cached);468        } else if (current) {469          // current active instance should no longer be kept-alive.470          // we can't unmount it now but it might be later, so reset its flag now.471          resetShapeFlag(current);472        }473        cache.delete(key);474        keys.delete(key);475      }476  477      // core478      let router;479      {480        router = VueRouter.useRouter();481      }482      if (!router) {483        throw new Error("router is not found! In unit test mode ,router is got from gloabl.router, otherwise VueRouter.useRouter()")484      }485      const _core = new Core({ router, pruneCacheEntry, replaceStay: props.replaceStay });486      {487        window.__core = _core;488      }489      // prune cache on include/exclude prop change490      watch(491        () => [props.include, props.exclude],492        ([include, exclude]) => {493          include && pruneCache(name => matches(include, name));494          exclude && pruneCache(name => !matches(exclude, name));495        },496        // prune post-render after `current` has been updated497        { flush: 'post', deep: true }498      );499  500      // cache sub tree after render501      let pendingCacheKey = null;502      const cacheSubtree = () => {503        // fix #1621, the pendingCacheKey could be 0504        if (pendingCacheKey != null) {505          cache.set(pendingCacheKey, getInnerChild(instance.subTree));506        }507      };508      onMounted(cacheSubtree);509      onUpdated(cacheSubtree);510  511      onBeforeUnmount(() => {512        cache.forEach(cached => {513          const { subTree, suspense } = instance;514          const vnode = getInnerChild(subTree);515          if (cached.type === vnode.type) {516            // current instance will be unmounted as part of keep-alive's unmount517            resetShapeFlag(vnode);518            // but invoke its deactivated hook here519            const da = vnode.component.da;520            da && queuePostRenderEffect(da, suspense);521            return522          }523          unmount(cached);524        });525      });526  527      return () => {528        pendingCacheKey = null;529  530        if (!slots.default) {531          return null532        }533        // generate a specific key for every vnode534        const _key = _core.genKeyForVnode();535        536        const children = slots.default({'key': _key});537        const rawVNode = children[0];538        if (children.length > 1) {539          {540            warn(`KeepAlive should contain exactly one component child.`);541          }542          current = null;543          _core.genInitialKeyNextTime();544          return children545        } else if (546          !isVNode(rawVNode) ||547          (!(rawVNode.shapeFlag === ShapeFlags.STATEFUL_COMPONENT) &&548            !(rawVNode.shapeFlag === ShapeFlags.SUSPENSE))549        ) {550          _core.genInitialKeyNextTime();551          current = null;552          return rawVNode553        }554  555        let vnode = getInnerChild(rawVNode);556        const comp = vnode.type;557        // for async components, name check should be based in its loaded558        // inner component if available559        const name = getComponentName(560          isAsyncWrapper(vnode)561            ? (vnode.type).__asyncResolved || {}562            : comp563        );564  565        const { include, exclude, max } = props;566  567        if (568          (include && (!name || !matches(include, name))) ||569          (exclude && name && matches(exclude, name))570        ) {571          current = vnode;572          return rawVNode573        }574  575        const key = vnode.key == null ? comp : vnode.key;576        const cachedVNode = cache.get(key);577        // clone vnode if it's reused because we are going to mutate it578        if (vnode.el) {579          vnode = cloneVNode(vnode);580          if (rawVNode.shapeFlag & ShapeFlags.SUSPENSE) {581            rawVNode.ssContent = vnode;582          }583        }584        // #1513 it's possible for the returned vnode to be cloned due to attr585        // fallthrough or scopeId, so the vnode here may not be the final vnode586        // that is mounted. Instead of caching it directly, we store the pending587        // key and cache `instance.subTree` (the normalized vnode) in588        // beforeMount/beforeUpdate hooks.589        pendingCacheKey = key;590        if (cachedVNode) {591          // copy over mounted state592          vnode.el = cachedVNode.el;593          vnode.component = cachedVNode.component;594          595          if (vnode.transition) {596            // recursively update transition hooks on subTree597            setTransitionHooks(vnode, vnode.transition);598          }599          // avoid vnode being mounted as fresh600          vnode.shapeFlag |= ShapeFlags.COMPONENT_KEPT_ALIVE;601          // make this key the freshest602          keys.delete(key);603          keys.add(key);604        } else {605          keys.add(key);606          // prune oldest entry607          if (max && keys.size > parseInt(max, 10)) {608            pruneCacheEntry(keys.values().next().value);609          }610        }611        // avoid vnode being unmounted612        vnode.shapeFlag |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;613  614        current = vnode;615        return rawVNode616      }617    }618  };619  620  const StackKeepAlive = StackKeepAliveImpl;621  622  function matches(pattern, name){623    if (isArray(pattern)) {624      return pattern.some((p) => matches(p, name))625    } else if (isString(pattern)) {626      return pattern.split(',').includes(name)627    } else if (pattern.test) {628      return pattern.test(name)629    }630    /* istanbul ignore next */631    return false632  }633  634  function resetShapeFlag(vnode) {635    let shapeFlag = vnode.shapeFlag;636    if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {637      shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE;638    }639    if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {640      shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE;641    }642    vnode.shapeFlag = shapeFlag;643  }644  645  function getInnerChild(vnode) {646    return vnode.shapeFlag & ShapeFlags.SUSPENSE ? vnode.ssContent : vnode647  }648var components = { StackKeepAlive };...Navigation.js
Source:Navigation.js  
...127            }128        };129        function unmount(vnode) {130            // reset the shapeFlag so it can be properly unmounted131            resetShapeFlag(vnode);132            _unmount(vnode, instance, parentSuspense);133        }134        function pruneCache(filter) {135            cache.forEach((vnode, key) => {136                const name = getComponentName(vnode.type);137                if (name && (!filter || !filter(name))) {138                    pruneCacheEntry(key);139                }140            });141        }142        function pruneCacheEntry(key) {143            const cached = cache.get(key);144            if (!current || cached.type !== current.type) {145                unmount(cached);146            } else if (current) {147                // current active instance should no longer be kept-alive.148                // we can't unmount it now but it might be later, so reset its flag now.149                resetShapeFlag(current);150            }151            cache.delete(key);152            keys.delete(key);153        }154        // prune cache on include/exclude prop change155        watch(() => [props.include, props.exclude, selfRouters], ([include, exclude, selfRouters]) => {156                include && pruneCache(name => matches(include, name));157                exclude && pruneCache(name => !matches(exclude, name));158                // if not in self-maintained routers, it need to delete from cache159                for (const key of cache.keys()) {160                    !matches(selfRouters, key) && pruneCacheEntry(key)161                }162            },163            // prune post-render after `current` has been updated164            { flush: 'post', deep: true });165        // cache sub tree after render166        let pendingCacheKey = null;167        const cacheSubtree = () => {168            // fix #1621, the pendingCacheKey could be 0169            if (pendingCacheKey != null) {170                cache.set(pendingCacheKey, getInnerChild(instance.subTree));171            }172        };173        onMounted(cacheSubtree);174        onUpdated(cacheSubtree);175        onBeforeUnmount(() => {176            cache.forEach(cached => {177                const { subTree, suspense } = instance;178                const vnode = getInnerChild(subTree);179                if (cached.type === vnode.type) {180                    // current instance will be unmounted as part of keep-alive's unmount181                    resetShapeFlag(vnode);182                    // but invoke its deactivated hook here183                    const da = vnode.component.da;184                    da && queuePostRenderEffect(da, suspense);185                    return;186                }187                unmount(cached);188            });189        });190        return () => {191            pendingCacheKey = null;192            if (!slots.default) {193                return null;194            }195            const children = slots.default();...router-alive-ext.jsx
Source:router-alive-ext.jsx  
...112      }, parentSuspense)113    }114    function unmount(vnode) {115      // reset the shapeFlag so it can be properly unmounted116      resetShapeFlag(vnode)117      _unmount(vnode, instance, parentSuspense)118    }119    function pruneCache(filter) {120      cache.forEach((vnode, key) => { 121        const name = getComponentName(vnode.type, vnode.key)122        if (name && (!filter || !filter(name))) {123          pruneCacheEntry(key)124        }125      })126    }127    function pruneCacheEntry(key) {128      const cached = cache.get(key)129      // if (!current || cached.type !== current.type) {130      //   unmount(cached)131      // } else if (current) {132      //   resetShapeFlag(current)133      // }134      // å½tabåºåå卿¨¡å页é¢135      if (current){136        unmount(cached)137      }138      139      cache.delete(key)140      keys.delete(key)141    }142    watch(143      () => [props.include, props.exclude],144      ([include, exclude]) => {145        include && pruneCache(name => matches(include, name))146        exclude && pruneCache(name => !matches(exclude, name))147      },148      // prune post-render after `current` has been updated149      { flush: 'post', deep: true }150    )151    // cache sub tree after render152    let pendingCacheKey = null153    const cacheSubtree = () => {154      // fix #1621, the pendingCacheKey could be 0155      if (pendingCacheKey != null) {156        cache.set(pendingCacheKey, getInnerChild(instance.subTree))157      }158    }159    onMounted(cacheSubtree)160    onUpdated(cacheSubtree)161    onBeforeUnmount(() => {162      cache.forEach(cached => {163        const { subTree, suspense } = instance164        const vnode = getInnerChild(subTree)165        if (cached.type === vnode.type) {166          // current instance will be unmounted as part of keep-alive's unmount167          resetShapeFlag(vnode)168          // but invoke its deactivated hook here169          const da = vnode.component.da170          da && queuePostRenderEffect(da, suspense)171          return172        }173        unmount(cached)174      })175    })176    //render fn177    return () => {178      pendingCacheKey = null179      if (!slots.default) {180        return null181      }182      const children = slots.default()183      const rawVNode = children[0]184      if (children.length > 1) {185       current = null186        return children187      } else if (188        !isVNode(rawVNode) ||189        (!(rawVNode.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) &&190          !(rawVNode.shapeFlag & ShapeFlags.SUSPENSE))191      ) {192        current = null193        return rawVNode194      }195      let vnode = getInnerChild(rawVNode)196      const comp = vnode.type197      const name = getComponentName(comp, vnode.key)198      const { include, exclude, max } = props199      if (200        (include && (!name || !matches(include, name))) ||201        (exclude && name && matches(exclude, name))202      ) {203        current = vnode204        return rawVNode205      }206      const key = vnode.key == null ? comp : vnode.key207      const cachedVNode = cache.get(key)208      if (vnode.el) {209        vnode = cloneVNode(vnode)210        if (rawVNode.shapeFlag & ShapeFlags.SUSPENSE) {211          rawVNode.ssContent = vnode212        }213      }214    215      pendingCacheKey = key216      if (cachedVNode) {217        vnode.el = cachedVNode.el218        vnode.component = cachedVNode.component219        if (vnode.transition) {220          setTransitionHooks(vnode, vnode.transition)221        }222        vnode.shapeFlag |= ShapeFlags.COMPONENT_KEPT_ALIVE223        keys.delete(key)224        keys.add(key)225      } else {226        keys.add(key)227        if (max && keys.size > parseInt(max, 10)) {228          pruneCacheEntry(keys.values().next().value)229        }230      }231      vnode.shapeFlag |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE232      current = vnode233      return rawVNode234    }235  }236}237function isFunction(val){238  return typeof val === 'function'239}240function getComponentName(241  Component,242  key243){244  if (key){245    return key246  }247  return isFunction(Component)248    ? Component.displayName || Component.name249    : Component.name250}251function resetShapeFlag(vnode) {252  let shapeFlag = vnode.shapeFlag253  if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {254    shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE255  }256  if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {257    shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE258  }259  vnode.shapeFlag = shapeFlag260}261function getInnerChild(vnode) {262  return vnode.shapeFlag & ShapeFlags.SUSPENSE ? vnode.ssContent : vnode263}264function matches(pattern, name) {265  if (isArray(pattern)) {...KeepAlive.js
Source:KeepAlive.js  
...68        instance.isDeactivated = true69      }, parentSuspense)70    }71    function unmount (vnode) {72      resetShapeFlag(vnode)73      _unmount(vnode, instance, parentSuspense, true)74    }75    function pruneCache (filter) {76      cache.forEach((vnode, key) => {77        const name = getComponentName(vnode.type)78        if (name && (!filter || !filter(name))) {79          pruneCacheEntry(key)80        }81      })82    }83    function pruneCacheEntry (key) {84      const cached = cache.get(key)85      if (!current || cached.type !== current.type) {86        unmount(cached)87      } else if (current) {88        resetShapeFlag(current)89      }90      cache.delete(key)91      keys.delete(key)92    }93    watch(94      () => [props.include, props.exclude],95      ([include, exclude]) => {96        include && pruneCache(name => matches(include, name))97        exclude && pruneCache(name => !matches(exclude, name))98      },99      { flush: 'post', deep: true }100    )101    let pendingCacheKey = null102    const cacheSubtree = () => {103      if (pendingCacheKey != null) {104        cache.set(pendingCacheKey, getInnerChild(instance.subTree))105      }106    }107    onMounted(cacheSubtree)108    onUpdated(cacheSubtree)109    onBeforeUnmount(() => {110      cache.forEach(cached => {111        const { subTree, suspense } = instance112        const vnode = getInnerChild(subTree)113        if (cached.type === vnode.type) {114          resetShapeFlag(vnode)115          const da = vnode.component.da116          da && queuePostRenderEffect(da, suspense)117          return118        }119        unmount(cached)120      })121    })122    return () => {123      pendingCacheKey = null124      if (!slots.default) {125        return null126      }127      const children = slots.default()128      const rawVNode = children[0]...util.js
Source:util.js  
...99    }100    return true101  }102}103export function resetShapeFlag(vnode) {104  let shapeFlag = vnode.shapeFlag;105  if (shapeFlag & 256 /* COMPONENT_SHOULD_KEEP_ALIVE */) {106    shapeFlag -= 256 /* COMPONENT_SHOULD_KEEP_ALIVE */;107  }108  if (shapeFlag & 512 /* COMPONENT_KEPT_ALIVE */) {109    shapeFlag -= 512 /* COMPONENT_KEPT_ALIVE */;110  }111  vnode.shapeFlag = shapeFlag;112}113export function matches(pattern, name) {114  if (isArray(pattern)) {115    return pattern.some((p) => matches(p, name));116  }117  else if (isString(pattern)) {...Using AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/server/chromium/crPage');2const { chromium } = require('playwright');3(async () => {4  const browser = await chromium.launch();5  const context = await browser.newContext();6  const page = await context.newPage();7  await page.screenshot({ path: 'google.png' });8  await page.evaluate(resetShapeFlag);9  await page.screenshot({ path: 'google2.png' });10  await browser.close();11})();12const { resetShapeFlag } = require('playwright/lib/server/chromium/crPage');13const { chromium } = require('playwright');14(async () => {15  const browser = await chromium.launch();16  const context = await browser.newContext();17  const page = await context.newPage();18  await page.screenshot({ path: 'google.png' });19  await page.evaluate(resetShapeFlag);20  await page.screenshot({ path: 'google2.png' });21  await browser.close();22})();23const { resetShapeFlag } = require('playwright/lib/server/chromium/crPage');24const { chromium } = require('playwright');25(async () => {26  const browser = await chromium.launch();27  const context = await browser.newContext();28  const page = await context.newPage();29  await page.screenshot({ path: 'google.png' });30  await page.evaluate(resetShapeFlag);31  await page.screenshot({ path: 'google2.png' });32  await browser.close();33})();34const { resetShapeFlag } = require('playwright/lib/server/chromium/crPage');35const { chromium } = require('playwright');36(async () => {37  const browser = await chromium.launch();38  const context = await browser.newContext();39  const page = await context.newPage();40  await page.screenshot({ path: 'google.png' });41  await page.evaluate(resetShapeFlag);42  await page.screenshot({Using AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/webkit/webkit');2resetShapeFlag();3const { resetShapeFlag } = require('playwright/lib/chromium/chromium');4resetShapeFlag();5const { resetShapeFlag } = require('playwright/lib/firefox/firefox');6resetShapeFlag();7const { resetShapeFlag } = require('playwright/lib/server/server');8resetShapeFlag();9const { resetShapeFlag } = require('playwright/lib/android/android');10resetShapeFlag();11const { resetShapeFlag } = require('playwright/lib/ios/ios');12resetShapeFlag();13const { resetShapeFlag } = require('playwright/lib/electron/electron');14resetShapeFlag();15const { resetShapeFlag } = require('playwright/lib/driver/driver');16resetShapeFlag();17const { resetShapeFlag } = require('playwright/lib/transport/transport');18resetShapeFlag();19const { resetShapeFlag } = require('playwright/lib/utils/utils');20resetShapeFlag();21const { resetShapeFlag } = require('playwright/lib/protocol/protocol');22resetShapeFlag();23const { resetShapeFlag } = require('playwright/lib/helper/helper');24resetShapeFlag();25const { resetShapeFlag } = require('playwright/lib/api/api');26resetShapeFlag();27const { resetShapeFlag } = require('playwright/lib/trace/trace');28resetShapeFlag();29const { resetShapeFlag } = require('playwright/lib/locator/locator');Using AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');2resetShapeFlag();3const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');4resetShapeFlag();5const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');6resetShapeFlag();7const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');8resetShapeFlag();9const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');10resetShapeFlag();11const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');12resetShapeFlag();13const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');14resetShapeFlag();15const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');16resetShapeFlag();17const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');18resetShapeFlag();19const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');20resetShapeFlag();21const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');22resetShapeFlag();23const { resetShapeFlagUsing AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/server/trace/recorder/recorderApp');2const { test } = require('@playwright/test');3test('test', async ({page}) => {4  await page.click('text=Get Started');5  await page.click('text=Docs');6  await page.click('text=API');7  await page.click('text=Class: Page');Using AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/server/trace/recorder/recorderApp');2resetShapeFlag();3const { recordTrace } = require('playwright/lib/server/trace/recorder/recorderApp');4recordTrace();5const { stopRecordingTrace } = require('playwright/lib/server/trace/recorder/recorderApp');6stopRecordingTrace();7const { setTraceFileName } = require('playwright/lib/server/trace/recorder/recorderApp');8setTraceFileName('custom-trace-file-name');9const { setTraceFilePath } = require('playwright/lib/server/trace/recorder/recorderApp');10setTraceFilePath('custom-trace-file-path');11const { setTraceFileNameAndPath } = require('playwright/lib/server/trace/recorder/recorderApp');12setTraceFileNameAndPath('custom-trace-file-name', 'custom-trace-file-path');Using AI Code Generation
1const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');2resetShapeFlag();3const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');4resetShapeFlag();5const { chromium } = require('playwright');6(async () => {7  const browser = await chromium.launch();8  const context = await browser.newContext();9  const page = await context.newPage();10  await page.click('text=Get Started');11  await page.click('text=Docs');12  await browser.close();13})();14const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');15resetShapeFlag();16const { test, expect } = require('@playwright/test');17test('My test', async ({ page }) => {18  await page.click('text=Get Started');19  await page.click('text=Docs');20});21const { resetShapeFlag } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');22resetShapeFlag();23const { chromium } = require('playwright');24(async () => {25  const browser = await chromium.launch();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!!
