]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(vapor): optimize v-if in once mode
authorEvan You <evan@vuejs.org>
Wed, 12 Feb 2025 00:58:22 +0000 (08:58 +0800)
committerEvan You <evan@vuejs.org>
Wed, 12 Feb 2025 00:58:22 +0000 (08:58 +0800)
packages/runtime-vapor/src/apiCreateIf.ts

index e4035313931877375d28345f851ad91d47974084..947935f88b0c6effa9a4564bc953c77ed31e9847 100644 (file)
@@ -1,4 +1,4 @@
-import { type BlockFn, DynamicFragment } from './block'
+import { type Block, type BlockFn, DynamicFragment } from './block'
 import { renderEffect } from './renderEffect'
 
 export function createIf(
@@ -7,12 +7,12 @@ export function createIf(
   b2?: BlockFn,
   once?: boolean,
   // hydrationNode?: Node,
-): DynamicFragment {
-  const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
+): Block {
   if (once) {
-    frag.update(condition() ? b1 : b2)
+    return condition() ? b1() : b2 ? b2() : []
   } else {
+    const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
     renderEffect(() => frag.update(condition() ? b1 : b2))
+    return frag
   }
-  return frag
 }