Skip to content

Commit 73bb298

Browse files
committed
fix(compile-vapor): ensure component node is initialized before applyVShow is called
1 parent e1d26b1 commit 73bb298

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/compiler-vapor/src/transform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ export class TransformContext<T extends AllNode = AllNode> {
176176
this.block.operation.push(...node)
177177
}
178178

179+
registerOperationAt(node: OperationNode, index: number): void {
180+
this.block.operation.splice(index, 0, node)
181+
}
182+
179183
create<T extends TemplateChildNode>(
180184
node: T,
181185
index: number,

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ import {
3333
type IRProps,
3434
type IRPropsDynamicAttribute,
3535
type IRPropsStatic,
36+
type OperationNode,
3637
type VaporDirectiveNode,
3738
} from '../ir'
3839
import { EMPTY_EXPRESSION } from './utils'
39-
import { findProp } from '../utils'
40+
import { findDir, findProp } from '../utils'
4041

4142
export const isReservedProp: (key: string) => boolean = /*#__PURE__*/ makeMap(
4243
// the leading comma is intentional so empty string "" is also included
@@ -124,7 +125,7 @@ function transformComponentElement(
124125
}
125126

126127
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT
127-
context.registerOperation({
128+
const op: OperationNode = {
128129
type: IRNodeTypes.CREATE_COMPONENT_NODE,
129130
id: context.reference(),
130131
tag,
@@ -134,7 +135,16 @@ function transformComponentElement(
134135
slots: [...context.slots],
135136
once: context.inVOnce,
136137
dynamic: dynamicComponent,
137-
})
138+
}
139+
const hasVShow = findDir(node, 'show')
140+
if (hasVShow) {
141+
const showOperationIndex = context.block.operation.findIndex(
142+
op => op.type === IRNodeTypes.DIRECTIVE && op.name === 'show',
143+
)
144+
context.registerOperationAt(op, showOperationIndex)
145+
} else {
146+
context.registerOperation(op)
147+
}
138148
context.slots = []
139149
}
140150

0 commit comments

Comments
 (0)