fix: ESM SSR

pull/855/head
sapphi-red 3 years ago
parent bedd7af68f
commit 6bb09e768f

@ -60,12 +60,7 @@ export function createRouter(
const targetLoc = new URL(href, fakeHost) const targetLoc = new URL(href, fakeHost)
const pendingPath = (latestPendingPath = targetLoc.pathname) const pendingPath = (latestPendingPath = targetLoc.pathname)
try { try {
let page = loadPageModule(pendingPath) let page = await loadPageModule(pendingPath)
// only await if it returns a Promise - this allows sync resolution
// on initial render in SSR.
if ('then' in page && typeof page.then === 'function') {
page = await page
}
if (latestPendingPath === pendingPath) { if (latestPendingPath === pendingPath) {
latestPendingPath = null latestPendingPath = null

@ -25,7 +25,7 @@ export async function renderPage(
const { app, router } = createApp() const { app, router } = createApp()
const routePath = `/${page.replace(/\.md$/, '')}` const routePath = `/${page.replace(/\.md$/, '')}`
const siteData = resolveSiteDataByRoute(config.site, routePath) const siteData = resolveSiteDataByRoute(config.site, routePath)
router.go(routePath) await router.go(routePath)
// lazy require server-renderer for production build // lazy require server-renderer for production build
// prioritize project root over vitepress' own dep // prioritize project root over vitepress' own dep

Loading…
Cancel
Save