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:
Evan You
2020-10-06 15:31:29 -04:00
parent cf2c9f6faa
commit a66e53a24f
4 changed files with 34 additions and 29 deletions

View File

@@ -74,7 +74,16 @@ export interface AppContext {
components: Record<string, Component>
directives: Record<string, Directive>
provides: Record<string | symbol, any>
reload?: () => void // HMR only
/**
* Flag for de-optimizing props normalization
* @internal
*/
deopt?: boolean
/**
* HMR only
* @internal
*/
reload?: () => void
}
type PluginInstallFunction = (app: App, ...options: any[]) => any
@@ -169,6 +178,11 @@ export function createAppAPI<HostElement>(
if (__FEATURE_OPTIONS_API__) {
if (!context.mixins.includes(mixin)) {
context.mixins.push(mixin)
// global mixin with props/emits de-optimizes props/emits
// normalization caching.
if (mixin.props || mixin.emits) {
context.deopt = true
}
} else if (__DEV__) {
warn(
'Mixin has already been applied to target app' +