Skip to content

Commit 3fa4069

Browse files
committed
perf(runtime): clear container on unmount
1 parent c1c316d commit 3fa4069

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

packages/runtime-vapor/src/apiCreateVaporApp.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,23 @@ export function createVaporApp(
109109
return app
110110
},
111111

112-
mount(rootContainer): any {
112+
mount(container): any {
113113
if (!instance) {
114-
rootContainer = normalizeContainer(rootContainer)
114+
container = normalizeContainer(container)
115115
// #5571
116-
if (__DEV__ && (rootContainer as any).__vue_app__) {
116+
if (__DEV__ && (container as any).__vue_app__) {
117117
warn(
118118
`There is already an app instance mounted on the host container.\n` +
119119
` If you want to mount another app on the same host container,` +
120120
` you need to unmount the previous app by calling \`app.unmount()\` first.`,
121121
)
122122
}
123+
124+
// clear content before mounting
125+
if (container.nodeType === 1 /* Node.ELEMENT_NODE */) {
126+
container.textContent = ''
127+
}
128+
123129
instance = createComponentInstance(
124130
rootComponent,
125131
rootProps,
@@ -128,17 +134,22 @@ export function createVaporApp(
128134
context,
129135
)
130136
setupComponent(instance)
131-
render(instance, rootContainer)
137+
render(instance, container)
132138

133-
app._container = rootContainer
139+
app._container = container
134140
// for devtools and telemetry
135-
;(rootContainer as any).__vue_app__ = app
141+
;(container as any).__vue_app__ = app
136142

137143
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
138144
app._instance = instance
139145
devtoolsInitApp(app, version)
140146
}
141147

148+
if (container instanceof Element) {
149+
container.removeAttribute('v-cloak')
150+
container.setAttribute('data-v-app', '')
151+
}
152+
142153
return instance
143154
} else if (__DEV__) {
144155
warn(

packages/runtime-vapor/src/apiRender.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
setCurrentInstance,
66
validateComponentName,
77
} from './component'
8-
import { insert, querySelector, remove } from './dom/element'
8+
import { insert, querySelector } from './dom/element'
99
import { flushPostFlushCbs, queuePostFlushCb } from './scheduler'
1010
import { invokeLifecycle } from './componentLifecycle'
1111
import { VaporLifecycleHooks } from './enums'
@@ -153,13 +153,13 @@ function mountComponent(
153153
}
154154

155155
export function unmountComponent(instance: ComponentInternalInstance): void {
156-
const { container, block, scope } = instance
156+
const { container, scope } = instance
157157

158158
// hook: beforeUnmount
159159
invokeLifecycle(instance, VaporLifecycleHooks.BEFORE_UNMOUNT, 'beforeUnmount')
160160

161161
scope.stop()
162-
block && remove(block, container)
162+
container.textContent = ''
163163

164164
// hook: unmounted
165165
invokeLifecycle(

0 commit comments

Comments
 (0)