Skip to content

refactor(vapor): compact createSlot options into flags - #14875

Merged
edison1105 merged 6 commits into
minorfrom
edison/perf/createSlot
May 25, 2026
Merged

edison1105 merged 6 commits into
minorfrom
edison/perf/createSlot

Conversation

@edison1105

@edison1105 edison1105 commented May 22, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Enhanced v-once support for slots: slot content and outlets now properly freeze reactive updates when marked with v-once, preventing unwanted re-renders
    • Improved interoperability between Vapor and standard Vue slots with enhanced once behavior support
  • Chores

    • Updated Node.js to version 24.15.0

Review Change Stack

@edison1105 edison1105 changed the title Edison/perf/createSlot refactor(vapor): compact createSlot options into flags May 22, 2026
@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 30cd616a-12bf-4353-a796-d26109131581

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/perf/createSlot

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented May 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14875
npm i https://pkg.pr.new/@vue/compiler-core@14875
yarn add https://pkg.pr.new/@vue/compiler-core@14875.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14875
npm i https://pkg.pr.new/@vue/compiler-dom@14875
yarn add https://pkg.pr.new/@vue/compiler-dom@14875.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14875
npm i https://pkg.pr.new/@vue/compiler-sfc@14875
yarn add https://pkg.pr.new/@vue/compiler-sfc@14875.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14875
npm i https://pkg.pr.new/@vue/compiler-ssr@14875
yarn add https://pkg.pr.new/@vue/compiler-ssr@14875.tgz

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@14875
npm i https://pkg.pr.new/@vue/compiler-vapor@14875
yarn add https://pkg.pr.new/@vue/compiler-vapor@14875.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14875
npm i https://pkg.pr.new/@vue/reactivity@14875
yarn add https://pkg.pr.new/@vue/reactivity@14875.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14875
npm i https://pkg.pr.new/@vue/runtime-core@14875
yarn add https://pkg.pr.new/@vue/runtime-core@14875.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14875
npm i https://pkg.pr.new/@vue/runtime-dom@14875
yarn add https://pkg.pr.new/@vue/runtime-dom@14875.tgz

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@14875
npm i https://pkg.pr.new/@vue/runtime-vapor@14875
yarn add https://pkg.pr.new/@vue/runtime-vapor@14875.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14875
npm i https://pkg.pr.new/@vue/server-renderer@14875
yarn add https://pkg.pr.new/@vue/server-renderer@14875.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14875
npm i https://pkg.pr.new/@vue/shared@14875
yarn add https://pkg.pr.new/@vue/shared@14875.tgz

vue

pnpm add https://pkg.pr.new/vue@14875
npm i https://pkg.pr.new/vue@14875
yarn add https://pkg.pr.new/vue@14875.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14875
npm i https://pkg.pr.new/@vue/compat@14875
yarn add https://pkg.pr.new/@vue/compat@14875.tgz

commit: d43e9d6

@edison1105 edison1105 added the scope: vapor related to vapor mode label May 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/runtime-vapor/src/vdomInterop.ts (1)

1514-1654: 💤 Low value

Consider renaming to avoid variable shadowing.

The inner renderSlotContent (line 1521) shadows the outer function renderSlotContent (line 1514). While this works correctly, it reduces readability. Consider renaming the inner function to something like invokeRenderSlot or callRenderSlot.

Suggested rename
-              const renderSlotContent = () =>
+              const invokeRenderSlot = () =>
                 renderSlot(
                   slotsRef.value,
                   isFunction(name) ? name() : name,
                   props,
                 )
               slotContent = once
