code: function aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement) {
      if (p._isElementCausesFosterParenting(commonAncestor)) {
          p._fosterParentElement(lastElement);
      } else {
          const tn = p.treeAdapter.getTagName(commonAncestor);
          const ns = p.treeAdapter.getNamespaceURI(commonAncestor);
  
          if (tn === $.TEMPLATE && ns === NS.HTML) {
              commonAncestor = p.treeAdapter.getTemplateContent(commonAncestor);
          }
  
          p.treeAdapter.appendChild(commonAncestor, lastElement);
      }
  }
docs: Step 14 of the algorithm