Skip to content

Commit

Permalink
feat: allow enhanceApp to return a Promise (#1760)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Borko <[email protected]>
  • Loading branch information
brc-dd and nborko authored Jan 4, 2023
1 parent 3b7ff8d commit 01ac579
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/guide/theme-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 9 additions & 9 deletions src/client/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const VitePressApp = defineComponent({
}
})

export function createApp() {
export async function createApp() {
const router = newRouter()

const app = newApp()
Expand All @@ -77,7 +77,7 @@ export function createApp() {
})

if (Theme.enhanceApp) {
Theme.enhanceApp({
await Theme.enhanceApp({
app,
router,
siteData: siteDataRef
Expand Down Expand Up @@ -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')
})
})
}
2 changes: 1 addition & 1 deletion src/client/app/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions src/client/app/theme.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

0 comments on commit 01ac579

Please sign in to comment.