Best JavaScript code snippet using playwright-internal
patch.js
Source:patch.js
...160 const appendAsTree = isDef(data) && isTrue(data.appendAsTree)161 if (!appendAsTree) {162 if (isDef(data)) {163 //æ¥çåè°ç¨ invokeCreateHooks æ¹æ³æ§è¡ææç create çé©å并æ vnode push å° insertedVnodeQueue ä¸ã164 invokeCreateHooks(vnode, insertedVnodeQueue)165 }166 insert(parentElm, vnode.elm, refElm)167 }168 createChildren(vnode, children, insertedVnodeQueue)169 if (appendAsTree) {170 if (isDef(data)) {171 //æ¥çåè°ç¨ invokeCreateHooks æ¹æ³æ§è¡ææç create çé©å并æ vnode push å° insertedVnodeQueue ä¸ã172 invokeCreateHooks(vnode, insertedVnodeQueue)173 }174 insert(parentElm, vnode.elm, refElm)175 }176 } else {177 createChildren(vnode, children, insertedVnodeQueue)178 if (isDef(data)) {179 //æ¥çåè°ç¨ invokeCreateHooks æ¹æ³æ§è¡ææç create çé©å并æ vnode push å° insertedVnodeQueue ä¸ã180 invokeCreateHooks(vnode, insertedVnodeQueue)181 }182 insert(parentElm, vnode.elm, refElm)183 }184 if (process.env.NODE_ENV !== 'production' && data && data.pre) {185 creatingElmInVPre--186 }187 } else if (isTrue(vnode.isComment)) {188 vnode.elm = nodeOps.createComment(vnode.text)189 insert(parentElm, vnode.elm, refElm)190 } else {191 vnode.elm = nodeOps.createTextNode(vnode.text)192 insert(parentElm, vnode.elm, refElm)193 }194 }195 //createComponent æ¹æ³ç®çæ¯å°è¯å建åç»ä»¶196 function createComponent (vnode, insertedVnodeQueue, parentElm, refElm) {197 let i = vnode.data198 if (isDef(i)) {199 const isReactivated = isDef(vnode.componentInstance) && i.keepAlive200 if (isDef(i = i.hook) && isDef(i = i.init)) {201 i(vnode, false /* hydrating */)202 }203 // after calling the init hook, if the vnode is a child component204 // it should've created a child instance and mounted it. the child205 // component also has set the placeholder vnode's elm.206 // in that case we can just return the element and be done.207 if (isDef(vnode.componentInstance)) {208 initComponent(vnode, insertedVnodeQueue)209 insert(parentElm, vnode.elm, refElm)210 if (isTrue(isReactivated)) {211 reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm)212 }213 return true214 }215 }216 }217 function initComponent (vnode, insertedVnodeQueue) {218 if (isDef(vnode.data.pendingInsert)) {219 insertedVnodeQueue.push.apply(insertedVnodeQueue, vnode.data.pendingInsert)220 vnode.data.pendingInsert = null221 }222 vnode.elm = vnode.componentInstance.$el223 if (isPatchable(vnode)) {224 //æ¥çåè°ç¨ invokeCreateHooks æ¹æ³æ§è¡ææç create çé©å并æ vnode push å° insertedVnodeQueue ä¸ã225 invokeCreateHooks(vnode, insertedVnodeQueue)226 setScope(vnode)227 } else {228 // empty component root.229 // skip all element-related modules except for ref (#3455)230 registerRef(vnode)231 // make sure to invoke the insert hook232 insertedVnodeQueue.push(vnode)233 }234 }235 function reactivateComponent (vnode, insertedVnodeQueue, parentElm, refElm) {236 let i237 // hack for #4339: a reactivated component with inner transition238 // does not trigger because the inner node's created hooks are not called239 // again. It's not ideal to involve module-specific logic in here but240 // there doesn't seem to be a better way to do it.241 let innerNode = vnode242 while (innerNode.componentInstance) {243 innerNode = innerNode.componentInstance._vnode244 if (isDef(i = innerNode.data) && isDef(i = i.transition)) {245 for (i = 0; i < cbs.activate.length; ++i) {246 cbs.activate[i](emptyNode, innerNode)247 }248 insertedVnodeQueue.push(innerNode)249 break250 }251 }252 // unlike a newly created component,253 // a reactivated keep-alive component doesn't insert itself254 insert(parentElm, vnode.elm, refElm)255 }256 function insert (parent, elm, ref) {257 if (isDef(parent)) {258 if (isDef(ref)) {259 if (nodeOps.parentNode(ref) === parent) {260 nodeOps.insertBefore(parent, elm, ref)261 }262 } else {263 nodeOps.appendChild(parent, elm)264 }265 }266 }267 //createChildren çé»è¾å¾ç®åï¼å®é
ä¸æ¯éååèæèç¹ï¼268 //éå½è°ç¨ createElmï¼è¿æ¯ä¸ç§å¸¸ç¨ç深度ä¼å
çéåç®æ³ï¼269 //è¿éè¦æ³¨æçä¸ç¹æ¯å¨éåè¿ç¨ä¸ä¼æ vnode.elm ä½ä¸ºç¶å®¹å¨ç DOM èç¹å ä½ç¬¦ä¼ å
¥ã270 function createChildren (vnode, children, insertedVnodeQueue) {271 if (Array.isArray(children)) {272 if (process.env.NODE_ENV !== 'production') {273 checkDuplicateKeys(children)274 }275 for (let i = 0; i < children.length; ++i) {276 createElm(children[i], insertedVnodeQueue, vnode.elm, null, true, children, i)277 }278 } else if (isPrimitive(vnode.text)) {279 nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(String(vnode.text)))280 }281 }282 function isPatchable (vnode) {283 while (vnode.componentInstance) {284 vnode = vnode.componentInstance._vnode285 }286 return isDef(vnode.tag)287 }288 function invokeCreateHooks (vnode, insertedVnodeQueue) {289 for (let i = 0; i < cbs.create.length; ++i) {290 cbs.create[i](emptyNode, vnode)291 }292 i = vnode.data.hook // Reuse variable293 if (isDef(i)) {294 if (isDef(i.create)) i.create(emptyNode, vnode)295 //æåè°ç¨ insert æ¹æ³æ DOM æå
¥å°ç¶èç¹ä¸ï¼å 为æ¯éå½è°ç¨ï¼296 //åå
ç´ ä¼ä¼å
è°ç¨ insertï¼æ以æ´ä¸ª vnode æ èç¹çæå
¥é¡ºåºæ¯å
ååç¶ã297 //æ¥çä¸ä¸ insert æ¹æ³ï¼å®çå®ä¹å¨ src/core/vdom/patch.js ä¸ã298 if (isDef(i.insert)) insertedVnodeQueue.push(vnode)299 }300 }301 // set scope id attribute for scoped CSS.302 // this is implemented as a special case to avoid the overhead303 // of going through the normal attribute patching process.304 function setScope (vnode) {305 let i306 if (isDef(i = vnode.fnScopeId)) {307 nodeOps.setStyleScope(vnode.elm, i)308 } else {309 let ancestor = vnode310 while (ancestor) {311 if (isDef(i = ancestor.context) && isDef(i = i.$options._scopeId)) {312 nodeOps.setStyleScope(vnode.elm, i)313 }314 ancestor = ancestor.parent315 }316 }317 // for slot content they should also get the scopeId from the host instance.318 if (isDef(i = activeInstance) &&319 i !== vnode.context &&320 i !== vnode.fnContext &&321 isDef(i = i.$options._scopeId)322 ) {323 nodeOps.setStyleScope(vnode.elm, i)324 }325 }326 function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx, insertedVnodeQueue) {327 for (; startIdx <= endIdx; ++startIdx) {328 createElm(vnodes[startIdx], insertedVnodeQueue, parentElm, refElm, false, vnodes, startIdx)329 }330 }331 function invokeDestroyHook (vnode) {332 let i, j333 const data = vnode.data334 if (isDef(data)) {335 if (isDef(i = data.hook) && isDef(i = i.destroy)) i(vnode)336 for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)337 }338 if (isDef(i = vnode.children)) {339 for (j = 0; j < vnode.children.length; ++j) {340 invokeDestroyHook(vnode.children[j])341 }342 }343 }344 function removeVnodes (parentElm, vnodes, startIdx, endIdx) {345 for (; startIdx <= endIdx; ++startIdx) {346 const ch = vnodes[startIdx]347 if (isDef(ch)) {348 if (isDef(ch.tag)) {349 removeAndInvokeRemoveHook(ch)350 invokeDestroyHook(ch)351 } else { // Text node352 removeNode(ch.elm)353 }354 }355 }356 }357 function removeAndInvokeRemoveHook (vnode, rm) {358 if (isDef(rm) || isDef(vnode.data)) {359 let i360 const listeners = cbs.remove.length + 1361 if (isDef(rm)) {362 // we have a recursively passed down rm callback363 // increase the listeners count364 rm.listeners += listeners365 } else {366 // directly removing367 rm = createRmCb(vnode.elm, listeners)368 }369 // recursively invoke hooks on child component root node370 if (isDef(i = vnode.componentInstance) && isDef(i = i._vnode) && isDef(i.data)) {371 removeAndInvokeRemoveHook(i, rm)372 }373 for (i = 0; i < cbs.remove.length; ++i) {374 cbs.remove[i](vnode, rm)375 }376 if (isDef(i = vnode.data.hook) && isDef(i = i.remove)) {377 i(vnode, rm)378 } else {379 rm()380 }381 } else {382 removeNode(vnode.elm)383 }384 }385 function updateChildren (parentElm, oldCh, newCh, insertedVnodeQueue, removeOnly) {386 let oldStartIdx = 0387 let newStartIdx = 0388 let oldEndIdx = oldCh.length - 1389 let oldStartVnode = oldCh[0]390 let oldEndVnode = oldCh[oldEndIdx]391 let newEndIdx = newCh.length - 1392 let newStartVnode = newCh[0]393 let newEndVnode = newCh[newEndIdx]394 let oldKeyToIdx, idxInOld, vnodeToMove, refElm395 // removeOnly is a special flag used only by <transition-group>396 // to ensure removed elements stay in correct relative positions397 // during leaving transitions398 const canMove = !removeOnly399 if (process.env.NODE_ENV !== 'production') {400 checkDuplicateKeys(newCh)401 }402 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {403 if (isUndef(oldStartVnode)) {404 oldStartVnode = oldCh[++oldStartIdx] // Vnode has been moved left405 } else if (isUndef(oldEndVnode)) {406 oldEndVnode = oldCh[--oldEndIdx]407 } else if (sameVnode(oldStartVnode, newStartVnode)) {408 patchVnode(oldStartVnode, newStartVnode, insertedVnodeQueue)409 oldStartVnode = oldCh[++oldStartIdx]410 newStartVnode = newCh[++newStartIdx]411 } else if (sameVnode(oldEndVnode, newEndVnode)) {412 patchVnode(oldEndVnode, newEndVnode, insertedVnodeQueue)413 oldEndVnode = oldCh[--oldEndIdx]414 newEndVnode = newCh[--newEndIdx]415 } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right416 patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue)417 canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm))418 oldStartVnode = oldCh[++oldStartIdx]419 newEndVnode = newCh[--newEndIdx]420 } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left421 patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue)422 canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)423 oldEndVnode = oldCh[--oldEndIdx]424 newStartVnode = newCh[++newStartIdx]425 } else {426 if (isUndef(oldKeyToIdx)) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx)427 idxInOld = isDef(newStartVnode.key)428 ? oldKeyToIdx[newStartVnode.key]429 : findIdxInOld(newStartVnode, oldCh, oldStartIdx, oldEndIdx)430 if (isUndef(idxInOld)) { // New element431 createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm, false, newCh, newStartIdx)432 } else {433 vnodeToMove = oldCh[idxInOld]434 if (sameVnode(vnodeToMove, newStartVnode)) {435 patchVnode(vnodeToMove, newStartVnode, insertedVnodeQueue)436 oldCh[idxInOld] = undefined437 canMove && nodeOps.insertBefore(parentElm, vnodeToMove.elm, oldStartVnode.elm)438 } else {439 // same key but different element. treat as new element440 createElm(newStartVnode, insertedVnodeQueue, parentElm, oldStartVnode.elm, false, newCh, newStartIdx)441 }442 }443 newStartVnode = newCh[++newStartIdx]444 }445 }446 if (oldStartIdx > oldEndIdx) {447 refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm448 addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx, insertedVnodeQueue)449 } else if (newStartIdx > newEndIdx) {450 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx)451 }452 }453 function checkDuplicateKeys (children) {454 const seenKeys = {}455 for (let i = 0; i < children.length; i++) {456 const vnode = children[i]457 const key = vnode.key458 if (isDef(key)) {459 if (seenKeys[key]) {460 warn(461 `Duplicate keys detected: '${key}'. This may cause an update error.`,462 vnode.context463 )464 } else {465 seenKeys[key] = true466 }467 }468 }469 }470 function findIdxInOld (node, oldCh, start, end) {471 for (let i = start; i < end; i++) {472 const c = oldCh[i]473 if (isDef(c) && sameVnode(node, c)) return i474 }475 }476 function patchVnode (oldVnode, vnode, insertedVnodeQueue, removeOnly) {477 if (oldVnode === vnode) {478 return479 }480 const elm = vnode.elm = oldVnode.elm481 if (isTrue(oldVnode.isAsyncPlaceholder)) {482 if (isDef(vnode.asyncFactory.resolved)) {483 hydrate(oldVnode.elm, vnode, insertedVnodeQueue)484 } else {485 vnode.isAsyncPlaceholder = true486 }487 return488 }489 // reuse element for static trees.490 // note we only do this if the vnode is cloned -491 // if the new node is not cloned it means the render functions have been492 // reset by the hot-reload-api and we need to do a proper re-render.493 if (isTrue(vnode.isStatic) &&494 isTrue(oldVnode.isStatic) &&495 vnode.key === oldVnode.key &&496 (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))497 ) {498 vnode.componentInstance = oldVnode.componentInstance499 return500 }501 let i502 const data = vnode.data503 if (isDef(data) && isDef(i = data.hook) && isDef(i = i.prepatch)) {504 i(oldVnode, vnode)505 }506 const oldCh = oldVnode.children507 const ch = vnode.children508 if (isDef(data) && isPatchable(vnode)) {509 for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)510 if (isDef(i = data.hook) && isDef(i = i.update)) i(oldVnode, vnode)511 }512 if (isUndef(vnode.text)) {513 if (isDef(oldCh) && isDef(ch)) {514 if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)515 } else if (isDef(ch)) {516 if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')517 addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)518 } else if (isDef(oldCh)) {519 removeVnodes(elm, oldCh, 0, oldCh.length - 1)520 } else if (isDef(oldVnode.text)) {521 nodeOps.setTextContent(elm, '')522 }523 } else if (oldVnode.text !== vnode.text) {524 nodeOps.setTextContent(elm, vnode.text)525 }526 if (isDef(data)) {527 if (isDef(i = data.hook) && isDef(i = i.postpatch)) i(oldVnode, vnode)528 }529 }530 function invokeInsertHook (vnode, queue, initial) {531 // delay insert hooks for component root nodes, invoke them after the532 // element is really inserted533 if (isTrue(initial) && isDef(vnode.parent)) {534 vnode.parent.data.pendingInsert = queue535 } else {536 for (let i = 0; i < queue.length; ++i) {537 queue[i].data.hook.insert(queue[i])538 }539 }540 }541 let hydrationBailed = false542 // list of modules that can skip create hook during hydration because they543 // are already rendered on the client or has no need for initialization544 // Note: style is excluded because it relies on initial clone for future545 // deep updates (#7063).546 const isRenderedModule = makeMap('attrs,class,staticClass,staticStyle,key')547 // Note: this is a browser-only function so we can assume elms are DOM nodes.548 function hydrate (elm, vnode, insertedVnodeQueue, inVPre) {549 let i550 const { tag, data, children } = vnode551 inVPre = inVPre || (data && data.pre)552 vnode.elm = elm553 if (isTrue(vnode.isComment) && isDef(vnode.asyncFactory)) {554 vnode.isAsyncPlaceholder = true555 return true556 }557 // assert node match558 if (process.env.NODE_ENV !== 'production') {559 if (!assertNodeMatch(elm, vnode, inVPre)) {560 return false561 }562 }563 if (isDef(data)) {564 if (isDef(i = data.hook) && isDef(i = i.init)) i(vnode, true /* hydrating */)565 if (isDef(i = vnode.componentInstance)) {566 // child component. it should have hydrated its own tree.567 initComponent(vnode, insertedVnodeQueue)568 return true569 }570 }571 if (isDef(tag)) {572 if (isDef(children)) {573 // empty element, allow client to pick up and populate children574 if (!elm.hasChildNodes()) {575 //æ¥ä¸æ¥è°ç¨ createChildren æ¹æ³å»å建åå
ç´ ï¼576 createChildren(vnode, children, insertedVnodeQueue)577 } else {578 // v-html and domProps: innerHTML579 if (isDef(i = data) && isDef(i = i.domProps) && isDef(i = i.innerHTML)) {580 if (i !== elm.innerHTML) {581 /* istanbul ignore if */582 if (process.env.NODE_ENV !== 'production' &&583 typeof console !== 'undefined' &&584 !hydrationBailed585 ) {586 hydrationBailed = true587 console.warn('Parent: ', elm)588 console.warn('server innerHTML: ', i)589 console.warn('client innerHTML: ', elm.innerHTML)590 }591 return false592 }593 } else {594 // iterate and compare children lists595 let childrenMatch = true596 let childNode = elm.firstChild597 for (let i = 0; i < children.length; i++) {598 if (!childNode || !hydrate(childNode, children[i], insertedVnodeQueue, inVPre)) {599 childrenMatch = false600 break601 }602 childNode = childNode.nextSibling603 }604 // if childNode is not null, it means the actual childNodes list is605 // longer than the virtual children list.606 if (!childrenMatch || childNode) {607 /* istanbul ignore if */608 if (process.env.NODE_ENV !== 'production' &&609 typeof console !== 'undefined' &&610 !hydrationBailed611 ) {612 hydrationBailed = true613 console.warn('Parent: ', elm)614 console.warn('Mismatching childNodes vs. VNodes: ', elm.childNodes, children)615 }616 return false617 }618 }619 }620 }621 if (isDef(data)) {622 let fullInvoke = false623 for (const key in data) {624 if (!isRenderedModule(key)) {625 fullInvoke = true626 //æ¥çåè°ç¨ invokeCreateHooks æ¹æ³æ§è¡ææç create çé©å并æ vnode push å° insertedVnodeQueue ä¸ã627 invokeCreateHooks(vnode, insertedVnodeQueue)628 break629 }630 }631 if (!fullInvoke && data['class']) {632 // ensure collecting deps for deep class bindings for future updates633 traverse(data['class'])634 }635 }636 } else if (elm.data !== vnode.text) {637 elm.data = vnode.text638 }639 return true640 }641 function assertNodeMatch (node, vnode, inVPre) {...
5-client-hydrating.js
Source:5-client-hydrating.js
...168 for (var key in data) {169 if (!isRenderedModule(key)) {170 fullInvoke = true;171 // ç»ä»¶çå±æ§äºä»¶å¦ä½æ å°å°çå®ç DOM å
ç´ ï¼å°±æ¯æ¤å½æ°æ§è¡ã172 invokeCreateHooks(vnode, insertedVnodeQueue);173 break174 }175 }176 if (!fullInvoke && data['class']) {177 // ensure collecting deps for deep class bindings for future updates178 traverse(data['class']);179 }180 }181 } else if (elm.data !== vnode.text) {182 elm.data = vnode.text;183 }184 return true185}186// æè¨ç¡®å® vnode æ¯ä¸ä¸ªç»ä»¶èç¹æä¸node ä¸æ ·çèç¹ç±»å187function assertNodeMatch (node, vnode, inVPre) {188 if (isDef(vnode.tag)) {189 return vnode.tag.indexOf('vue-component') === 0 || (190 !isUnknownElement$$1(vnode, inVPre) &&191 vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase())192 )193 } else {194 return node.nodeType === (vnode.isComment ? 8 : 3)195 }196}197/**198 * createElm å½æ°å¨å®¢æ·ç«¯æ¸²ææ¶ä½¿ç¨ï¼ä¸»è¦æ§è¡ä»¥ä¸ä¸¤æ¥æä½ï¼199 * 1. æ§è¡æ§ oldVnode åæ° Vnode å¯¹æ¯ patch / patchVnodeï¼å®æå±æ§çæ°æ®å°çå® DOMä¸ï¼ä¸»è¦ç± invokeCreateHooks å½æ°å®æ200 * 2. ä½¿ç¨ node ä¸ç¸å
³ API è¿è¡æå
¥å°çå®ç DOM ä¸ï¼æ¾å¨ nodeOps 对象ä¸201 */ 202function createElm (203 vnode,204 insertedVnodeQueue,205 parentElm,206 refElm,207 nested,208 ownerArray,209 index210) {211 if (isDef(vnode.elm) && isDef(ownerArray)) {212 // This vnode was used in a previous render!213 // now it's used as a new node, overwriting its elm would cause214 // potential patch errors down the road when it's used as an insertion215 // reference node. Instead, we clone the node on-demand before creating216 // associated DOM element for it.217 vnode = ownerArray[index] = cloneVNode(vnode);218 }219 vnode.isRootInsert = !nested; // for transition enter check220 // createElm æ 论ææ ·é½å°è¯å½æç»ä»¶å建ï¼è§å¯æ¯å¦æåã221 // å¦æå½åèç¹ vnode ä¸è½ä½ä¸ºç»ä»¶å建è¿å falseï¼å³å¾ä¸ç»§æ¿æ§è¡222 // å¦æå½åèç¹æ¯ç»ä»¶ vnode åæ§è¡ç»ä»¶å®ä¾åï¼å¹¶è¿å trueï¼å½åå½æ°éåº223 if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {224 return225 }226 var data = vnode.data;227 var children = vnode.children;228 var tag = vnode.tag;229 if (isDef(tag)) {230 {231 if (data && data.pre) {232 creatingElmInVPre++;233 }234 if (isUnknownElement$$1(vnode, creatingElmInVPre)) {235 warn(236 'Unknown custom element: <' + tag + '> - did you ' +237 'register the component correctly? For recursive components, ' +238 'make sure to provide the "name" option.',239 vnode.context240 );241 }242 }243 vnode.elm = vnode.ns244 ? nodeOps.createElementNS(vnode.ns, tag)245 : nodeOps.createElement(tag, vnode);246 setScope(vnode);247 /* istanbul ignore if */248 {249 createChildren(vnode, children, insertedVnodeQueue);250 if (isDef(data)) {251 invokeCreateHooks(vnode, insertedVnodeQueue);252 }253 insert(parentElm, vnode.elm, refElm);254 }255 if (data && data.pre) {256 creatingElmInVPre--;257 }258 } else if (isTrue(vnode.isComment)) {259 vnode.elm = nodeOps.createComment(vnode.text);260 insert(parentElm, vnode.elm, refElm);261 } else {262 vnode.elm = nodeOps.createTextNode(vnode.text);263 insert(parentElm, vnode.elm, refElm);264 }265}...
vue-server-renderer-client-hydrating.js
Source:vue-server-renderer-client-hydrating.js
...168 for (var key in data) {169 if (!isRenderedModule(key)) {170 fullInvoke = true;171 // ç»ä»¶çå±æ§äºä»¶å¦ä½æ å°å°çå®ç DOM å
ç´ ï¼å°±æ¯æ¤å½æ°æ§è¡ã172 invokeCreateHooks(vnode, insertedVnodeQueue);173 break174 }175 }176 if (!fullInvoke && data['class']) {177 // ensure collecting deps for deep class bindings for future updates178 traverse(data['class']);179 }180 }181 } else if (elm.data !== vnode.text) {182 elm.data = vnode.text;183 }184 return true185}186// æè¨ç¡®å® vnode æ¯ä¸ä¸ªç»ä»¶èç¹æä¸node ä¸æ ·çèç¹ç±»å187function assertNodeMatch (node, vnode, inVPre) {188 if (isDef(vnode.tag)) {189 return vnode.tag.indexOf('vue-component') === 0 || (190 !isUnknownElement$$1(vnode, inVPre) &&191 vnode.tag.toLowerCase() === (node.tagName && node.tagName.toLowerCase())192 )193 } else {194 return node.nodeType === (vnode.isComment ? 8 : 3)195 }196}197/**198 * createElm å½æ°å¨å®¢æ·ç«¯æ¸²ææ¶ä½¿ç¨ï¼ä¸»è¦æ§è¡ä»¥ä¸ä¸¤æ¥æä½ï¼199 * 1. æ§è¡æ§ oldVnode åæ° Vnode å¯¹æ¯ patch / patchVnodeï¼å®æå±æ§çæ°æ®å°çå® DOMä¸ï¼ä¸»è¦ç± invokeCreateHooks å½æ°å®æ200 * 2. ä½¿ç¨ node ä¸ç¸å
³ API è¿è¡æå
¥å°çå®ç DOM ä¸ï¼æ¾å¨ nodeOps 对象ä¸201 */ 202function createElm (203 vnode,204 insertedVnodeQueue,205 parentElm,206 refElm,207 nested,208 ownerArray,209 index210) {211 if (isDef(vnode.elm) && isDef(ownerArray)) {212 // This vnode was used in a previous render!213 // now it's used as a new node, overwriting its elm would cause214 // potential patch errors down the road when it's used as an insertion215 // reference node. Instead, we clone the node on-demand before creating216 // associated DOM element for it.217 vnode = ownerArray[index] = cloneVNode(vnode);218 }219 vnode.isRootInsert = !nested; // for transition enter check220 // createElm æ 论ææ ·é½å°è¯å½æç»ä»¶å建ï¼è§å¯æ¯å¦æåã221 // å¦æå½åèç¹ vnode ä¸è½ä½ä¸ºç»ä»¶å建è¿å falseï¼å³å¾ä¸ç»§æ¿æ§è¡222 // å¦æå½åèç¹æ¯ç»ä»¶ vnode åæ§è¡ç»ä»¶å®ä¾åï¼å¹¶è¿å trueï¼å½åå½æ°éåº223 if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {224 return225 }226 var data = vnode.data;227 var children = vnode.children;228 var tag = vnode.tag;229 if (isDef(tag)) {230 {231 if (data && data.pre) {232 creatingElmInVPre++;233 }234 if (isUnknownElement$$1(vnode, creatingElmInVPre)) {235 warn(236 'Unknown custom element: <' + tag + '> - did you ' +237 'register the component correctly? For recursive components, ' +238 'make sure to provide the "name" option.',239 vnode.context240 );241 }242 }243 vnode.elm = vnode.ns244 ? nodeOps.createElementNS(vnode.ns, tag)245 : nodeOps.createElement(tag, vnode);246 setScope(vnode);247 /* istanbul ignore if */248 {249 createChildren(vnode, children, insertedVnodeQueue);250 if (isDef(data)) {251 invokeCreateHooks(vnode, insertedVnodeQueue);252 }253 insert(parentElm, vnode.elm, refElm);254 }255 if (data && data.pre) {256 creatingElmInVPre--;257 }258 } else if (isTrue(vnode.isComment)) {259 vnode.elm = nodeOps.createComment(vnode.text);260 insert(parentElm, vnode.elm, refElm);261 } else {262 vnode.elm = nodeOps.createTextNode(vnode.text);263 insert(parentElm, vnode.elm, refElm);264 }265}...
util.js
Source:util.js
...34 }35 return createVnode(tagName, {}, [], undefined, elm)36}3738export function invokeCreateHooks(vnode, insertedVnodeQueue) {39 let i40 for (i = 0; i < cbs.create.length; i++) {41 cbs.create[i](emptyNode, vnode)42 }43 i = vnode.data.hook44 if (isDef(i)) {45 if (isDef(i.create)) i.create(emptyNode, vnode)46 if (isDef(i.insert)) insertedVnodeQueue.push(vnode)47 }48}4950export function invokeDestroyHook(vnode) {51 let i, j52 let data = vnode.data5354 if (isDef(data)) {55 if (isDef(i = data.hook) && isDef(i = i.destroy)) {56 i(vnode)57 }5859 for (i = 0; i < cbs.destroy.length; i++) {60 cbs.destroy[i](vnode)61 }6263 if (isDef(vnode.children)) {64 for (j = 0; j < vnode.children.length; j++) {65 i = vnode.children[j]66 if (i != null && typeof i !== 'string') {67 invokeDestroyHook(i)68 }69 }70 }71 }72}7374export function createRmCb(childElm, listeners) {75 return function remove() {76 if (--listeners === 0) {77 const parent = parentNode(childElm)78 removeChild(parent, childElm)79 }80 }81}8283export function formatRootVnode(vnode) {84 if (isPrimitiveVnode(vnode)) {85 vnode = createVnode(undefined, undefined, undefined, vnode, undefined)86 }87 if (isArray(vnode)) {88 vnode = createFragmentVnode(vnode)89 console.warn('Warning: Aadjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?')90 }91 return vnode92}9394// If it is a fragment, return the last nextSibling in the list95export function nextSibling(node) {96 return node._isFragmentNode97 ? node.nextSibling98 : api.nextSibling(node)99}100101export function parentNode(node) {102 return node._isFragmentNode103 ? node.parentNode104 : api.parentNode(node)105}106107export function appendChild(node, child) {108 if (node._isFragmentNode) {109 node.appendChild(child)110 } else {111 if (child._isFragmentNode) {112 child.appendSelfInParent(node)113 } else {114 api.appendChild(node, child)115 }116 }117}118119export function removeChild(node, child) {120 if (node._isFragmentNode) {121 node.removeChild(child)122 } else {123 if (child._isFragmentNode) {124 child.removeSelfInParent(node)125 } else {126 api.removeChild(node, child)127 }128 }129}130131export function insertBefore(parentNode, newNode, referenceNode) {132 if (!parentNode || !newNode) return133 if (parentNode._isFragmentNode) {134 parentNode.insertBefore(newNode, referenceNode)135 } else {136 if (newNode._isFragmentNode) {137 newNode.insertBeforeSelfInParent(parentNode, referenceNode)138 } else {139 if (referenceNode && referenceNode._isFragmentNode) {140 referenceNode = referenceNode.first141 }142 api.insertBefore(parentNode, newNode, referenceNode)143 }144 }145}146147export function createComponent(vnode) {148 let i = vnode.data149 if (isDef(i)) {150 if (isDef(i = i.hook) && isDef(i = i.init)) {151 i(vnode)152 }153 return isDef(vnode.component)154 }155 return false156}157158export function createElm(vnode, insertedVnodeQueue) {159 // If it is a component, there is no need to go down (including custom components and internal identification components)160 if (createComponent(vnode) && !isProvider(vnode)) {161 // The `portal` component needs to proxy and forward events to the `container` in the `create` hook162 if (isPortal(vnode)) {163 vnode.elm = api.createComment('Oops.portal')164 invokeCreateHooks(vnode, insertedVnodeQueue)165 }166 return vnode.elm167 }168169 const { tag, data, children } = vnode170171 if(vnode.isComment) {172 vnode.elm = api.createComment(vnode.text)173 } else if (isDef(tag)) {174 let elm175 if (isFragment(vnode) || isProvider(vnode)) {176 elm = vnode.elm = new FragmentNode()177 } else {178 elm = vnode.elm = isDef(data) && isDef(data.ns)179 ? api.createElementNS(data.ns, tag)180 : api.createElement(tag)181 }182 if (isArray(children)) {183 for (let i = 0; i < children.length; i++) {184 const chVNode = children[i]185 if (chVNode != null) {186 appendChild(elm, createElm(chVNode, insertedVnodeQueue))187 }188 }189 } else if (isPrimitiveVnode(vnode.text)) {190 appendChild(elm, api.createTextNode(vnode.text))191 }192 invokeCreateHooks(vnode, insertedVnodeQueue)193 } else {194 vnode.elm = api.createTextNode(vnode.text)195 }196197 // After initialization198 if (isDef(data)) {199 let i = data.hook200 if (isDef(i) && isDef(i = i.initBefore)) {201 i(vnode)202 }203 }204 return vnode.elm
...
patch-fn.html.a0f5ac45.js
Source:patch-fn.html.a0f5ac45.js
1const data = {2 "key": "v-4b651e1f",3 "path": "/vue/source-study/vdom/patch-fn.html",4 "title": "patch \u8F85\u52A9\u51FD\u6570",5 "lang": "en-US",6 "frontmatter": {},7 "excerpt": "",8 "headers": [9 {10 "level": 2,11 "title": "VNode/DOM \u64CD\u4F5C\u76F8\u5173",12 "slug": "vnode-dom-\u64CD\u4F5C\u76F8\u5173",13 "children": [14 {15 "level": 3,16 "title": "sameVnode",17 "slug": "samevnode",18 "children": []19 },20 {21 "level": 3,22 "title": "removeVnodes\uFF1A\u79FB\u9664\u5B50 VNode \u53CA\u5176 DOM \u5143\u7D20\u8282\u70B9",23 "slug": "removevnodes-\u79FB\u9664\u5B50-vnode-\u53CA\u5176-dom-\u5143\u7D20\u8282\u70B9",24 "children": []25 },26 {27 "level": 3,28 "title": "removeAndInvokeRemoveHook\uFF1A\u79FB\u9664 VNode \u5BF9\u5E94\u7684 DOM \u5143\u7D20\u8282\u70B9",29 "slug": "removeandinvokeremovehook-\u79FB\u9664-vnode-\u5BF9\u5E94\u7684-dom-\u5143\u7D20\u8282\u70B9",30 "children": []31 },32 {33 "level": 3,34 "title": "removeNode\uFF1A\u79FB\u9664 DOM \u5143\u7D20\u8282\u70B9",35 "slug": "removenode-\u79FB\u9664-dom-\u5143\u7D20\u8282\u70B9",36 "children": []37 }38 ]39 },40 {41 "level": 2,42 "title": "\u94A9\u5B50\u51FD\u6570",43 "slug": "\u94A9\u5B50\u51FD\u6570",44 "children": [45 {46 "level": 3,47 "title": "invokeCreateHooks",48 "slug": "invokecreatehooks",49 "children": []50 },51 {52 "level": 3,53 "title": "invokeDestroyHook\uFF1A\u9500\u6BC1 VNode",54 "slug": "invokedestroyhook-\u9500\u6BC1-vnode",55 "children": []56 }57 ]58 }59 ],60 "filePathRelative": "vue/source-study/vdom/patch-fn.md"61};...
12423.js
Source:12423.js
...37 {38 var appendAsTree = isDef(data) && isTrue(data.appendAsTree);39 if (!appendAsTree) {40 if (isDef(data)) {41 invokeCreateHooks(vnode, insertedVnodeQueue);42 }43 insert(parentElm, vnode.elm, refElm);44 }45 createChildren(vnode, children, insertedVnodeQueue);46 if (appendAsTree) {47 if (isDef(data)) {48 invokeCreateHooks(vnode, insertedVnodeQueue);49 }50 insert(parentElm, vnode.elm, refElm);51 }52 }53 if (process.env.NODE_ENV !== "production" && data && data.pre) {54 inPre--;55 }56 } else if (isTrue(vnode.isComment)) {57 vnode.elm = nodeOps.createComment(vnode.text);58 insert(parentElm, vnode.elm, refElm);59 } else {60 vnode.elm = nodeOps.createTextNode(vnode.text);61 insert(parentElm, vnode.elm, refElm);62 }...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright['chromium'].launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('input[name="q"]', 'Playwright');7 await page.click('input[type="submit"]');8 await page.waitForSelector('text=Playwright');9 await browser.close();10})();
Using AI Code Generation
1const { invokeCreateHooks } = require('playwright/lib/server/frames');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 const frame = page.mainFrame();8 const elementHandle = await frame.$('input[name="q"]');9 await invokeCreateHooks(elementHandle, 'click');10 await browser.close();11})();12 at CDPSession.send (C:\Users\Z002Y8N\Documents\GitHub\playwright\lib\server\cdp.js:37:19)13 at async ExecutionContext._evaluateInternal (C:\Users\Z002Y8N\Documents\GitHub\playwright\lib\server\dom.js:110:24)14 at async ExecutionContext.evaluate (C:\Users\Z002Y8N\Documents\GitHub\playwright\lib\server\dom.js:83:16)15 at async ElementHandle._evaluateInUtility (C:\Users\Z002Y8N\Documents\GitHub\playwright\lib\server\dom.js:1003:20)16 at async Object.invokeCreateHooks (C:\Users\Z002Y8N\Documents\GitHub\playwright\lib\server\frames.js:27:5)17 at async Object.<anonymous> (C:\Users\Z002Y8N\Documents\GitHub\playwright\test.js:13:5)
Using AI Code Generation
1const { invokeCreateHooks } = require('playwright/lib/server/browserType');2const { chromium } = require('playwright');3(async () => {4 const browserServer = await chromium.launchServer({ headless: false });5 const browser = await browserServer.newBrowser();6 const context = await browser.newContext();7 const page = await context.newPage();8 const createHooks = invokeCreateHooks('chromium');9 await createHooks(page);10 await browser.close();11})();12 at async Promise.all (index 0)13 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)14 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)15 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)16 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)17 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)18 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)19 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)20 at async BrowserContext._doAddInitScript (/Users/raghavendra.kalakodla/playwright/node_modules/playwright/lib/server/browserContext.js:159:5)21 at async BrowserContext._doAddInitScript (/Users/
Using AI Code Generation
1const { invokeCreateHooks } = require('playwright/lib/server/browserContext');2const { chromium } = require('playwright');3const { Page } = require('playwright/lib/server/page');4const { BrowserContext } = require('playwright/lib/server/browserContext');5const browser = await chromium.launch();6const context = await browser.newContext();7const page = await context.newPage();8const response = new Page.Response(page, request, {9 headers: { 'content-type': 'text/html' },10 body: Buffer.from('<html><body><h1>Hello World!</h1></body></html>', 'utf8'),11});12await invokeCreateHooks(context, [request, response]);13await browser.close();14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const context = await browser.newContext();18 const page = await context.newPage();19 await browser.close();20})();21The following options can be passed to Browser.newContext() method:
Using AI Code Generation
1const playwright = require("playwright");2const { invokeCreateHooks } = require("playwright/lib/server/browserType");3const { chromium } = require("playwright");4const { firefox } = require("playwright");5const { webkit } = 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.screenshot({ path: "example.png" });11 await browser.close();12})();13const playwright = require("playwright");14const { invokeCreateHooks } = require("playwright/lib/server/browserType");15const { chromium } = require("playwright");16const { firefox } = require("playwright");17const { webkit } = require("playwright");18(async () => {19 const browser = await chromium.launch();20 const context = await browser.newContext();21 const page = await context.newPage();22 await page.screenshot({ path: "example.png" });23 await browser.close();24})();25const playwright = require("playwright");26const { invokeCreateHooks } = require("playwright/lib/server/browserType");27const { chromium } = require("playwright");28const { firefox } = require("playwright");29const { webkit } = require("playwright");30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await page.screenshot({ path: "example.png" });35 await browser.close();36})();37const playwright = require("playwright");38const { invokeCreateHooks } = require("playwright/lib/server/browserType");39const { chromium } = require("playwright");40const { firefox } = require("playwright");41const { webkit } = require("playwright");42(async () => {43 const browser = await chromium.launch();44 const context = await browser.newContext();45 const page = await context.newPage();
Using AI Code Generation
1const { Playwright } = require('playwright');2const { Internal } = require('playwright/lib/server/inprocess');3const { Browser } = require('playwright/lib/server/browser');4const { Page } = require('playwright/lib/server/page');5const { Frame } = require('playwright/lib/server/frame');6const browser = new Browser(new Internal(), 'browserId', 'browserName', 'browserVersion', 'platform', 'userAgent');7const page = new Page(browser, 'pageId', 'pageName', 'pageUrl');8const frame = new Frame(page, 'frameId', 'frameName', 'frameUrl');9Internal.invokeCreateHooks(browser, page, frame);10test('test', async () => {11});12test('test', async () => {13});14test('test', async () => {15});16Error: The Playwright module has not been initialized. Did you forget to call `require('playwright')` or `require('playwright').chromium`?
Using AI Code Generation
1const { invokeCreateHooks } = require('@playwright/test/lib/server/traceViewer/api');2const { createTraceViewer } = require('@playwright/test/lib/server/traceViewer/traceViewer');3const { createTraceModel } = require('@playwright/test/lib/server/traceViewer/traceModel');4const { TraceModel } = require('@playwright/test/lib/server/traceModel');5const path = require('path');6const fs = require('fs');7const traceViewer = createTraceViewer();8const traceModel = createTraceModel(traceViewer);9const trace = fs.readFileSync(path.join(__dirname, 'trace.zip'));10traceModel.setTrace(trace);11const page = await context.newPage();12invokeCreateHooks(page, traceModel);13await page.screenshot({ path: 'google.png' });14await browserContext.close();
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!!