wip(vapor): optimize vapor interop update

This commit is contained in:
Evan You 2025-02-04 13:11:51 +08:00
parent b20bcf1fb6
commit f09e343962
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
3 changed files with 14 additions and 16 deletions

View File

@ -189,7 +189,7 @@ export interface VaporInVDOMInterface {
anchor: any, anchor: any,
parentComponent: ComponentInternalInstance | null, parentComponent: ComponentInternalInstance | null,
): GenericComponentInstance // VaporComponentInstance ): GenericComponentInstance // VaporComponentInstance
update(n1: VNode, n2: VNode): void update(n1: VNode, n2: VNode, shouldUpdate: boolean): void
unmount(vnode: VNode, doRemove?: boolean): void unmount(vnode: VNode, doRemove?: boolean): void
move(vnode: VNode, container: any, anchor: any): void move(vnode: VNode, container: any, anchor: any): void
} }

View File

@ -1158,7 +1158,11 @@ function baseCreateRenderer(
parentComponent, parentComponent,
) )
} else { } else {
getVaporInterface(parentComponent).update(n1, n2) getVaporInterface(parentComponent).update(
n1,
n2,
shouldUpdateComponent(n1, n2, optimized),
)
} }
} else if (n1 == null) { } else if (n1 == null) {
if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) { if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {

View File

@ -1,7 +1,5 @@
import { import {
type GenericComponentInstance,
type Plugin, type Plugin,
type VNode,
type VaporInVDOMInterface, type VaporInVDOMInterface,
currentInstance, currentInstance,
shallowRef, shallowRef,
@ -16,12 +14,7 @@ import {
import { insert } from './block' import { insert } from './block'
const vaporInVDOMInterface: VaporInVDOMInterface = { const vaporInVDOMInterface: VaporInVDOMInterface = {
mount( mount(vnode, container, anchor, parentComponent) {
vnode: VNode,
container: ParentNode,
anchor: Node,
parentComponent: GenericComponentInstance | null,
) {
const selfAnchor = (vnode.anchor = document.createComment('vapor')) const selfAnchor = (vnode.anchor = document.createComment('vapor'))
container.insertBefore(selfAnchor, anchor) container.insertBefore(selfAnchor, anchor)
const prev = currentInstance const prev = currentInstance
@ -37,19 +30,20 @@ const vaporInVDOMInterface: VaporInVDOMInterface = {
return instance return instance
}, },
update(n1: VNode, n2: VNode) { update(n1, n2, shouldUpdate) {
n2.component = n1.component n2.component = n1.component
// TODO if has patchFlag, do simple diff to skip unnecessary updates if (shouldUpdate) {
;(n2.component as any as VaporComponentInstance).rawPropsRef!.value = ;(n2.component as any as VaporComponentInstance).rawPropsRef!.value =
n2.props n2.props
}
}, },
unmount(vnode: VNode, doRemove?: boolean) { unmount(vnode, doRemove) {
const container = doRemove ? vnode.anchor!.parentNode : undefined const container = doRemove ? vnode.anchor!.parentNode : undefined
unmountComponent(vnode.component as any, container) unmountComponent(vnode.component as any, container)
}, },
move(vnode: VNode, container: ParentNode, anchor: Node) { move(vnode, container, anchor) {
insert(vnode.component as any, container, anchor) insert(vnode.component as any, container, anchor)
insert(vnode.anchor as any, container, anchor) insert(vnode.anchor as any, container, anchor)
}, },