|
@@ -39,6 +39,7 @@ import {
|
|
|
import { createElement } from '../dom/node'
|
|
import { createElement } from '../dom/node'
|
|
|
import { type VaporFragment, isDynamicFragment, isFragment } from '../fragment'
|
|
import { type VaporFragment, isDynamicFragment, isFragment } from '../fragment'
|
|
|
import type { EffectScope } from '@vue/reactivity'
|
|
import type { EffectScope } from '@vue/reactivity'
|
|
|
|
|
+import { isInteropEnabled } from '../vdominteropState'
|
|
|
|
|
|
|
|
export interface VaporKeepAliveContext {
|
|
export interface VaporKeepAliveContext {
|
|
|
processShapeFlag(block: Block): boolean
|
|
processShapeFlag(block: Block): boolean
|
|
@@ -154,7 +155,7 @@ const VaporKeepAliveImpl = defineVaporComponent({
|
|
|
keepAliveInstance.ctx = {
|
|
keepAliveInstance.ctx = {
|
|
|
getStorageContainer: () => storageContainer,
|
|
getStorageContainer: () => storageContainer,
|
|
|
getCachedComponent: (comp, key) => {
|
|
getCachedComponent: (comp, key) => {
|
|
|
- if (isVNode(comp)) {
|
|
|
|
|
|
|
+ if (isInteropEnabled && isVNode(comp)) {
|
|
|
return cache.get(resolveKey(comp.type, comp.key, currentBranchKey))
|
|
return cache.get(resolveKey(comp.type, comp.key, currentBranchKey))
|
|
|
}
|
|
}
|
|
|
return cache.get(resolveKey(comp, key, currentBranchKey))
|
|
return cache.get(resolveKey(comp, key, currentBranchKey))
|
|
@@ -219,7 +220,7 @@ const VaporKeepAliveImpl = defineVaporComponent({
|
|
|
const [innerBlock, interop] = getInnerBlock(block)
|
|
const [innerBlock, interop] = getInnerBlock(block)
|
|
|
if (!innerBlock || !shouldCache(innerBlock!, props, interop)) return false
|
|
if (!innerBlock || !shouldCache(innerBlock!, props, interop)) return false
|
|
|
|
|
|
|
|
- if (interop) {
|
|
|
|
|
|
|
+ if (interop && isInteropEnabled) {
|
|
|
const cacheKey = getCacheKey(innerBlock, true, currentBranchKey)
|
|
const cacheKey = getCacheKey(innerBlock, true, currentBranchKey)
|
|
|
if (cache.has(cacheKey)) {
|
|
if (cache.has(cacheKey)) {
|
|
|
innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_KEPT_ALIVE
|
|
innerBlock.vnode!.shapeFlag! |= ShapeFlags.COMPONENT_KEPT_ALIVE
|
|
@@ -228,9 +229,11 @@ const VaporKeepAliveImpl = defineVaporComponent({
|
|
|
} else {
|
|
} else {
|
|
|
const cacheKey = getCacheKey(innerBlock, false, currentBranchKey)
|
|
const cacheKey = getCacheKey(innerBlock, false, currentBranchKey)
|
|
|
if (cache.has(cacheKey)) {
|
|
if (cache.has(cacheKey)) {
|
|
|
- innerBlock!.shapeFlag! |= ShapeFlags.COMPONENT_KEPT_ALIVE
|
|
|
|
|
|
|
+ ;(innerBlock as VaporComponentInstance)!.shapeFlag! |=
|
|
|
|
|
+ ShapeFlags.COMPONENT_KEPT_ALIVE
|
|
|
}
|
|
}
|
|
|
- innerBlock!.shapeFlag! |= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
|
|
|
|
|
|
|
+ ;(innerBlock as VaporComponentInstance)!.shapeFlag! |=
|
|
|
|
|
+ ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
@@ -352,7 +355,7 @@ const shouldCache = (
|
|
|
) => {
|
|
) => {
|
|
|
const isAsync = !interop && isAsyncWrapper(block as GenericComponentInstance)
|
|
const isAsync = !interop && isAsyncWrapper(block as GenericComponentInstance)
|
|
|
const type = (
|
|
const type = (
|
|
|
- interop
|
|
|
|
|
|
|
+ interop && isInteropEnabled
|
|
|
? (block as VaporFragment).vnode!.type
|
|
? (block as VaporFragment).vnode!.type
|
|
|
: (block as GenericComponentInstance).type
|
|
: (block as GenericComponentInstance).type
|
|
|
) as GenericComponent & AsyncComponentInternalOptions
|
|
) as GenericComponent & AsyncComponentInternalOptions
|
|
@@ -376,7 +379,7 @@ const resetCachedShapeFlag = (
|
|
|
) => {
|
|
) => {
|
|
|
if (isVaporComponent(cached)) {
|
|
if (isVaporComponent(cached)) {
|
|
|
resetShapeFlag(cached)
|
|
resetShapeFlag(cached)
|
|
|
- } else {
|
|
|
|
|
|
|
+ } else if (isInteropEnabled) {
|
|
|
resetShapeFlag(cached.vnode)
|
|
resetShapeFlag(cached.vnode)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -405,7 +408,7 @@ function getCacheKey(
|
|
|
interop: boolean,
|
|
interop: boolean,
|
|
|
branchKey?: any,
|
|
branchKey?: any,
|
|
|
): CacheKey {
|
|
): CacheKey {
|
|
|
- if (interop) {
|
|
|
|
|
|
|
+ if (interop && isInteropEnabled) {
|
|
|
const frag = block as VaporFragment
|
|
const frag = block as VaporFragment
|
|
|
return resolveKey(
|
|
return resolveKey(
|
|
|
frag.vnode!.type,
|
|
frag.vnode!.type,
|
|
@@ -420,7 +423,7 @@ function getCacheKey(
|
|
|
function getInnerBlock(block: Block): InnerBlockResult {
|
|
function getInnerBlock(block: Block): InnerBlockResult {
|
|
|
if (isVaporComponent(block)) {
|
|
if (isVaporComponent(block)) {
|
|
|
return [block, false]
|
|
return [block, false]
|
|
|
- } else if (isInteropFragment(block)) {
|
|
|
|
|
|
|
+ } else if (isInteropEnabled && isInteropFragment(block)) {
|
|
|
return [block, true]
|
|
return [block, true]
|
|
|
} else if (isFragment(block)) {
|
|
} else if (isFragment(block)) {
|
|
|
return getInnerBlock(block.nodes)
|
|
return getInnerBlock(block.nodes)
|
|
@@ -434,12 +437,14 @@ function isInteropFragment(block: Block): block is VaporFragment {
|
|
|
|
|
|
|
|
function getInstanceFromCache(
|
|
function getInstanceFromCache(
|
|
|
cached: VaporComponentInstance | VaporFragment,
|
|
cached: VaporComponentInstance | VaporFragment,
|
|
|
-): GenericComponentInstance {
|
|
|
|
|
|
|
+): GenericComponentInstance | undefined {
|
|
|
if (isVaporComponent(cached)) {
|
|
if (isVaporComponent(cached)) {
|
|
|
return cached
|
|
return cached
|
|
|
}
|
|
}
|
|
|
// vdom interop
|
|
// vdom interop
|
|
|
- return cached.vnode!.component as GenericComponentInstance
|
|
|
|
|
|
|
+ if (isInteropEnabled) {
|
|
|
|
|
+ return cached.vnode!.component as GenericComponentInstance
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function activate(
|
|
export function activate(
|