-                ? withOnceSlot(renderSlotContent)
-                : renderSlotContent()
+                ? withOnceSlot(invokeRenderSlot)
+                : invokeRenderSlot()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-vapor/src/vdomInterop.ts` around lines 1514 - 1654, The
inner const renderSlotContent declared inside the outer renderSlotContent
function shadows the outer function, hurting readability; rename the inner
helper (e.g. to invokeRenderSlot) and update its two call sites (the
withOnceSlot(...) and the direct invocation) as well as the once ?
withOnceSlot(...) branch so that the outer renderSlotContent function remains
unshadowed (references: outer renderSlotContent, inner renderSlotContent,
slotsRef.value, withOnceSlot).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/runtime-vapor/src/vdomInterop.ts`:
- Around line 1514-1654: The inner const renderSlotContent declared inside the
outer renderSlotContent function shadows the outer function, hurting
readability; rename the inner helper (e.g. to invokeRenderSlot) and update its
two call sites (the withOnceSlot(...) and the direct invocation) as well as the
once ? withOnceSlot(...) branch so that the outer renderSlotContent function
remains unshadowed (references: outer renderSlotContent, inner
renderSlotContent, slotsRef.value, withOnceSlot).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3039d440-1d16-43db-8c45-5ce2ef8004a9

📥 Commits

Reviewing files that changed from the base of the PR and between fcd7177 and 1aeea72.

⛔ Files ignored due to path filters (6)
  • packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/logicalIndex.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/vOnce.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • packages/compiler-vapor/__tests__/transforms/transformSlotOutlet.spec.ts
  • packages/compiler-vapor/src/generators/slotOutlet.ts
  • packages/compiler-vapor/src/ir/index.ts
  • packages/compiler-vapor/src/transforms/transformSlotOutlet.ts
  • packages/runtime-core/src/apiCreateApp.ts
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/__tests__/scopeId.spec.ts
  • packages/runtime-vapor/__tests__/vdomInterop.spec.ts
  • packages/runtime-vapor/src/componentSlots.ts
  • packages/runtime-vapor/src/vdomInterop.ts
  • packages/shared/src/vaporFlags.ts

@edison1105
edison1105 marked this pull request as ready for review May 22, 2026 07:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/runtime-vapor/src/vdomInterop.ts (1)

1515-1530: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep the once scope active through mount/hydrate.

Line 1528 only wraps renderSlot() itself. The returned VNodes are instantiated later at Lines 1560-1575 and 1608-1619, after withOnceSlot() has already unwound, so nested Vapor children miss the isOnce/props snapshot path and can still observe parent updates from a supposedly frozen slot.

