Skip to content

Commit 01ac579

Browse files
brc-ddnborko
andauthoredJan 4, 2023
feat: allow enhanceApp to return a Promise (#1760)
Co-authored-by: Nick Borko <nick.borko@gmail.com>
1 parent 3b7ff8d commit 01ac579

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed
 

Diff for: ‎docs/guide/theme-introduction.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ A VitePress custom theme is simply an object containing four properties and is d
3838
interface Theme {
3939
Layout: Component // Vue 3 component
4040
NotFound?: Component
41-
enhanceApp?: (ctx: EnhanceAppContext) => void
41+
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
4242
setup?: () => void
4343
}
4444

Diff for: ‎src/client/app/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const VitePressApp = defineComponent({
5252
}
5353
})
5454

55-
export function createApp() {
55+
export async function createApp() {
5656
const router = newRouter()
5757

5858
const app = newApp()
@@ -77,7 +77,7 @@ export function createApp() {
7777
})
7878

7979
if (Theme.enhanceApp) {
80-
Theme.enhanceApp({
80+
await Theme.enhanceApp({
8181
app,
8282
router,
8383
siteData: siteDataRef
@@ -127,12 +127,12 @@ function newRouter(): Router {
127127
}
128128

129129
if (inBrowser) {
130-
const { app, router, data } = createApp()
131-
132-
// wait until page component is fetched before mounting
133-
router.go().then(() => {
134-
// dynamically update head tags
135-
useUpdateHead(router.route, data.site)
136-
app.mount('#app')
130+
createApp().then(({ app, router, data }) => {
131+
// wait until page component is fetched before mounting
132+
router.go().then(() => {
133+
// dynamically update head tags
134+
useUpdateHead(router.route, data.site)
135+
app.mount('#app')
136+
})
137137
})
138138
}

Diff for: ‎src/client/app/ssr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createApp } from './index.js'
33
import { renderToString } from 'vue/server-renderer'
44

55
export async function render(path: string) {
6-
const { app, router } = createApp()
6+
const { app, router } = await createApp()
77
await router.go(path)
88
return renderToString(app)
99
}

Diff for: ‎src/client/app/theme.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { App, Ref, Component } from 'vue'
22
import type { Router } from './router.js'
3-
import type { SiteData } from '../shared.js'
3+
import type { Awaitable, SiteData } from '../shared.js'
44

55
export interface EnhanceAppContext {
66
app: App
@@ -11,6 +11,6 @@ export interface EnhanceAppContext {
1111
export interface Theme {
1212
Layout: Component
1313
NotFound?: Component
14-
enhanceApp?: (ctx: EnhanceAppContext) => void
14+
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
1515
setup?: () => void
1616
}

0 commit comments

Comments
 (0)