Skip to content

Commit d262db5

Browse files
committed
chore: tweaks
1 parent f135945 commit d262db5

File tree

5 files changed

+33
-55
lines changed

5 files changed

+33
-55
lines changed

packages/compiler-vapor/src/generators/component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,7 @@ function genSlotBlockWithProps(oper: SlotBlockIRNode, context: CodegenContext) {
462462

463463
if (
464464
node.type === NodeTypes.ELEMENT &&
465-
// // Not a real component
466-
// !isTeleportTag(node.tag) &&
467-
// // Needs to determine whether to activate/deactivate based on instance.parent being KeepAlive
468-
// !isKeepAliveTag(node.tag) &&
469-
// // Slot updates need to trigger TransitionGroup's onBeforeUpdate/onUpdated hook
465+
// Slot updates need to trigger TransitionGroup's onBeforeUpdate/onUpdated hook
470466
!isTransitionGroupTag(node.tag)
471467
) {
472468
// wrap with withVaporCtx to ensure correct currentInstance inside slot

packages/runtime-vapor/src/block.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,16 @@ export function setScopeId(block: Block, scopeIds: string[]): void {
252252
}
253253

254254
export function setComponentScopeId(instance: VaporComponentInstance): void {
255-
const parent = instance.parent
256-
const slotScopeOwner = instance.slotScopeOwner
257-
if (!parent && !slotScopeOwner) return
255+
const { parent, slotOwner } = instance
256+
if (!parent && !slotOwner) return
258257
// prevent setting scopeId on multi-root fragments
259258
if (isArray(instance.block) && instance.block.length > 1) return
260259

261260
const scopeIds: string[] = []
262261

263-
const slotScopeId = slotScopeOwner && slotScopeOwner.type.__scopeId
264-
const parentScopeId = parent && parent.type.__scopeId
265-
266-
if (slotScopeId) {
267-
scopeIds.push(slotScopeId)
268-
} else if (parentScopeId) {
269-
scopeIds.push(parentScopeId)
270-
}
262+
const scopeId =
263+
(slotOwner && slotOwner.type.__scopeId) || (parent && parent.type.__scopeId)
264+
if (scopeId) scopeIds.push(scopeId)
271265

272266
// inherit scopeId from vdom parent
273267
if (

packages/runtime-vapor/src/component.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import {
7272
dynamicSlotsProxyHandlers,
7373
getSlot,
7474
getSlotConsumer,
75-
getSlotScopeOwner,
75+
getSlotOwner,
7676
} from './componentSlots'
7777
import { hmrReload, hmrRerender } from './hmr'
7878
import {
@@ -180,10 +180,8 @@ export function createComponent(
180180
rawSlots?: LooseRawSlots | null,
181181
isSingleRoot?: boolean,
182182
once?: boolean,
183-
appContext: GenericAppContext = (((getSlotScopeOwner() as VaporComponentInstance | null) ||
184-
(currentInstance as VaporComponentInstance | null)) &&
185-
((getSlotScopeOwner() as VaporComponentInstance | null) ||
186-
(currentInstance as VaporComponentInstance | null))!.appContext) ||
183+
appContext: GenericAppContext = (currentInstance &&
184+
currentInstance.appContext) ||
187185
emptyContext,
188186
): VaporComponentInstance {
189187
const _insertionParent = insertionParent
@@ -196,8 +194,7 @@ export function createComponent(
196194
}
197195

198196
const parentInstance =
199-
(getSlotConsumer() as VaporComponentInstance | null) ||
200-
(currentInstance as VaporComponentInstance | null)
197+
getSlotConsumer() || (currentInstance as VaporComponentInstance | null)
201198

202199
if (
203200
isSingleRoot &&
@@ -480,8 +477,8 @@ export class VaporComponentInstance implements GenericComponentInstance {
480477

481478
slots: StaticSlots
482479

483-
// slot template owner for scope inheritance
484-
slotScopeOwner: VaporComponentInstance | null
480+
// slot owner for scopeId inheritance
481+
slotOwner?: VaporComponentInstance | null
485482

486483
// to hold vnode props / slots in vdom interop mode
487484
rawPropsRef?: ShallowRef<any>
@@ -609,7 +606,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
609606
: rawSlots
610607
: EMPTY_OBJ
611608

612-
this.slotScopeOwner = getSlotScopeOwner() as VaporComponentInstance | null
609+
this.slotOwner = getSlotOwner()
613610

614611
// apply custom element special handling
615612
if (comp.ce) {
@@ -683,7 +680,7 @@ export function createPlainElement(
683680
;(el as any).$root = isSingleRoot
684681

685682
if (!isHydrating) {
686-
const scopeOwner = getSlotScopeOwner() || currentInstance
683+
const scopeOwner = getSlotOwner() || currentInstance
687684
const scopeId = scopeOwner && scopeOwner.type.__scopeId
688685
if (scopeId) setScopeId(el, [scopeId])
689686
}

packages/runtime-vapor/src/componentSlots.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,26 @@ export function getSlot(
125125
// Tracks slot execution context: the owner that defined the slot, and the
126126
// consumer that is currently rendering it.
127127
const slotOwnerStack: (VaporComponentInstance | null)[] = []
128-
const slotConsumerStack: (GenericComponentInstance | null)[] = []
128+
const slotConsumerStack: (VaporComponentInstance | null)[] = []
129129

130-
export function getSlotScopeOwner(): GenericComponentInstance | null {
130+
export function getSlotOwner(): VaporComponentInstance | null {
131131
return slotOwnerStack.length > 0
132132
? slotOwnerStack[slotOwnerStack.length - 1]
133133
: null
134134
}
135135

136-
export function getSlotConsumer(): GenericComponentInstance | null {
136+
export function getSlotConsumer(): VaporComponentInstance | null {
137137
return slotConsumerStack.length > 0
138138
? slotConsumerStack[slotConsumerStack.length - 1]
139139
: null
140140
}
141141

142142
export function withVaporCtx(fn: Function): BlockFn {
143-
const owner =
144-
(currentInstance as VaporComponentInstance | null) ||
145-
(getSlotScopeOwner() as VaporComponentInstance | null)
146-
147-
const ownerInstance = owner!
143+
const ownerInstance = currentInstance as VaporComponentInstance | null
148144
return (...args: any[]) => {
149145
const prev = setCurrentInstance(ownerInstance)
150146
slotOwnerStack.push(ownerInstance)
151-
slotConsumerStack.push(prev[0])
147+
slotConsumerStack.push(prev[0] as VaporComponentInstance | null)
152148
try {
153149
return fn(...args)
154150
} finally {
@@ -170,25 +166,21 @@ export function createSlot(
170166
const _isLastInsertion = isLastInsertion
171167
if (!isHydrating) resetInsertionState()
172168

173-
const slotContext =
174-
(currentInstance as VaporComponentInstance | null) ||
175-
(getSlotScopeOwner() as VaporComponentInstance | null)
176-
const owner =
177-
(getSlotScopeOwner() as VaporComponentInstance | null) || slotContext!
178-
const rawSlots = slotContext!.rawSlots
169+
const instance = (currentInstance as VaporComponentInstance) || getSlotOwner()
170+
const ownerInstance = getSlotOwner() || (instance! as VaporComponentInstance)
171+
const rawSlots = instance!.rawSlots
179172
const slotProps = rawProps
180173
? new Proxy(rawProps, rawPropsProxyHandlers)
181174
: EMPTY_OBJ
182175

183176
let fragment: DynamicFragment
184-
const contextInstance = owner
185177
if (isRef(rawSlots._)) {
186178
if (isHydrating) locateHydrationNode()
187-
fragment = contextInstance.appContext.vapor!.vdomSlot(
179+
fragment = ownerInstance.appContext.vapor!.vdomSlot(
188180
rawSlots._,
189181
name,
190182
slotProps,
191-
contextInstance,
183+
ownerInstance,
192184
fallback,
193185
)
194186
} else {
@@ -201,7 +193,7 @@ export function createSlot(
201193
// Calculate slotScopeIds once (for vdom interop)
202194
const slotScopeIds: string[] = []
203195
if (!noSlotted) {
204-
const scopeId = contextInstance.type.__scopeId
196+
const scopeId = ownerInstance.type.__scopeId
205197
if (scopeId) {
206198
slotScopeIds.push(`${scopeId}-s`)
207199
}
@@ -214,10 +206,10 @@ export function createSlot(
214206
// because in shadowRoot: false mode the slot element gets
215207
// replaced by injected content
216208
if (
217-
(slotContext as GenericComponentInstance).ce ||
218-
(slotContext!.parent &&
219-
isAsyncWrapper(slotContext!.parent) &&
220-
slotContext!.parent.ce)
209+
(instance as GenericComponentInstance).ce ||
210+
(instance!.parent &&
211+
isAsyncWrapper(instance!.parent) &&
212+
instance!.parent.ce)
221213
) {
222214
const el = createElement('slot')
223215
renderEffect(() => {
@@ -265,7 +257,7 @@ export function createSlot(
265257

266258
if (!isHydrating) {
267259
if (!noSlotted) {
268-
const scopeId = owner.type.__scopeId
260+
const scopeId = ownerInstance.type.__scopeId
269261
if (scopeId) {
270262
setScopeId(fragment, [`${scopeId}-s`])
271263
}

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
} from '@vue/shared'
6060
import { type RawProps, rawPropsProxyHandlers } from './componentProps'
6161
import type { RawSlots, VaporSlot } from './componentSlots'
62-
import { currentSlotScopeIds, getSlotScopeOwner } from './componentSlots'
62+
import { currentSlotScopeIds, getSlotOwner } from './componentSlots'
6363
import { renderEffect } from './renderEffect'
6464
import { _next, createTextNode } from './dom/node'
6565
import { optimizePropertyLookup } from './dom/prop'
@@ -335,10 +335,9 @@ function createVDOMComponent(
335335
frag.nodes = vnode.el as any
336336
}
337337

338-
const slotScopeOwner = getSlotScopeOwner()
339338
const scopeOwner =
340-
(isVaporComponent(slotScopeOwner) ? slotScopeOwner : null) ||
341-
(parentInstance && parentInstance.slotScopeOwner) ||
339+
getSlotOwner() ||
340+
(parentInstance && parentInstance.slotOwner) ||
342341
parentInstance
343342
vnode.scopeId = scopeOwner && scopeOwner.type.__scopeId!
344343
vnode.slotScopeIds = currentSlotScopeIds

0 commit comments

Comments
 (0)