Skip to content

Commit

Permalink
fix(document-driven): ensure layout is set on hydration (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Apr 19, 2023
1 parent 1a44364 commit 05dc079
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/runtime/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import layouts from '#build/layouts'
export default defineNuxtPlugin((nuxt) => {
const moduleOptions = useRuntimeConfig()?.public?.content.documentDriven as unknown as Exclude<ModuleOptions['documentDriven'], boolean>
const isClientDBEnabled = useRuntimeConfig()?.public?.content.experimental.clientDB
const { navigation, pages, globals, surrounds } = useContentState()

/**
* Finds a layout value from a cascade of objects.
Expand Down Expand Up @@ -58,8 +59,6 @@ export default defineNuxtPlugin((nuxt) => {
return
}

const { navigation, pages, globals, surrounds } = useContentState()

// Normalize route path
const _path = withoutTrailingSlash(to.path)

Expand Down Expand Up @@ -257,7 +256,15 @@ export default defineNuxtPlugin((nuxt) => {
// TODO: Remove this (https://github.com/nuxt/framework/pull/5274)
if (to.path.includes('favicon.ico')) { return }
// Avoid calling on hash change
if (process.client && !isClientDBEnabled && to.path === from.path) { return }
if (process.client && !isClientDBEnabled && to.path === from.path) {
if (!to.meta.layout) {
const _path = withoutTrailingSlash(to.path)
if (pages.value[_path]) {
to.meta.layout = pages.value[_path].layout
}
}
return
}

const redirect = await refresh(to, false)

Expand Down

0 comments on commit 05dc079

Please sign in to comment.