fix(runtime-vapor): normalize state&block

This commit is contained in:
三咲智子 Kevin Deng 2024-01-19 22:43:43 +08:00
parent 305a651c68
commit fc651f6905
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
1 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,5 @@
import { proxyRefs } from '@vue/reactivity' import { proxyRefs } from '@vue/reactivity'
import { type Data, invokeArrayFns } from '@vue/shared' import { type Data, invokeArrayFns, isArray, isObject } from '@vue/shared'
import { import {
type Component, type Component,
type ComponentInternalInstance, type ComponentInternalInstance,
@ -46,17 +46,27 @@ export function mountComponent(
const setupFn = const setupFn =
typeof component === 'function' ? component : component.setup typeof component === 'function' ? component : component.setup
const state = setupFn && setupFn(props, ctx) const stateOrNode = setupFn && setupFn(props, ctx)
let block: Block | null = null
if (state && '__isScriptSetup' in state) { let block: Block | undefined
instance.setupState = proxyRefs(state) let setupState: Data | undefined
block = component.render(instance.setupState)
} else { if (stateOrNode instanceof Node) {
block = state as Block block = stateOrNode
} else if (isObject(stateOrNode) && !isArray(stateOrNode)) {
setupState = proxyRefs(stateOrNode)
} }
if (!block && component.render) {
block = component.render(setupState)
}
if (block instanceof DocumentFragment) { if (block instanceof DocumentFragment) {
block = Array.from(block.childNodes) block = Array.from(block.childNodes)
} }
if (!block) {
// TODO: warn no template
block = []
}
return (instance.block = block) return (instance.block = block)
})! })!
const { bm, m } = instance const { bm, m } = instance