feat: allow `enhanceApp` to return a `Promise` (#1760)

Co-authored-by: Nick Borko <nick.borko@gmail.com>
pull/1772/head
Divyansh Singh 2 years ago committed by GitHub
parent 3b7ff8d66e
commit 01ac579187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -38,7 +38,7 @@ A VitePress custom theme is simply an object containing four properties and is d
interface Theme {
Layout: Component // Vue 3 component
NotFound?: Component
enhanceApp?: (ctx: EnhanceAppContext) => void
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
setup?: () => void
}

@ -52,7 +52,7 @@ const VitePressApp = defineComponent({
}
})
export function createApp() {
export async function createApp() {
const router = newRouter()
const app = newApp()
@ -77,7 +77,7 @@ export function createApp() {
})
if (Theme.enhanceApp) {
Theme.enhanceApp({
await Theme.enhanceApp({
app,
router,
siteData: siteDataRef
@ -127,12 +127,12 @@ function newRouter(): Router {
}
if (inBrowser) {
const { app, router, data } = createApp()
// wait until page component is fetched before mounting
router.go().then(() => {
// dynamically update head tags
useUpdateHead(router.route, data.site)
app.mount('#app')
createApp().then(({ app, router, data }) => {
// wait until page component is fetched before mounting
router.go().then(() => {
// dynamically update head tags
useUpdateHead(router.route, data.site)
app.mount('#app')
})
})
}

@ -3,7 +3,7 @@ import { createApp } from './index.js'
import { renderToString } from 'vue/server-renderer'
export async function render(path: string) {
const { app, router } = createApp()
const { app, router } = await createApp()
await router.go(path)
return renderToString(app)
}

@ -1,6 +1,6 @@
import type { App, Ref, Component } from 'vue'
import type { Router } from './router.js'
import type { SiteData } from '../shared.js'
import type { Awaitable, SiteData } from '../shared.js'
export interface EnhanceAppContext {
app: App
@ -11,6 +11,6 @@ export interface EnhanceAppContext {
export interface Theme {
Layout: Component
NotFound?: Component
enhanceApp?: (ctx: EnhanceAppContext) => void
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
setup?: () => void
}

Loading…
Cancel
Save