feat(nuxt): support named layout slots#20
Conversation
|
Hello, thanks for this great feature! I wanted to ask you whether it's intended to be used with the explicit wrapping within
This issue appears only when using the named slots feature you implemented in this PR without wrapping the page's content in an explicit |
|
This may be due to the heuristic page component matching I'm currently using https://github.com/KazariEX/dxup/pull/20/changes#diff-eb05991fdc60c6791b6cb89225aeaa94dac24d257ec24e0673d19d13fe9e3625R18-R22. You can clone this branch and check the result in the local playground. |
|
@udrzbarik Could you try again to see if the problem still occurs? If so, open an issue with a minimal reproduction. Before the next minor release of Nuxt, you can enable this feature early using |
|
Hi, I'm using the following setup in my package.json And the above setup for my template inside of the page, but I still seem to hit the Codegen node issue. |
|
Have you enabled |
|
Hi, I can confirm it no longer throws an error, but it doesn't seem to work for me either way. <template>
<!-- Slot inside of the `layouts/legislative.vue` -->
<slot name="breadcrumbs" />
</template><template>
<!-- Component inside of the `pages/[...slug].vue` -->
<template #breadcrumbs>
<ResolutionBreadcrumbs :canSaveDraft="isNew" />
</template>
</template>
<script setup lang="ts">
definePageMeta({
layout: {
name: 'legislative',
props: {
class: 'pb-7 max-w-325'
}
}
})
</script>It appears it doesn't throw an error regarding the codegen anymore, but it doesn't display the content of the slot either. I am using // nuxt.config.ts
// ...
// dxup setup
experimental: {
typescriptPlugin: true,
},
dxup: {
features: {
// enable namedSlots in pages
namedLayoutSlots: true,
},
},
// ... |
|
Does your layout component render default slots? Under the current implementation, not having a default slot will cause the page to hang forever. If that's not the reason, I think it's best to provide a minimal reproduction for me to investigate. |
|
Hi, yes, I have a default slot as well, here. is a the whole version of the layout. <template>
<NuxtLayout name="dashboard" :submenu :breadcrumbs>
<template v-if="$slots.breadcrumbs" #breadcrumbs>
<slot name="breadcrumbs" />
</template>
<div class="px-20 py-14">
<div :class="['mx-auto w-full', layoutClass]">
<slot />
</div>
</div>
</NuxtLayout>
</template>I even tried turning off the v-if to no avail. |
|
I’m not sure exactly where the component file you listed are located, but this feature currently only applies to components in the layouts directory. Maybe that's a pattern I'm not familiar with, but why is your layout wrapped in a |
|
The // nuxt.config.ts
pages: {
// Ignore `/components` so that it doesn't get picked up as a route
pattern: ['**/*.vue', '!**/components/**']
}As for why I have nested Layouts, I have a main layout called
I'm not sure if this answers your questions, but it's due to the specificity. The interesting thing is, that the pattern above where I wrap the same component with a named slot and the <template>
<NuxtLayout name="legislative" v-bind="layoutProps">
<!--- This works --->
<template #breadcrumbs>
<ResolutionBreadcrumbs :canSaveDraft @draftSubmit="handleDraftSubmit" />
</template>
</NuxtLayout>
</template>
<script setup lang="ts">
// but seems to require ..
definePageMeta({
layout: false
})
</script> |
|
Does this patch fix the issue? diff --git a/dist/runtime/layouts.mjs b/dist/runtime/layouts.mjs
index 9d581e0014a0b3901a3900972c5921b5966ffa62..1acc2b64c075ef0fd294623912ff11d34e2c0064 100644
--- a/dist/runtime/layouts.mjs
+++ b/dist/runtime/layouts.mjs
@@ -1,4 +1,4 @@
-import { defineComponent, h, inject, provide, shallowRef } from "vue";
+import { defineComponent, getCurrentInstance, h, inject, provide, shallowRef } from "vue";
import { NuxtLayout } from "#build/dxup/layouts.mjs";
//#region src/module/named-layout-slots/runtime/layouts.ts
const injectionKey = Symbol.for("dxup:layout-slots");
@@ -24,7 +24,8 @@ const LayoutSlot = defineComponent({
} },
setup(props, ctx) {
const { slots, ready } = inject(injectionKey);
- const render = () => slots.value[props.name]?.(ctx.attrs);
+ const currentInstance = getCurrentInstance();
+ const render = () => (slots.value[props.name] ?? currentInstance?.parent?.slots[props.name])?.(ctx.attrs);
if (import.meta.server && !slots.value[props.name]) return ready.then(() => render);
return render;
}I suspect |
Runtime support might need to be implemented within the nuxt core to ensure its compatibility with other features.The current approach results in the entire layout component being remounted when switching between pages with the same layout.Done!!!