|
|
@@ -7,6 +7,7 @@ import {
|
|
|
unmountComponent,
|
|
|
} from './component'
|
|
|
import {
|
|
|
+ type App,
|
|
|
type AppMountFn,
|
|
|
type AppUnmountFn,
|
|
|
type CreateAppFunction,
|
|
|
@@ -20,6 +21,7 @@ import {
|
|
|
import type { RawProps } from './componentProps'
|
|
|
import { getGlobalThis } from '@vue/shared'
|
|
|
import { optimizePropertyLookup } from './dom/prop'
|
|
|
+import { withHydration } from './dom/hydrate'
|
|
|
|
|
|
let _createApp: CreateAppFunction<ParentNode, VaporComponent>
|
|
|
|
|
|
@@ -28,6 +30,9 @@ const mountApp: AppMountFn<ParentNode> = (app, container) => {
|
|
|
|
|
|
// clear content before mounting
|
|
|
if (container.nodeType === 1 /* Node.ELEMENT_NODE */) {
|
|
|
+ if (__DEV__ && container.childNodes.length) {
|
|
|
+ warn('mount target container is not empty and will be cleared.')
|
|
|
+ }
|
|
|
container.textContent = ''
|
|
|
}
|
|
|
|
|
|
@@ -38,21 +43,38 @@ const mountApp: AppMountFn<ParentNode> = (app, container) => {
|
|
|
false,
|
|
|
app._context,
|
|
|
)
|
|
|
-
|
|
|
mountComponent(instance, container)
|
|
|
flushOnAppMount()
|
|
|
|
|
|
- return instance
|
|
|
+ return instance!
|
|
|
+}
|
|
|
+
|
|
|
+let _hydrateApp: CreateAppFunction<ParentNode, VaporComponent>
|
|
|
+
|
|
|
+const hydrateApp: AppMountFn<ParentNode> = (app, container) => {
|
|
|
+ optimizePropertyLookup()
|
|
|
+
|
|
|
+ let instance: VaporComponentInstance
|
|
|
+ withHydration(container, () => {
|
|
|
+ instance = createComponent(
|
|
|
+ app._component,
|
|
|
+ app._props as RawProps,
|
|
|
+ null,
|
|
|
+ false,
|
|
|
+ app._context,
|
|
|
+ )
|
|
|
+ mountComponent(instance, container)
|
|
|
+ flushOnAppMount()
|
|
|
+ })
|
|
|
+
|
|
|
+ return instance!
|
|
|
}
|
|
|
|
|
|
const unmountApp: AppUnmountFn = app => {
|
|
|
unmountComponent(app._instance as VaporComponentInstance, app._container)
|
|
|
}
|
|
|
|
|
|
-export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
|
|
|
- comp,
|
|
|
- props,
|
|
|
-) => {
|
|
|
+function prepareApp() {
|
|
|
// compile-time feature flags check
|
|
|
if (__ESM_BUNDLER__ && !__TEST__) {
|
|
|
initFeatureFlags()
|
|
|
@@ -63,10 +85,9 @@ export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
|
|
|
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
|
|
|
setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target)
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp, getExposed)
|
|
|
- const app = _createApp(comp, props)
|
|
|
-
|
|
|
+function postPrepareApp(app: App) {
|
|
|
if (__DEV__) {
|
|
|
app.config.globalProperties = new Proxy(
|
|
|
{},
|
|
|
@@ -84,5 +105,27 @@ export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
|
|
|
container = normalizeContainer(container) as ParentNode
|
|
|
return mount(container, ...args)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
|
|
|
+ comp,
|
|
|
+ props,
|
|
|
+) => {
|
|
|
+ prepareApp()
|
|
|
+ if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp, getExposed)
|
|
|
+ const app = _createApp(comp, props)
|
|
|
+ postPrepareApp(app)
|
|
|
+ return app
|
|
|
+}
|
|
|
+
|
|
|
+export const createVaporSSRApp: CreateAppFunction<
|
|
|
+ ParentNode,
|
|
|
+ VaporComponent
|
|
|
+> = (comp, props) => {
|
|
|
+ prepareApp()
|
|
|
+ if (!_hydrateApp)
|
|
|
+ _hydrateApp = createAppAPI(hydrateApp, unmountApp, getExposed)
|
|
|
+ const app = _hydrateApp(comp, props)
|
|
|
+ postPrepareApp(app)
|
|
|
return app
|
|
|
}
|