]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): fix static content re-insertion
authorEvan You <yyx990803@gmail.com>
Sun, 23 Jan 2022 13:37:54 +0000 (21:37 +0800)
committerEvan You <yyx990803@gmail.com>
Sun, 23 Jan 2022 13:44:32 +0000 (21:44 +0800)
fix #5308

The regression was introduced in ed9eb62. In the cached code path,
we attempt re-insertion by cloning cached nodes. However if the static
fragment was removed as component root, it loses the nodes between
start and end because each node was removed individually. Therefore
the cached path can only be taken if the fragment has a single node, or
it was removed as part of a parent tree so the sibling information is
still available.

packages/runtime-dom/src/nodeOps.ts

index c3a4f4ba64247cb5c0848527a70eb83afc76cabb..16762580e98231717e298ca998e5aca3b3611e77 100644 (file)
@@ -76,7 +76,10 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
   insertStaticContent(content, parent, anchor, isSVG, start, end) {
     // <parent> before | first ... last | anchor </parent>
     const before = anchor ? anchor.previousSibling : parent.lastChild
-    if (start && end) {
+    // #5308 can only take cached path if:
+    // - has a single root node
+    // - nextSibling info is still available
+    if (start && (start === end || start.nextSibling)) {
       // cached
       while (true) {
         parent.insertBefore(start!.cloneNode(true), anchor)