diff --git a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
index cb7b5de8683..56a1e8c726a 100644
--- a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
+++ b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
@@ -316,17 +316,17 @@ export function render(_ctx) {
`;
exports[`compile > expression parsing > v-slot 1`] = `
-"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
+"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
const t0 = _template(" ")
export function render(_ctx) {
const _component_Comp = _resolveComponent("Comp")
const n1 = _createComponentWithFallback(_component_Comp, null, {
- "foo": _withVaporCtx((_slotProps0) => {
+ "foo": (_slotProps0) => {
const n0 = t0()
_renderEffect(() => _setText(n0, _toDisplayString(_slotProps0.a + _slotProps0.b)))
return n0
- })
+ }
}, true)
return n1
}"
diff --git a/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap
index c49073973a1..5a399581868 100644
--- a/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap
+++ b/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap
@@ -1,23 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`scopeId compiler support > should wrap default slot 1`] = `
-"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
+"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
const t0 = _template("
')() as HTMLDivElement
renderEffect(() => setDynamicProps(n0, [attrs]))
return n0
- }),
+ },
})
return n0
},
diff --git a/packages/runtime-vapor/__tests__/componentAttrs.spec.ts b/packages/runtime-vapor/__tests__/componentAttrs.spec.ts
index d82837ffa7e..e5838e91ffe 100644
--- a/packages/runtime-vapor/__tests__/componentAttrs.spec.ts
+++ b/packages/runtime-vapor/__tests__/componentAttrs.spec.ts
@@ -20,7 +20,6 @@ import {
setProp,
setStyle,
template,
- withVaporCtx,
} from '../src'
import { makeRender } from './_utils'
import { stringifyStyle } from '@vue/shared'
@@ -1087,10 +1086,10 @@ describe('attribute fallthrough', () => {
() => 'button',
null,
{
- default: withVaporCtx(() => {
+ default: () => {
const n0 = createSlot('default', null)
return n0
- }),
+ },
},
true,
)
diff --git a/packages/runtime-vapor/__tests__/componentSlots.spec.ts b/packages/runtime-vapor/__tests__/componentSlots.spec.ts
index 74b6a9b3b9a..db2171b583a 100644
--- a/packages/runtime-vapor/__tests__/componentSlots.spec.ts
+++ b/packages/runtime-vapor/__tests__/componentSlots.spec.ts
@@ -178,7 +178,7 @@ describe('component: slots', () => {
const { host } = define(() => {
return createComponent(Comp, null, {
- header: withVaporCtx(() => template('header')()),
+ header: () => template('header')(),
})
}).render()
@@ -225,7 +225,7 @@ describe('component: slots', () => {
)
define(() =>
createComponent(Comp, null, {
- default: withVaporCtx((_props: any) => ((props = _props), [])),
+ default: (_props: any) => ((props = _props), []),
}),
).render()
@@ -253,7 +253,7 @@ describe('component: slots', () => {
)
define(() =>
createComponent(Comp, null, {
- default: withVaporCtx((_props: any) => ((props = _props), [])),
+ default: (_props: any) => ((props = _props), []),
}),
).render()
@@ -286,13 +286,13 @@ describe('component: slots', () => {
$: [
() => ({
name: 'header',
- fn: withVaporCtx((props: any) => {
+ fn: (props: any) => {
const el = template('
')()
renderEffect(() => {
setElementText(el, props.title)
})
return el
- }),
+ },
}),
],
})
@@ -321,8 +321,8 @@ describe('component: slots', () => {
const { host } = define(() => {
return createComponent(Comp, null, {
- header: withVaporCtx(() => template('header')()),
- footer: withVaporCtx(() => template('footer')()),
+ header: () => template('header')(),
+ footer: () => template('footer')(),
})
}).render()
@@ -371,11 +371,11 @@ describe('component: slots', () => {
flag1.value
? {
name: 'one',
- fn: withVaporCtx(() => template('one content')()),
+ fn: () => template('one content')(),
}
: {
name: 'two',
- fn: withVaporCtx(() => template('two content')()),
+ fn: () => template('two content')(),
},
],
})
@@ -420,8 +420,8 @@ describe('component: slots', () => {
Child,
{},
{
- one: withVaporCtx(() => template('one content')()),
- two: withVaporCtx(() => template('two content')()),
+ one: () => template('one content')(),
+ two: () => template('two content')(),
},
)
}).render()
@@ -468,14 +468,14 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
return createIf(
() => toggle.value,
() => {
return document.createTextNode('content')
},
)
- }),
+ },
})
},
}).render()
@@ -505,14 +505,14 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
return createIf(
() => toggle.value,
() => {
return document.createTextNode('content')
},
)
- }),
+ },
})
},
}).render()
@@ -546,9 +546,9 @@ describe('component: slots', () => {
(toggle.value
? {
name: val.value,
- fn: withVaporCtx(() => {
+ fn: () => {
return template('
')()
- }),
+ },
}
: void 0) as DynamicSlot,
],
@@ -574,9 +574,9 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
return template('')()
- }),
+ },
})
},
}).render()
@@ -598,14 +598,14 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
return createIf(
() => toggle.value,
() => {
return document.createTextNode('content')
},
)
- }),
+ },
})
},
}).render()
@@ -636,7 +636,7 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
return createIf(
() => outerShow.value,
() => {
@@ -648,7 +648,7 @@ describe('component: slots', () => {
)
},
)
- }),
+ },
})
},
}).render()
@@ -693,7 +693,7 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
const n2 = createFor(
() => items.value,
for_item0 => {
@@ -706,7 +706,7 @@ describe('component: slots', () => {
},
)
return n2
- }),
+ },
})
},
}).render()
@@ -739,7 +739,7 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
const n2 = createFor(
() => items.value,
for_item0 => {
@@ -752,7 +752,7 @@ describe('component: slots', () => {
},
)
return n2
- }),
+ },
})
},
}).render()
@@ -794,12 +794,12 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
const n3 = template('
')() as any
const x3 = txt(n3) as any
renderEffect(() => setText(x3, toDisplayString(count.value)))
return n3
- }),
+ },
})
},
}).render()
@@ -843,11 +843,11 @@ describe('component: slots', () => {
Parent,
null,
{
- foo: withVaporCtx(() => {
+ foo: () => {
const n0 = template(' ')() as any
renderEffect(() => setText(n0, foo.value))
return n0
- }),
+ },
},
true,
)
@@ -888,16 +888,16 @@ describe('component: slots', () => {
Parent,
null,
{
- foo: withVaporCtx(() => {
+ foo: () => {
const n0 = template(' ')() as any
renderEffect(() => setText(n0, foo.value))
return n0
- }),
- default: withVaporCtx(() => {
+ },
+ default: () => {
const n3 = template(' ')() as any
renderEffect(() => setText(n3, foo.value))
return n3
- }),
+ },
},
true,
)
@@ -936,7 +936,7 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Parent, null, {
- default: withVaporCtx(() => template('')()),
+ default: () => template('')(),
})
},
}).render()
@@ -976,7 +976,7 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Parent, null, {
- default: withVaporCtx(() => template('')()),
+ default: () => template('')(),
})
},
}).render()
@@ -1057,8 +1057,8 @@ describe('component: slots', () => {
const { html } = define({
setup() {
return createComponent(Child, null, {
- default: withVaporCtx(() => template('default')()),
- foo: withVaporCtx(() => template('foo')()),
+ default: () => template('default')(),
+ foo: () => template('foo')(),
})
},
}).render()
diff --git a/packages/runtime-vapor/__tests__/components/Teleport.spec.ts b/packages/runtime-vapor/__tests__/components/Teleport.spec.ts
index f6b47220e76..c8f77f29af9 100644
--- a/packages/runtime-vapor/__tests__/components/Teleport.spec.ts
+++ b/packages/runtime-vapor/__tests__/components/Teleport.spec.ts
@@ -4,7 +4,6 @@ import {
createComponent as createComp,
createComponent,
} from '../../src/component'
-import { withVaporCtx } from '../../src'
import {
type VaporDirective,
VaporTeleport,
@@ -719,11 +718,11 @@ function runSharedTests(deferMode: boolean): void {
VaporTeleport,
{ to: () => svg.value },
{
- default: withVaporCtx(() => {
+ default: () => {
const n3 = template('
', false, 1)() as any
_setTemplateRef(n3, circle, undefined, undefined, 'circle')
return n3
- }),
+ },
},
)
return n4
diff --git a/packages/runtime-vapor/__tests__/customElement.spec.ts b/packages/runtime-vapor/__tests__/customElement.spec.ts
index faad57aa52b..fecbf51780b 100644
--- a/packages/runtime-vapor/__tests__/customElement.spec.ts
+++ b/packages/runtime-vapor/__tests__/customElement.spec.ts
@@ -1407,7 +1407,7 @@ describe('defineVaporCustomElement', () => {
return createPlainElement('my-parent', null, {
default: withVaporCtx(() =>
createPlainElement('my-child', null, {
- default: withVaporCtx(() => template('
default')()),
+ default: () => template('
default')(),
}),
),
})
@@ -1461,7 +1461,7 @@ describe('defineVaporCustomElement', () => {
return createPlainElement('my-el-teleport-parent', null, {
default: withVaporCtx(() =>
createPlainElement('my-el-teleport-child', null, {
- default: withVaporCtx(() => template('
default')()),
+ default: () => template('
default')(),
}),
),
})
@@ -1505,10 +1505,10 @@ describe('defineVaporCustomElement', () => {
const App = {
setup() {
return createPlainElement('my-el-two-teleport-child', null, {
- default: withVaporCtx(() => [
+ default: () => [
template('
header
')(),
template('
body')(),
- ]),
+ ],
})
},
}
@@ -1556,10 +1556,10 @@ describe('defineVaporCustomElement', () => {
const App = {
setup() {
return createPlainElement('my-el-two-teleport-child-0', null, {
- default: withVaporCtx(() => [
+ default: () => [
template('
header
')(),
template('
body')(),
- ]),
+ ],
})
},
}
@@ -1591,7 +1591,7 @@ describe('defineVaporCustomElement', () => {
const ChildWrapper = {
setup() {
return createPlainElement('my-el-child-shadow-false', null, {
- default: withVaporCtx(() => template('child')()),
+ default: () => template('child')(),
})
},
}
diff --git a/packages/runtime-vapor/__tests__/dom/templateRef.spec.ts b/packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
index 536ae965eb3..c86eb48de08 100644
--- a/packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
+++ b/packages/runtime-vapor/__tests__/dom/templateRef.spec.ts
@@ -12,7 +12,6 @@ import {
insert,
renderEffect,
template,
- withVaporCtx,
} from '../../src'
import { compile, makeRender, runtimeDom, runtimeVapor } from '../_utils'
import {
@@ -613,11 +612,11 @@ describe('api: template ref', () => {
render() {
const setRef = createTemplateRefSetter()
const n0 = createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
n = document.createElement('div')
setRef(n, 'foo')
return n
- }),
+ },
})
return n0
},
@@ -641,11 +640,11 @@ describe('api: template ref', () => {
setup() {
const setRef = createTemplateRefSetter()
const n0 = createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
n = document.createElement('div')
setRef(n, r)
return n
- }),
+ },
})
return n0
},
@@ -670,11 +669,11 @@ describe('api: template ref', () => {
r = useTemplateRef('foo')
const setRef = createTemplateRefSetter()
const n0 = createComponent(Child, null, {
- default: withVaporCtx(() => {
+ default: () => {
n = document.createElement('div')
setRef(n, 'foo')
return n
- }),
+ },
})
return n0
},
diff --git a/packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts b/packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts
index 1f73df6e0a8..0c5b50725c1 100644
--- a/packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts
+++ b/packages/runtime-vapor/__tests__/helpers/useCssVars.spec.ts
@@ -9,7 +9,6 @@ import {
setStyle,
template,
useVaporCssVars,
- withVaporCtx,
} from '@vue/runtime-vapor'
import { nextTick, onMounted, reactive, ref } from '@vue/runtime-core'
import { makeRender } from '../_utils'
@@ -246,14 +245,14 @@ describe('useVaporCssVars', () => {
VaporTeleport,
{ to: () => target },
{
- default: withVaporCtx(() => {
+ default: () => {
const n0 = template('
', true)()
const n1 = createIf(
() => toggle.value,
() => template('
', true)(),
)
return [n0, n1]
- }),
+ },
},
)
},
@@ -286,7 +285,7 @@ describe('useVaporCssVars', () => {
VaporTeleport,
{ to: () => target, disabled: () => true },
{
- default: withVaporCtx(() => template('
', true)()),
+ default: () => template('
', true)(),
},
)
},
diff --git a/packages/runtime-vapor/__tests__/scopeId.spec.ts b/packages/runtime-vapor/__tests__/scopeId.spec.ts
index 4689c1b6b7d..04b54e7d1cb 100644
--- a/packages/runtime-vapor/__tests__/scopeId.spec.ts
+++ b/packages/runtime-vapor/__tests__/scopeId.spec.ts
@@ -293,9 +293,9 @@ describe('scopeId', () => {
Slotted,
null,
{
- default: withVaporCtx(() => {
+ default: () => {
return template('
')()
- }),
+ },
},
true,
)
diff --git a/packages/runtime-vapor/src/apiCreateFor.ts b/packages/runtime-vapor/src/apiCreateFor.ts
index 1ef4d5d8bec..5e46056b3b2 100644
--- a/packages/runtime-vapor/src/apiCreateFor.ts
+++ b/packages/runtime-vapor/src/apiCreateFor.ts
@@ -39,7 +39,6 @@ import {
isLastInsertion,
resetInsertionState,
} from './insertionState'
-import { triggerTransitionGroupUpdate } from './components/TransitionGroup'
class ForBlock extends VaporFragment {
scope: EffectScope | undefined
@@ -131,12 +130,6 @@ export const createFor = (
newBlocks = new Array(newLength)
let isFallback = false
- // trigger TransitionGroup update hooks
- const transitionHooks = frag.$transition
- if (transitionHooks && transitionHooks.group && isMounted) {
- triggerTransitionGroupUpdate(transitionHooks)
- }
-
const prevSub = setActiveSub()
if (!isMounted) {
diff --git a/packages/runtime-vapor/src/block.ts b/packages/runtime-vapor/src/block.ts
index 3163cb92cc2..323ef7beefc 100644
--- a/packages/runtime-vapor/src/block.ts
+++ b/packages/runtime-vapor/src/block.ts
@@ -28,8 +28,6 @@ export interface VaporTransitionHooks extends TransitionHooks {
instance: VaporComponentInstance
// mark transition hooks as disabled
disabled?: boolean
- // indicates a group transition
- group?: boolean
}
export interface TransitionOptions {
diff --git a/packages/runtime-vapor/src/component.ts b/packages/runtime-vapor/src/component.ts
index 9371c1a1abd..ae568ac3a1b 100644
--- a/packages/runtime-vapor/src/component.ts
+++ b/packages/runtime-vapor/src/component.ts
@@ -78,9 +78,9 @@ import {
type StaticSlots,
type VaporSlot,
dynamicSlotsProxyHandlers,
- getParentInstance,
+ getScopeOwner,
getSlot,
- setCurrentSlotConsumer,
+ setCurrentSlotOwner,
} from './componentSlots'
import { hmrReload, hmrRerender } from './hmr'
import {
@@ -202,24 +202,22 @@ export function createComponent(
resetInsertionState()
}
- const parentInstance = getParentInstance()
-
let prevSuspense: SuspenseBoundary | null = null
- if (__FEATURE_SUSPENSE__ && parentInstance && parentInstance.suspense) {
- prevSuspense = setParentSuspense(parentInstance.suspense)
+ if (__FEATURE_SUSPENSE__ && currentInstance && currentInstance.suspense) {
+ prevSuspense = setParentSuspense(currentInstance.suspense)
}
if (
(isSingleRoot ||
// transition has attrs fallthrough
- (parentInstance && isVaporTransition(parentInstance!.type))) &&
+ (currentInstance && isVaporTransition(currentInstance!.type))) &&
component.inheritAttrs !== false &&
- isVaporComponent(parentInstance) &&
- parentInstance.hasFallthrough
+ isVaporComponent(currentInstance) &&
+ currentInstance.hasFallthrough
) {
// check if we are the single root of the parent
// if yes, inject parent attrs as dynamic props source
- const attrs = parentInstance.attrs
+ const attrs = currentInstance.attrs
if (rawProps && rawProps !== EMPTY_OBJ) {
;((rawProps as RawProps).$ || ((rawProps as RawProps).$ = [])).push(
() => attrs,
@@ -230,8 +228,12 @@ export function createComponent(
}
// keep-alive
- if (parentInstance && parentInstance.vapor && isKeepAlive(parentInstance)) {
- const cached = (parentInstance as KeepAliveInstance).getCachedComponent(
+ if (
+ currentInstance &&
+ currentInstance.vapor &&
+ isKeepAlive(currentInstance)
+ ) {
+ const cached = (currentInstance as KeepAliveInstance).getCachedComponent(
component,
)
// @ts-expect-error
@@ -240,14 +242,12 @@ export function createComponent(
// vdom interop enabled and component is not an explicit vapor component
if (appContext.vapor && !component.__vapor) {
- const prevSlotConsumer = setCurrentSlotConsumer(null)
const frag = appContext.vapor.vdomMount(
component as any,
- parentInstance as any,
+ currentInstance as any,
rawProps,
rawSlots,
)
- setCurrentSlotConsumer(prevSlotConsumer)
if (!isHydrating) {
if (_insertionParent) insert(frag, _insertionParent, _insertionAnchor)
} else {
@@ -280,11 +280,10 @@ export function createComponent(
rawSlots as RawSlots,
appContext,
once,
- parentInstance,
)
- // set currentSlotConsumer to null to avoid affecting the child components
- const prevSlotConsumer = setCurrentSlotConsumer(null)
+ // reset currentSlotOwner to null to avoid affecting the child components
+ const prevSlotOwner = setCurrentSlotOwner(null)
// HMR
if (__DEV__) {
@@ -347,12 +346,12 @@ export function createComponent(
endMeasure(instance, 'init')
}
- if (__FEATURE_SUSPENSE__ && parentInstance && parentInstance.suspense) {
+ if (__FEATURE_SUSPENSE__ && currentInstance && currentInstance.suspense) {
setParentSuspense(prevSuspense)
}
- // restore currentSlotConsumer to previous value after setupFn is called
- setCurrentSlotConsumer(prevSlotConsumer)
+ // restore currentSlotOwner to previous value after setupFn is called
+ setCurrentSlotOwner(prevSlotOwner)
onScopeDispose(() => unmountComponent(instance), true)
if (_insertionParent || isHydrating) {
@@ -594,19 +593,19 @@ export class VaporComponentInstance implements GenericComponentInstance {
rawSlots?: RawSlots | null,
appContext?: GenericAppContext,
once?: boolean,
- parent: GenericComponentInstance | null = currentInstance,
) {
this.vapor = true
this.uid = nextUid()
this.type = comp
- this.parent = parent
- this.root = parent ? parent.root : this
+ this.parent = currentInstance
- if (parent) {
- this.appContext = parent.appContext
- this.provides = parent.provides
- this.ids = parent.ids
+ if (currentInstance) {
+ this.root = currentInstance.root
+ this.appContext = currentInstance.appContext
+ this.provides = currentInstance.provides
+ this.ids = currentInstance.ids
} else {
+ this.root = this
this.appContext = appContext || emptyContext
this.provides = Object.create(this.appContext.provides)
this.ids = ['', 0, 0]
@@ -655,7 +654,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
: rawSlots
: EMPTY_OBJ
- this.scopeId = currentInstance && currentInstance.type.__scopeId
+ this.scopeId = getCurrentScopeId()
// apply custom element special handling
if (comp.ce) {
@@ -745,7 +744,7 @@ export function createPlainElement(
;(el as any).$root = isSingleRoot
if (!isHydrating) {
- const scopeId = currentInstance!.type.__scopeId
+ const scopeId = getCurrentScopeId()
if (scopeId) setScopeId(el, [scopeId])
}
@@ -1030,3 +1029,8 @@ function handleSetupResult(
popWarningContext()
}
}
+
+export function getCurrentScopeId(): string | undefined {
+ const scopeOwner = getScopeOwner()
+ return scopeOwner ? scopeOwner.type.__scopeId : undefined
+}
diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts
index b450e077a14..b0c50917f64 100644
--- a/packages/runtime-vapor/src/componentSlots.ts
+++ b/packages/runtime-vapor/src/componentSlots.ts
@@ -6,7 +6,6 @@ import {
currentInstance,
isAsyncWrapper,
isRef,
- setCurrentInstance,
} from '@vue/runtime-dom'
import type { LooseRawProps, VaporComponentInstance } from './component'
import { renderEffect } from './renderEffect'
@@ -124,42 +123,47 @@ export function getSlot(
}
}
-export let currentSlotConsumer: GenericComponentInstance | null = null
+/**
+ * Tracks the slot owner (the component that defines the slot content).
+ * This is used for:
+ * 1. Getting the correct rawSlots in forwarded slots (via createSlot)
+ * 2. Inheriting the slot owner's scopeId
+ */
+export let currentSlotOwner: VaporComponentInstance | null = null
-export function setCurrentSlotConsumer(
- consumer: GenericComponentInstance | null,
-): GenericComponentInstance | null {
+export function setCurrentSlotOwner(
+ owner: VaporComponentInstance | null,
+): VaporComponentInstance | null {
try {
- return currentSlotConsumer
+ return currentSlotOwner
} finally {
- currentSlotConsumer = consumer
+ currentSlotOwner = owner
}
}
/**
- * use currentSlotConsumer as parent, the currentSlotConsumer will be reset to null
- * before setupFn call to avoid affecting children and restore to previous value
- * after setupFn is called
+ * Get the effective slot instance for accessing rawSlots and scopeId.
+ * Prefers currentSlotOwner (if inside a slot), falls back to currentInstance.
*/
-export function getParentInstance(): GenericComponentInstance | null {
- return currentSlotConsumer || currentInstance
+export function getScopeOwner(): VaporComponentInstance | null {
+ return (currentSlotOwner || currentInstance) as VaporComponentInstance | null
}
/**
- * Wrap a slot function to memoize currentInstance
- * 1. ensure correct currentInstance in forwarded slots
- * 2. elements created in the slot inherit the slot owner's scopeId
+ * Wrap a slot function to track the slot owner.
+ *
+ * This ensures:
+ * 1. createSlot gets rawSlots from the correct component (slot owner)
+ * 2. Elements inherit the slot owner's scopeId
*/
export function withVaporCtx(fn: Function): BlockFn {
- const owner = currentInstance
+ const owner = currentInstance as VaporComponentInstance
return (...args: any[]) => {
- const prev = setCurrentInstance(owner)
- const prevConsumer = setCurrentSlotConsumer(prev[0])
+ const prevOwner = setCurrentSlotOwner(owner)
try {
return fn(...args)
} finally {
- setCurrentInstance(...prev)
- setCurrentSlotConsumer(prevConsumer)
+ setCurrentSlotOwner(prevOwner)
}
}
}
@@ -176,7 +180,7 @@ export function createSlot(
const _isLastInsertion = isLastInsertion
if (!isHydrating) resetInsertionState()
- const instance = currentInstance as VaporComponentInstance
+ const instance = getScopeOwner()!
const rawSlots = instance.rawSlots
const slotProps = rawProps
? new Proxy(rawProps, rawPropsProxyHandlers)
diff --git a/packages/runtime-vapor/src/components/Teleport.ts b/packages/runtime-vapor/src/components/Teleport.ts
index f83da4f8bda..9379cdabdbe 100644
--- a/packages/runtime-vapor/src/components/Teleport.ts
+++ b/packages/runtime-vapor/src/components/Teleport.ts
@@ -3,6 +3,7 @@ import {
MismatchTypes,
type TeleportProps,
type TeleportTargetElement,
+ currentInstance,
isMismatchAllowed,
isTeleportDeferred,
isTeleportDisabled,
@@ -31,7 +32,6 @@ import {
setCurrentHydrationNode,
} from '../dom/hydration'
import { applyTransitionHooks } from './Transition'
-import { getParentInstance } from '../componentSlots'
export const VaporTeleportImpl = {
name: 'VaporTeleport',
@@ -62,7 +62,7 @@ export class TeleportFragment extends VaporFragment {
super([])
this.rawProps = props
this.rawSlots = slots
- this.parentComponent = getParentInstance()
+ this.parentComponent = currentInstance
this.anchor = isHydrating
? undefined
: __DEV__
diff --git a/packages/runtime-vapor/src/components/Transition.ts b/packages/runtime-vapor/src/components/Transition.ts
index d6666e81925..5459c29b90a 100644
--- a/packages/runtime-vapor/src/components/Transition.ts
+++ b/packages/runtime-vapor/src/components/Transition.ts
@@ -208,7 +208,7 @@ export function applyTransitionHooks(
return hooks
}
- const { props, instance, state, delayedLeave, group } = hooks
+ const { props, instance, state, delayedLeave } = hooks
let resolvedHooks = resolveTransitionHooks(
child,
props,
@@ -217,7 +217,6 @@ export function applyTransitionHooks(
hooks => (resolvedHooks = hooks as VaporTransitionHooks),
)
resolvedHooks.delayedLeave = delayedLeave
- resolvedHooks.group = group
child.$transition = resolvedHooks
if (isFrag) setTransitionHooksOnFragment(block, resolvedHooks)
diff --git a/packages/runtime-vapor/src/components/TransitionGroup.ts b/packages/runtime-vapor/src/components/TransitionGroup.ts
index 568c67b1f84..76d5acd1c1a 100644
--- a/packages/runtime-vapor/src/components/TransitionGroup.ts
+++ b/packages/runtime-vapor/src/components/TransitionGroup.ts
@@ -10,12 +10,11 @@ import {
hasCSSTransform,
onBeforeUpdate,
onUpdated,
- queuePostFlushCb,
resolveTransitionProps,
useTransitionState,
warn,
} from '@vue/runtime-dom'
-import { extend, invokeArrayFns, isArray } from '@vue/shared'
+import { extend, isArray } from '@vue/shared'
import {
type Block,
type TransitionBlock,
@@ -125,7 +124,6 @@ export const VaporTransitionGroup: ObjectVaporComponent = decorate({
props: cssTransitionProps,
state,
instance,
- group: true,
} as VaporTransitionHooks)
children = getTransitionBlocks(slottedBlock)
@@ -139,7 +137,6 @@ export const VaporTransitionGroup: ObjectVaporComponent = decorate({
state,
instance!,
)
- hooks.group = true
setTransitionHooks(child, hooks)
} else if (__DEV__) {
warn(`
children must be keyed`)
@@ -216,23 +213,3 @@ function getFirstConnectedChild(
if (el.isConnected) return el
}
}
-
-/**
- * The implementation of TransitionGroup relies on the onBeforeUpdate and onUpdated hooks.
- * However, when the slot content of TransitionGroup updates, it does not trigger the
- * onBeforeUpdate and onUpdated hooks. Therefore, it is necessary to manually trigger
- * the TransitionGroup update hooks to ensure its proper work.
- */
-export function triggerTransitionGroupUpdate(
- transition: VaporTransitionHooks,
-): void {
- const { instance } = transition
- if (!instance.isUpdating) {
- instance.isUpdating = true
- if (instance.bu) invokeArrayFns(instance.bu)
- queuePostFlushCb(() => {
- instance.isUpdating = false
- if (instance.u) invokeArrayFns(instance.u)
- })
- }
-}
diff --git a/packages/runtime-vapor/src/fragment.ts b/packages/runtime-vapor/src/fragment.ts
index ed0b64e4246..f80f0761176 100644
--- a/packages/runtime-vapor/src/fragment.ts
+++ b/packages/runtime-vapor/src/fragment.ts
@@ -14,6 +14,7 @@ import {
type GenericComponentInstance,
type TransitionHooks,
type VNode,
+ currentInstance,
queuePostFlushCb,
setCurrentInstance,
warnExtraneousAttributes,
@@ -31,7 +32,6 @@ import {
locateFragmentEndAnchor,
locateHydrationNode,
} from './dom/hydration'
-import { getParentInstance } from './componentSlots'
import { isArray } from '@vue/shared'
import { renderEffect } from './renderEffect'
@@ -99,7 +99,6 @@ export class DynamicFragment extends VaporFragment {
constructor(anchorLabel?: string) {
super([])
- this.parentComponent = getParentInstance()
if (isHydrating) {
this.anchorLabel = anchorLabel
locateHydrationNode()
@@ -117,6 +116,7 @@ export class DynamicFragment extends VaporFragment {
}
this.current = key
+ const instance = currentInstance
const prevSub = setActiveSub()
const parent = isHydrating ? null : this.anchor.parentNode
const transition = this.$transition
@@ -136,7 +136,7 @@ export class DynamicFragment extends VaporFragment {
const mode = transition && transition.mode
if (mode) {
applyTransitionLeaveHooks(this.nodes, transition, () =>
- this.render(render, transition, parent),
+ this.render(render, transition, parent, instance),
)
parent && remove(this.nodes, parent)
if (mode === 'out-in') {
@@ -148,7 +148,7 @@ export class DynamicFragment extends VaporFragment {
}
}
- this.render(render, transition, parent)
+ this.render(render, transition, parent, instance)
if (this.fallback) {
// set fallback for nested fragments
@@ -182,6 +182,7 @@ export class DynamicFragment extends VaporFragment {
render: BlockFn | undefined,
transition: VaporTransitionHooks | undefined,
parent: ParentNode | null,
+ instance: GenericComponentInstance | null,
) {
if (render) {
// try to reuse the kept-alive scope
@@ -195,10 +196,9 @@ export class DynamicFragment extends VaporFragment {
// switch current instance to parent instance during update
// ensure that the parent instance is correct for nested components
let prev
- if (this.parentComponent && parent)
- prev = setCurrentInstance(this.parentComponent)
+ if (parent && instance) prev = setCurrentInstance(instance)
this.nodes = this.scope.run(render) || []
- if (this.parentComponent && parent) setCurrentInstance(...prev!)
+ if (parent && instance) setCurrentInstance(...prev!)
if (transition) {
this.$transition = applyTransitionHooks(this.nodes, transition)
diff --git a/packages/runtime-vapor/src/vdomInterop.ts b/packages/runtime-vapor/src/vdomInterop.ts
index 60b5aad1f44..c6a0d98bbcc 100644
--- a/packages/runtime-vapor/src/vdomInterop.ts
+++ b/packages/runtime-vapor/src/vdomInterop.ts
@@ -45,6 +45,7 @@ import {
type VaporComponent,
VaporComponentInstance,
createComponent,
+ getCurrentScopeId,
isVaporComponent,
mountComponent,
unmountComponent,
@@ -304,7 +305,6 @@ function createVDOMComponent(
rawSlots as RawSlots,
parentComponent ? parentComponent.appContext : undefined,
undefined,
- parentComponent,
)
// overwrite how the vdom instance handles props
@@ -351,7 +351,7 @@ function createVDOMComponent(
frag.nodes = vnode.el as any
}
- vnode.scopeId = (currentInstance && currentInstance.type.__scopeId) || null
+ vnode.scopeId = getCurrentScopeId() || null
vnode.slotScopeIds = currentSlotScopeIds
frag.insert = (parentNode, anchor, transition) => {