Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/compiler-vapor/src/generators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ export function genCreateComponent(
...genCall(
operation.dynamic && !operation.dynamic.isStatic
? helper('createDynamicComponent')
: operation.asset
: operation.isCustomElement
? helper('createComponentWithFallback')
: helper('createComponent'),
: operation.asset
? helper('createComponentWithFallback')
: helper('createComponent'),
tag,
rawProps,
rawSlots,
Expand All @@ -86,7 +88,9 @@ export function genCreateComponent(
]

function genTag() {
if (operation.dynamic) {
if (operation.isCustomElement) {
return JSON.stringify(operation.tag)
} else if (operation.dynamic) {
if (operation.dynamic.isStatic) {
return genCall(
helper('resolveDynamicComponent'),
Expand Down
1 change: 1 addition & 0 deletions packages/compiler-vapor/src/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export interface CreateComponentIRNode extends BaseIRNode {
root: boolean
once: boolean
dynamic?: SimpleExpressionNode
isCustomElement: boolean
parent?: number
anchor?: number
append?: boolean
Expand Down
12 changes: 10 additions & 2 deletions packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const transformElement: NodeTransform = (node, context) => {
)
return

const isComponent = node.tagType === ElementTypes.COMPONENT
// treat custom elements as components because the template helper cannot
// resolve them properly; they require creation via createElement
const isCustomElement = !!context.options.isCustomElement(node.tag)
const isComponent =
node.tagType === ElementTypes.COMPONENT || isCustomElement

const isDynamicComponent = isComponentTag(node.tag)
const propsResult = buildProps(
node,
Expand Down Expand Up @@ -88,6 +93,7 @@ export const transformElement: NodeTransform = (node, context) => {
singleRoot,
context,
isDynamicComponent,
isCustomElement,
)
} else {
transformNativeElement(
Expand All @@ -107,6 +113,7 @@ function transformComponentElement(
singleRoot: boolean,
context: TransformContext,
isDynamicComponent: boolean,
isCustomElement: boolean,
) {
const dynamicComponent = isDynamicComponent
? resolveDynamicComponent(node)
Expand All @@ -115,7 +122,7 @@ function transformComponentElement(
let { tag } = node
let asset = true

if (!dynamicComponent) {
if (!dynamicComponent && !isCustomElement) {
const fromSetup = resolveSetupReference(tag, context)
if (fromSetup) {
tag = fromSetup
Expand Down Expand Up @@ -160,6 +167,7 @@ function transformComponentElement(
slots: [...context.slots],
once: context.inVOnce,
dynamic: dynamicComponent,
isCustomElement,
}
context.slots = []
}
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime-core/src/apiCreateApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ export interface App<HostElement = any> {
*/
_ceVNode?: VNode

/**
* @internal vapor custom element instance
*/
_ceComponent?: GenericComponentInstance | null

/**
* v2 compat only
*/
Expand Down
11 changes: 10 additions & 1 deletion packages/runtime-core/src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ function reload(id: string, newComp: HMRComponent): void {
// create a snapshot which avoids the set being mutated during updates
const instances = [...record.instances]

if (newComp.__vapor) {
if (newComp.__vapor && !instances.some(i => i.ceReload)) {
// For multiple instances with the same __hmrId, remove styles first before reload
// to avoid the second instance's style removal deleting the first instance's
// newly added styles (since hmrReload is synchronous)
for (const instance of instances) {
// update custom element child style
if (instance.root && instance.root.ce && instance !== instance.root) {
instance.root.ce._removeChildStyle(instance.type)
}
}
for (const instance of instances) {
instance.hmrReload!(newComp)
}
Expand Down
Loading
Loading