Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 13, 2024
1 parent 34bcc6a commit e11a73a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
39 changes: 15 additions & 24 deletions packages/runtime-vapor/src/apiCreateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
createComponentInstance,
currentInstance,
} from './component'
import { type Block, setupComponent } from './apiRender'
import { setupComponent } from './apiRender'
import {
type NormalizedRawProps,
type RawProps,
normalizeRawProps,
walkRawProps,
} from './componentProps'
import type { RawSlots } from './componentSlots'
import { type RawSlots, isDynamicSlotFn } from './componentSlots'
import { withAttrs } from './componentAttrs'
import { isString } from '@vue/shared'
import { renderEffect } from './renderEffect'
Expand All @@ -24,9 +24,9 @@ export function createComponent(
slots: RawSlots | null = null,
singleRoot: boolean = false,
once: boolean = false,
): ComponentInternalInstance {
): ComponentInternalInstance | HTMLElement {
if (isString(comp)) {
return fallbackComponent(comp, rawProps, slots, singleRoot)
return fallbackComponent(comp, rawProps, slots)
}

const current = currentInstance!
Expand All @@ -48,8 +48,7 @@ function fallbackComponent(
comp: string,
rawProps: RawProps | null,
slots: RawSlots | null,
singleRoot: boolean,
) {
): HTMLElement {
// eslint-disable-next-line no-restricted-globals
const el = document.createElement(comp)

Expand All @@ -62,24 +61,16 @@ function fallbackComponent(
})
}

if (slots && slots.length) {
renderEffect(() => {
let block: Block | undefined

if (slots && slots.default) {
block = slots.default()
} else {
for (const slotFn of dynamicSlots!) {
const slot = slotFn()
if (slot.name === 'default') {
block = slot.fn()
break
}
}
if (slots) {
if (!Array.isArray(slots)) slots = [slots]
for (let i = 0; i < slots.length; i++) {
const slot = slots[i]
if (!isDynamicSlotFn(slot) && slot.default) {
const block = slot.default && slot.default()
if (block) el.append(...normalizeBlock(block))
}

if (block) el.append(...normalizeBlock(block))
})
}
}
return { __return: el, rawProps }

return el
}
4 changes: 2 additions & 2 deletions packages/runtime-vapor/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function registerProp(
}
}

export function normalizeRawProps(rawProps: RawProps) {
export function normalizeRawProps(rawProps: RawProps): NormalizedRawProps {
if (!rawProps) return []
if (!isArray(rawProps)) return [rawProps]
return rawProps
Expand All @@ -172,7 +172,7 @@ export function normalizeRawProps(rawProps: RawProps) {
export function walkRawProps(
rawProps: NormalizedRawProps,
cb: (key: string, value: any, getter?: boolean) => void,
) {
): void {
for (const props of Array.from(rawProps).reverse()) {
if (isFunction(props)) {
const resolved = props()
Expand Down

0 comments on commit e11a73a

Please sign in to comment.