Skip to content

Commit

Permalink
fix: pages server-side render (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored May 20, 2021
1 parent bee93de commit 4421651
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 1 addition & 7 deletions src/core/runtime/composables/helpers.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
10 changes: 6 additions & 4 deletions src/core/runtime/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/core/runtime/docus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

1 comment on commit 4421651

@vercel
Copy link

@vercel vercel bot commented on 4421651 May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.