]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(Suspense): properly fix #6416
authorEvan You <yyx990803@gmail.com>
Wed, 13 Dec 2023 09:56:58 +0000 (17:56 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 13 Dec 2023 09:56:58 +0000 (17:56 +0800)
previous fix caused regressions in nuxt

packages/runtime-core/__tests__/components/Suspense.spec.ts
packages/runtime-core/src/componentRenderUtils.ts
packages/runtime-core/src/renderer.ts

index 60dcedc9700c46a1df10a5a31408378534167ea6..92638cc6ba3a4b37b3c0e97e2554dfbd96d76a17 100644 (file)
@@ -1684,7 +1684,9 @@ describe('Suspense', () => {
     expect(serializeInner(root)).toBe('<div>async</div>')
 
     viewRef.value = 1
-    await nextTick() //TypeError: Cannot read properties of null (reading 'parentNode'),This has been fixed
+    await nextTick()
+    // TypeError: Cannot read properties of null (reading 'parentNode')
+    // This has been fixed
     expect(serializeInner(root)).toBe(`<div>sync</div>`)
   })
 
index 2ed64f7b5773896c0693bcb3c13161d5793d910e..38a9e8d19d801c8c18205ff6b6d7c7e1f9d0aaf2 100644 (file)
@@ -428,8 +428,16 @@ export function updateHOCHostEl(
   { vnode, parent }: ComponentInternalInstance,
   el: typeof vnode.el // HostNode
 ) {
-  while (parent && parent.subTree === vnode) {
-    ;(vnode = parent.vnode).el = el
-    parent = parent.parent
+  while (parent) {
+    const root = parent.subTree
+    if (root.suspense && root.suspense.activeBranch === vnode) {
+      root.el = vnode.el
+    }
+    if (root === vnode) {
+      ;(vnode = parent.vnode).el = el
+      parent = parent.parent
+    } else {
+      break
+    }
   }
 }
index b0eb1844ed99277a1a7d9950a9ae870a68e0824b..d79be152f219abbbbaa925f94d93da9215e5e3c8 100644 (file)
@@ -1241,10 +1241,6 @@ function baseCreateRenderer(
       if (!initialVNode.el) {
         const placeholder = (instance.subTree = createVNode(Comment))
         processCommentNode(null, placeholder, container!, anchor)
-        // This noramlly gets setup by the following `setupRenderEffect`.
-        // But the call is skipped in initial mounting of async element.
-        // Thus, manually patching is required here or it will result in a crash during parent component update.
-        initialVNode.el = placeholder.el
       }
       return
     }