From 442165127e0eb1f29521b95fadd9719bf212cf7c Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Thu, 20 May 2021 19:29:55 +0430 Subject: [PATCH] fix: pages server-side render (#320) --- src/core/runtime/composables/helpers.ts | 8 +------- src/core/runtime/composables/navigation.ts | 10 ++++++---- src/core/runtime/docus.ts | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/core/runtime/composables/helpers.ts b/src/core/runtime/composables/helpers.ts index 7e18d9bb4..e34d8c010 100644 --- a/src/core/runtime/composables/helpers.ts +++ b/src/core/runtime/composables/helpers.ts @@ -1,16 +1,10 @@ import Vue from 'vue' import { DocusAddonContext } from '../../../types' -export const docusInit = async ({ context, state }: DocusAddonContext, fetch: any) => { - // Fetch on server +export const docusInit = ({ context, state }: DocusAddonContext) => { if (process.server) { - await fetch() - context.beforeNuxtRender(({ nuxtState }) => (nuxtState.docus = state)) } - - // SPA Fallback - if (process.client && !state.settings) await fetch() } export const clientAsyncData = (app, $nuxt: any) => { diff --git a/src/core/runtime/composables/navigation.ts b/src/core/runtime/composables/navigation.ts index 35f5c7e2c..2bcfa6dbc 100644 --- a/src/core/runtime/composables/navigation.ts +++ b/src/core/runtime/composables/navigation.ts @@ -117,11 +117,13 @@ export const useDocusNavigation = ({ $nuxt, context, state, api }: DocusAddonCon return withTrailingSlash(path) === withTrailingSlash(context.$contentLocalePath(to)) } - window.onNuxtReady($nuxt => { - $nuxt.$on('content:update', () => { - fetchNavigation() + if (process.client) { + window.onNuxtReady($nuxt => { + $nuxt.$on('content:update', () => { + fetchNavigation() + }) }) - }) + } return { getPageTemplate, diff --git a/src/core/runtime/docus.ts b/src/core/runtime/docus.ts index a960e7222..d3cfcbb05 100644 --- a/src/core/runtime/docus.ts +++ b/src/core/runtime/docus.ts @@ -63,7 +63,7 @@ export const createDocus = async ( await setupAddons() // Init Docus for every context - await docusInit(docusAddonContext, fetch) + await docusInit(docusAddonContext) // Workaround for async data clientAsyncData(context.app, $nuxt)