fix(runtime-core): fix SSR memoery leak due to props normalization cache
fix #2225 The previous props/emits normlaization was caching normalized result per app instance, but during SSR there is a new app instance created for every request. The fix now de-opts props/emits normlaization caching when there are props/emits declared in global mixins - which is a very rare use case.
This commit is contained in:
@@ -328,11 +328,8 @@ export function normalizePropsOptions(
|
||||
appContext: AppContext,
|
||||
asMixin = false
|
||||
): NormalizedPropsOptions {
|
||||
const appId = appContext.app ? appContext.app._uid : -1
|
||||
const cache = comp.__props || (comp.__props = {})
|
||||
const cached = cache[appId]
|
||||
if (cached) {
|
||||
return cached
|
||||
if (!appContext.deopt && comp.__props) {
|
||||
return comp.__props
|
||||
}
|
||||
|
||||
const raw = comp.props
|
||||
@@ -360,7 +357,7 @@ export function normalizePropsOptions(
|
||||
}
|
||||
|
||||
if (!raw && !hasExtends) {
|
||||
return (cache[appId] = EMPTY_ARR)
|
||||
return (comp.__props = EMPTY_ARR)
|
||||
}
|
||||
|
||||
if (isArray(raw)) {
|
||||
@@ -398,7 +395,16 @@ export function normalizePropsOptions(
|
||||
}
|
||||
}
|
||||
|
||||
return (cache[appId] = [normalized, needCastKeys])
|
||||
return (comp.__props = [normalized, needCastKeys])
|
||||
}
|
||||
|
||||
function validatePropName(key: string) {
|
||||
if (key[0] !== '$') {
|
||||
return true
|
||||
} else if (__DEV__) {
|
||||
warn(`Invalid prop name: "${key}" is a reserved property.`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// use function string name to check type constructors
|
||||
@@ -441,18 +447,6 @@ function validateProps(props: Data, instance: ComponentInternalInstance) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dev only
|
||||
*/
|
||||
function validatePropName(key: string) {
|
||||
if (key[0] !== '$') {
|
||||
return true
|
||||
} else if (__DEV__) {
|
||||
warn(`Invalid prop name: "${key}" is a reserved property.`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* dev only
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user