function hydrate()

in views/vue.js [6189:6297]


    function hydrate(elm, vnode, insertedVnodeQueue, inVPre) {
      let i;
      const tag = vnode.tag;
      const data = vnode.data;
      const children = vnode.children;
      inVPre = inVPre || (data && data.pre);
      vnode.elm = elm;

      if (isTrue(vnode.isComment) && isDef(vnode.asyncFactory)) {
        vnode.isAsyncPlaceholder = true;
        return true;
      }
      // assert node match
      {
        if (!assertNodeMatch(elm, vnode, inVPre)) {
          return false;
        }
      }
      if (isDef(data)) {
        if (isDef((i = data.hook)) && isDef((i = i.init))) {
          i(vnode, true /* hydrating */);
        }
        if (isDef((i = vnode.componentInstance))) {
          // child component. it should have hydrated its own tree.
          initComponent(vnode, insertedVnodeQueue);
          return true;
        }
      }
      if (isDef(tag)) {
        if (isDef(children)) {
          // empty element, allow client to pick up and populate children
          if (!elm.hasChildNodes()) {
            createChildren(vnode, children, insertedVnodeQueue);
          } else {
            // v-html and domProps: innerHTML
            if (
              isDef((i = data)) &&
              isDef((i = i.domProps)) &&
              isDef((i = i.innerHTML))
            ) {
              if (i !== elm.innerHTML) {
                /* istanbul ignore if */
                if (
                  "development" !== "production" &&
                  typeof console !== "undefined" &&
                  !hydrationBailed
                ) {
                  hydrationBailed = true;
                  console.warn("Parent: ", elm);
                  console.warn("server innerHTML: ", i);
                  console.warn("client innerHTML: ", elm.innerHTML);
                }
                return false;
              }
            } else {
              // iterate and compare children lists
              let childrenMatch = true;
              let childNode = elm.firstChild;
              for (let i$1 = 0; i$1 < children.length; i$1++) {
                if (
                  !childNode ||
                  !hydrate(childNode, children[i$1], insertedVnodeQueue, inVPre)
                ) {
                  childrenMatch = false;
                  break;
                }
                childNode = childNode.nextSibling;
              }
              // if childNode is not null, it means the actual childNodes list is
              // longer than the virtual children list.
              if (!childrenMatch || childNode) {
                /* istanbul ignore if */
                if (
                  "development" !== "production" &&
                  typeof console !== "undefined" &&
                  !hydrationBailed
                ) {
                  hydrationBailed = true;
                  console.warn("Parent: ", elm);
                  console.warn(
                    "Mismatching childNodes vs. VNodes: ",
                    elm.childNodes,
                    children
                  );
                }
                return false;
              }
            }
          }
        }
        if (isDef(data)) {
          let fullInvoke = false;
          for (const key in data) {
            if (!isRenderedModule(key)) {
              fullInvoke = true;
              invokeCreateHooks(vnode, insertedVnodeQueue);
              break;
            }
          }
          if (!fullInvoke && data["class"]) {
            // ensure collecting deps for deep class bindings for future updates
            traverse(data["class"]);
          }
        }
      } else if (elm.data !== vnode.text) {
        elm.data = vnode.text;
      }
      return true;
    }