]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(suspense): fix more suspense patch before resolve edge cases
authorEvan You <yyx990803@gmail.com>
Wed, 10 Jan 2024 13:03:20 +0000 (21:03 +0800)
committerEvan You <yyx990803@gmail.com>
Wed, 10 Jan 2024 16:37:06 +0000 (00:37 +0800)
close #10017

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

index 203937aa52607b3692cde16af06cd25ed036aacd..7c3f8ff8b3dc0d0bbede53edf2bd7b5a6ace0736 100644 (file)
@@ -1692,7 +1692,7 @@ describe('Suspense', () => {
     expect(serializeInner(root)).toBe(`<div>sync</div>`)
   })
 
-  // #6416 follow up
+  // #6416 follow up / #10017
   test('Suspense patched during HOC async component re-mount', async () => {
     const key = ref('k')
     const data = ref('data')
@@ -1713,7 +1713,7 @@ describe('Suspense', () => {
     const App = {
       render() {
         return h(Suspense, null, {
-          default: h(Comp, { data: data.value }),
+          default: h(Comp, { k: key.value, data: data.value }),
         })
       },
     }
index e07a31ee2023430f7e01211cddd986931016e96f..4cb29180e25c9fa0fb865f0b63bdb4319173d38b 100644 (file)
@@ -428,7 +428,6 @@ export function updateHOCHostEl(
   { vnode, parent }: ComponentInternalInstance,
   el: typeof vnode.el, // HostNode
 ) {
-  if (!el) return
   while (parent) {
     const root = parent.subTree
     if (root.suspense && root.suspense.activeBranch === vnode) {
index 8d6ee16410ae0cf81589e80233d3bcf9a2756515..ac023ae60cd679af78fff164845fca88d6641362 100644 (file)
@@ -864,7 +864,14 @@ export function queueEffectWithSuspense(
 function setActiveBranch(suspense: SuspenseBoundary, branch: VNode) {
   suspense.activeBranch = branch
   const { vnode, parentComponent } = suspense
-  const el = (vnode.el = branch.el)
+  let el = branch.el
+  // if branch has no el after patch, it's a HOC wrapping async components
+  // drill and locate the placeholder comment node
+  while (!el && branch.component) {
+    branch = branch.component.subTree
+    el = branch.el
+  }
+  vnode.el = el
   // in case suspense is the root node of a component,
   // recursively update the HOC el
   if (parentComponent && parentComponent.subTree === vnode) {