Просмотр исходного кода

fix(Suspense): clear el reference from fallback vnode to allow garbage collection

daiwei 5 месяцев назад
Родитель
Сommit
9954f4546e
1 измененных файлов с 10 добавлено и 0 удалено
  1. 10 0
      packages/runtime-core/src/components/Suspense.ts

+ 10 - 0
packages/runtime-core/src/components/Suspense.ts

@@ -530,6 +530,7 @@ function createSuspenseBoundary(
         effects,
         effects,
         parentComponent,
         parentComponent,
         container,
         container,
+        isInFallback,
       } = suspense
       } = suspense
 
 
       // if there's a transition happening we need to wait it to finish.
       // if there's a transition happening we need to wait it to finish.
@@ -551,6 +552,10 @@ function createSuspenseBoundary(
                 MoveType.ENTER,
                 MoveType.ENTER,
               )
               )
               queuePostFlushCb(effects)
               queuePostFlushCb(effects)
+              // clear el reference from fallback vnode to allow GC after transition
+              if (isInFallback && vnode.ssFallback) {
+                vnode.ssFallback.el = null
+              }
             }
             }
           }
           }
         }
         }
@@ -570,6 +575,11 @@ function createSuspenseBoundary(
             anchor = next(activeBranch)
             anchor = next(activeBranch)
           }
           }
           unmount(activeBranch, parentComponent, suspense, true)
           unmount(activeBranch, parentComponent, suspense, true)
+          // clear el reference from fallback vnode to allow GC
+          // only clear immediately if there's no delayed transition
+          if (!delayEnter && isInFallback && vnode.ssFallback) {
+            vnode.ssFallback.el = null
+          }
         }
         }
         if (!delayEnter) {
         if (!delayEnter) {
           // move content from off-dom container to actual container
           // move content from off-dom container to actual container