Repository navigation
refactor(vapor): compact createSlot options into flags - #14875
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/compiler-vapor
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/runtime-vapor
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime-vapor/src/vdomInterop.ts (1)
1514-1654: 💤 Low valueConsider renaming to avoid variable shadowing.
The inner
renderSlotContent(line 1521) shadows the outer functionrenderSlotContent(line 1514). While this works correctly, it reduces readability. Consider renaming the inner function to something likeinvokeRenderSlotorcallRenderSlot.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
⛔ Files ignored due to path filters (6)
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/logicalIndex.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/vOnce.spec.ts.snapis excluded by!**/*.snappackages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (11)
packages/compiler-vapor/__tests__/transforms/transformSlotOutlet.spec.tspackages/compiler-vapor/src/generators/slotOutlet.tspackages/compiler-vapor/src/ir/index.tspackages/compiler-vapor/src/transforms/transformSlotOutlet.tspackages/runtime-core/src/apiCreateApp.tspackages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/__tests__/scopeId.spec.tspackages/runtime-vapor/__tests__/vdomInterop.spec.tspackages/runtime-vapor/src/componentSlots.tspackages/runtime-vapor/src/vdomInterop.tspackages/shared/src/vaporFlags.ts
There was a problem hiding this comment.
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 winKeep 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, afterwithOnceSlot()has already unwound, so nested Vapor children miss theisOnce/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
📒 Files selected for processing (9)
packages/runtime-core/src/apiCreateApp.tspackages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/__tests__/customElement.spec.tspackages/runtime-vapor/__tests__/vdomInterop.spec.tspackages/runtime-vapor/src/apiDefineAsyncComponent.tspackages/runtime-vapor/src/component.tspackages/runtime-vapor/src/componentProps.tspackages/runtime-vapor/src/componentSlots.tspackages/runtime-vapor/src/vdomInterop.ts
There was a problem hiding this comment.
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 winUse a null-prototype cache for once props/attrs.
hasOwn()fixes reads for keys liketoString, butinstance.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 winMount and hydrate VDOM components inside the once scope.
Forwarding
onceinto the wrapper is not enough here. A VDOM component returned from av-onceslot fallback still mounts outsidewithOnceSlot, so its own render effect can track arbitrary refs, and any nested Vapor descendants created during that render won't inheritisOnce.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 = trueAlso 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
📒 Files selected for processing (3)
packages/runtime-vapor/__tests__/componentSlots.spec.tspackages/runtime-vapor/src/componentProps.tspackages/runtime-vapor/src/vdomInterop.ts
Summary by CodeRabbit
New Features
Chores