Suggested direction
+      const runInOnceScope = <T>(fn: () => T): T =>
+        once ? withOnceSlot(fn) : fn()
+
       const renderSlotContent = () => {
-        runWithFragmentRenderCtx(frag, () =>
-          withOwnedSlotBoundary(boundary, () => {
+        runInOnceScope(() =>
+          runWithFragmentRenderCtx(frag, () =>
+            withOwnedSlotBoundary(boundary, () => {
               let slotContent: VNode | Block | undefined
               let slotContentValid = false

               if (slotsRef.value) {
-                const renderSlotContent = () =>
+                const renderSlotContent = () =>
                   renderSlot(
                     slotsRef.value,
                     isFunction(name) ? name() : name,
                     props,
                   )
-                slotContent = once
-                  ? withOnceSlot(renderSlotContent)
-                  : renderSlotContent()
+                slotContent = renderSlotContent()

                 // ...
                 if (isHydrating) {
                   // hydrateVNode(...)
                 } else if (isVNode(slotContent)) {
                   // internals.p(...)
                 }
-          }),
-        )
+            }),
+          ),
+        )
       }

Also applies to: 1560-1575, 1608-1619, 1655-1655

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-vapor/src/vdomInterop.ts` around lines 1515 - 1530, The
current code only wraps the immediate call to renderSlot() with withOnceSlot, so
the once scope unwinds before the returned VNodes are actually instantiated
during mount/hydrate; this allows nested Vapor children to observe updates.
Change the logic so that when once is true you keep the once scope active across
the mount/hydrate phases: instead of unwinding immediately, store a thunk or a
marker and ensure the actual instantiation paths (the places that process
slotContent during mount/hydrate) execute inside withOnceSlot. Concretely,
update renderSlotContent / slotContent handling so that when once is true you
either (a) keep slotContent as a thunk that calls renderSlotContent inside
withOnceSlot and only invoke that thunk during mount/hydrate, or (b) wrap the
mount/hydrate instantiation code paths that consume slotContent with
withOnceSlot; reference the variables/functions renderSlotContent, slotContent,
once, withOnceSlot, runWithFragmentRenderCtx and the mount/hydrate processing
locations so the once scope remains active until VNodes are instantiated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/runtime-vapor/__tests__/componentSlots.spec.ts`:
- Around line 1831-1839: The test mutates the global __DEV__ and restores it to
a hardcoded true which can leak state; fix by saving the original value (e.g.,
const prevDev = __DEV__) before setting __DEV__ = false, and in the finally
block restore it with __DEV__ = prevDev; apply the same change to the other
occurrence around the define/createComponent render block so both places restore
the original __DEV__ value instead of hardcoding true.

In `@packages/runtime-vapor/src/componentProps.ts`:
- Around line 95-105: The function-backed branch currently assigns
snapshotSources[i] = () => value which preserves the same object reference
returned by resolveFunctionSource and allows later mutations to leak into the
snapshot; change it so the function returns a fresh cloned/resolved object (like
the non-function branch) by iterating the keys of the returned record from
resolveFunctionSource and building a new object with resolveSource applied to
each property before returning it (update the logic around isFunction,
resolveFunctionSource and snapshotSources assignment).

---

Outside diff comments:
In `@packages/runtime-vapor/src/vdomInterop.ts`:
- Around line 1515-1530: The current code only wraps the immediate call to
renderSlot() with withOnceSlot, so the once scope unwinds before the returned
VNodes are actually instantiated during mount/hydrate; this allows nested Vapor
children to observe updates. Change the logic so that when once is true you keep
the once scope active across the mount/hydrate phases: instead of unwinding
immediately, store a thunk or a marker and ensure the actual instantiation paths
(the places that process slotContent during mount/hydrate) execute inside
withOnceSlot. Concretely, update renderSlotContent / slotContent handling so
that when once is true you either (a) keep slotContent as a thunk that calls
renderSlotContent inside withOnceSlot and only invoke that thunk during
mount/hydrate, or (b) wrap the mount/hydrate instantiation code paths that
consume slotContent with withOnceSlot; reference the variables/functions
renderSlotContent, slotContent, once, withOnceSlot, runWithFragmentRenderCtx and
the mount/hydrate processing locations so the once scope remains active until
VNodes are instantiated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 336b0090-788a-49ff-932e-3759e4d2a2e1

📥 Commits

Reviewing files that changed from the base of the PR and between e7110d5 and 7496635.

📒 Files selected for processing (9)
  • packages/runtime-core/src/apiCreateApp.ts
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/__tests__/customElement.spec.ts
  • packages/runtime-vapor/__tests__/vdomInterop.spec.ts
  • packages/runtime-vapor/src/apiDefineAsyncComponent.ts
  • packages/runtime-vapor/src/component.ts
  • packages/runtime-vapor/src/componentProps.ts
  • packages/runtime-vapor/src/componentSlots.ts
  • packages/runtime-vapor/src/vdomInterop.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/runtime-vapor/src/componentProps.ts (1)

233-243: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use a null-prototype cache for once props/attrs.

hasOwn() fixes reads for keys like toString, but instance.oncePropsCache = {} still leaves __proto__ as a setter hit instead of a real cached entry. A once-frozen prop/attr with that name can return the wrong value and corrupt the cache object.

Proposed fix
-      const cache = instance.oncePropsCache || (instance.oncePropsCache = {})
+      const cache =
+        instance.oncePropsCache ||
+        (instance.oncePropsCache = Object.create(null))
@@
-    const cache = target.oncePropsCache || (target.oncePropsCache = {})
+    const cache =
+      target.oncePropsCache ||
+      (target.oncePropsCache = Object.create(null))

Also applies to: 296-307

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-vapor/src/componentProps.ts` around lines 233 - 243, The
cache is created with a normal object (instance.oncePropsCache = {}) which
leaves a prototype and allows prototype-named keys (like toString) to be treated
as setters rather than real cached entries; change the initialization to a
null-prototype object (instance.oncePropsCache = Object.create(null)) wherever
the cache is created (the block that uses hasOwn(cache, key), getter(instance,
key), pauseTracking(), resetTracking() and the analogous block later) so that
storing/reading once props/attrs cannot be corrupted by inherited properties.
packages/runtime-vapor/src/vdomInterop.ts (1)

1004-1010: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Mount and hydrate VDOM components inside the once scope.

Forwarding once into the wrapper is not enough here. A VDOM component returned from a v-once slot fallback still mounts outside withOnceSlot, so its own render effect can track arbitrary refs, and any nested Vapor descendants created during that render won't inherit isOnce.

Proposed fix
 function createVDOMComponent(
   internals: RendererInternals,
   component: ConcreteComponent,
   parentComponent: VaporComponentInstance | null,
   rawProps?: LooseRawProps | null,
   rawSlots?: LooseRawSlots | null,
   once?: boolean,
 ): VaporFragment {
+  const runInOnceScope = <T>(fn: () => T): T =>
+    once ? withOnceSlot(fn) : fn()
+
   const suspense =
     currentParentSuspense || (parentComponent && parentComponent.suspense)
@@
   frag.hydrate = () => {
     if (!isHydrating) return
-    hydrateVNode(vnode, parentComponent as any)
+    runInOnceScope(() => hydrateVNode(vnode, parentComponent as any))
     isMounted = true
     frag.nodes = resolveVNodeNodes(vnode)
     frag.validityPending = false
   }
@@
       if (!isMounted) {
         if (transition) setVNodeTransitionHooks(vnode, transition)
-        internals.mt(
-          vnode,
-          parentNode,
-          anchor,
-          parentComponent as any,
-          suspense,
-          undefined,
-          false,
-        )
+        runInOnceScope(() =>
+          internals.mt(
+            vnode,
+            parentNode,
+            anchor,
+            parentComponent as any,
+            suspense,
+            undefined,
+            false,
+          ),
+        )
         // set ref
         if (rawRef) vdomSetRef(rawRef, null, null, vnode)
         isMounted = true

Also applies to: 1092-1129

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/runtime-vapor/src/vdomInterop.ts` around lines 1004 - 1010, The
wrapper VaporComponentInstance is being constructed outside the withOnceSlot
scope so its render effect and any nested Vapor descendants won't inherit the
isOnce context; instead create and initialize the instance inside a withOnceSlot
call (e.g., wrap the new VaporComponentInstance(...) creation and any subsequent
mount/hydrate calls inside withOnceSlot(() => { ... })) so the instance's
setup/render effects run within the once scope; apply the same change for the
analogous block around the VaporComponentInstance usage at the 1092-1129 region.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/runtime-vapor/src/componentProps.ts`:
- Around line 233-243: The cache is created with a normal object
(instance.oncePropsCache = {}) which leaves a prototype and allows
prototype-named keys (like toString) to be treated as setters rather than real
cached entries; change the initialization to a null-prototype object
(instance.oncePropsCache = Object.create(null)) wherever the cache is created
(the block that uses hasOwn(cache, key), getter(instance, key), pauseTracking(),
resetTracking() and the analogous block later) so that storing/reading once
props/attrs cannot be corrupted by inherited properties.

In `@packages/runtime-vapor/src/vdomInterop.ts`:
- Around line 1004-1010: The wrapper VaporComponentInstance is being constructed
outside the withOnceSlot scope so its render effect and any nested Vapor
descendants won't inherit the isOnce context; instead create and initialize the
instance inside a withOnceSlot call (e.g., wrap the new
VaporComponentInstance(...) creation and any subsequent mount/hydrate calls
inside withOnceSlot(() => { ... })) so the instance's setup/render effects run
within the once scope; apply the same change for the analogous block around the
VaporComponentInstance usage at the 1092-1129 region.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a35cbc67-38f3-4b1a-885e-fd68a6e85f95

📥 Commits

Reviewing files that changed from the base of the PR and between 7496635 and 068f5b1.

📒 Files selected for processing (3)
  • packages/runtime-vapor/__tests__/componentSlots.spec.ts
  • packages/runtime-vapor/src/componentProps.ts
  • packages/runtime-vapor/src/vdomInterop.ts

@edison1105
edison1105 merged commit c4d566b into minor May 25, 2026
13 of 14 checks passed
@edison1105
edison1105 deleted the edison/perf/createSlot branch May 25, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant