]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(hydration): prevent lazy hydration for updated components
authordaiwei <daiwei521@126.com>
Sun, 22 Jun 2025 02:16:02 +0000 (10:16 +0800)
committerdaiwei <daiwei521@126.com>
Sun, 22 Jun 2025 02:27:32 +0000 (10:27 +0800)
packages/runtime-core/src/apiAsyncComponent.ts

index cb675f06e432f808e0f45108251bba73db09f803..25e6fa481ca4e75f7bd49b67ce5c00ab10638162 100644 (file)
@@ -123,28 +123,28 @@ export function defineAsyncComponent<
 
     __asyncHydrate(el, instance, hydrate) {
       let patched = false
+      ;(instance.bu || (instance.bu = [])).push(() => (patched = true))
+      const performHydrate = () => {
+        // skip hydration if the component has been patched
+        if (__DEV__ && patched) {
+          warn(
+            `Skipping lazy hydration for component '${getComponentName(resolvedComp!) || resolvedComp!.__file}': ` +
+              `it was updated before lazy hydration performed.`,
+          )
+          return
+        }
+        hydrate()
+      }
       const doHydrate = hydrateStrategy
         ? () => {
-            const performHydrate = () => {
-              // skip hydration if the component has been patched
-              if (__DEV__ && patched) {
-                warn(
-                  `Skipping lazy hydration for component '${getComponentName(resolvedComp!)}': ` +
-                    `it was updated before lazy hydration performed.`,
-                )
-                return
-              }
-              hydrate()
-            }
             const teardown = hydrateStrategy(performHydrate, cb =>
               forEachElement(el, cb),
             )
             if (teardown) {
               ;(instance.bum || (instance.bum = [])).push(teardown)
             }
-            ;(instance.u || (instance.u = [])).push(() => (patched = true))
           }
-        : hydrate
+        : performHydrate
       if (resolvedComp) {
         doHydrate()
       } else {