Skip to content
Open
16 changes: 14 additions & 2 deletions packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
RootHydrateFunction,
isRuntimeOnly,
DeprecationTypes,
compatUtils
compatUtils,
effectScope
} from '@vue/runtime-core'
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
Expand Down Expand Up @@ -63,14 +64,16 @@ export const hydrate = ((...args) => {
}) as RootHydrateFunction

export const createApp = ((...args) => {
const scope = effectScope()

const app = ensureRenderer().createApp(...args)

if (__DEV__) {
injectNativeTagCheck(app)
injectCompilerOptionsCheck(app)
}

const { mount } = app
const { mount, unmount, runWithContext } = app
app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
const container = normalizeContainer(containerOrSelector)
if (!container) return
Expand Down Expand Up @@ -107,6 +110,15 @@ export const createApp = ((...args) => {
return proxy
}

app.runWithContext = <T>(fn: () => T): T => {
return scope.run(() => runWithContext(fn)) as T
}

app.unmount = () => {
scope.stop()
unmount()
}

return app
}) as CreateAppFunction<Element>

Expand Down