Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicated layout when using document driven with multiple layouts #1722

Open
Zerro97 opened this issue Dec 2, 2022 · 4 comments
Open

duplicated layout when using document driven with multiple layouts #1722

Zerro97 opened this issue Dec 2, 2022 · 4 comments

Comments

@Zerro97
Copy link

Zerro97 commented Dec 2, 2022

Environment

  • Operating System: Mac
  • Node Version: v16.16.0
  • Nuxt Version: 3.0.0
  • Package Manager: yarn@1.22.19

Reproduction

Reproduction Link: Link

Describe the bug

  1. Put NuxtLayout component in app.vue
<template>
  <div>
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </div>
</template>
  1. Enable document driven feature in nuxt.config.ts
  2. Create 2 layouts, 1 for default layout, 1 for custom layout
  3. Create 2 markdown file and specify the layouts made in previous step
---
layout: default
---
---
layout: custom
---

When using layout binding as instructed here, instead of replacing the default layout with the custom layout, custom layout is put within the <slot /> of the default layout (so two layouts showing).

Additional context

Might be related to this PR from nuxt/framework.

Logs

No response

@Zerro97
Copy link
Author

Zerro97 commented Dec 2, 2022

Moving <NuxtLayout> in app.vue to each of individual pages (in page directory) solves the problem.

It seems like the layout defined in app.vue is used no matter whether we define the layout in frontmatter of markdown file.

@Atinux
Copy link
Member

Atinux commented Dec 2, 2022

Actually we don't recommend to use the in app.vue until Vue 3 fixes a bug with Suspense and nested elements.

@garyo
Copy link

garyo commented Jan 19, 2023

I'm using latest nuxt-content with document-driven, and I just discovered I don't even have an app.vue at all! But everything seems to work OK. Is that expected? Perhaps it's just using the one from @nuxt/content/dist/runtime/app.vue (which just contains <NuxtPage />)?

@Zerro97
Copy link
Author

Zerro97 commented Feb 14, 2023

I actually got curious about the cause of this behavior so I took a look at the source code..


There is injectPage option in nuxt.config, which determines whether to inject document-driven.vue page into existing nuxt pages during pages:extend nuxt hook.

So, this document-driven.vue page is catch-all [slug].vue page and is used for fetching the page data from markdown files (page data is probably set/fetched at defineNuxtPlugin) and pass them to ContentRenderer which then creates HTML page from the content.

document-driven.vue uses <NuxtLayout> within it and document-driven.vue itself is a page that is injected into <NuxtPage> in app.vue. So if we define <NuxtLayout> in app.vue and choose to inject document-driven.vue into the existing pages, there will be 2 layouts showing, one from app.vue and the other from document-driven.vue.

We can choose not to inject document-driven.vue by setting injectPage to false. So in this case, only the layout defined in app.vue will be shown...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants