diff --git a/src/runtime/components/ContentRenderer.vue b/src/runtime/components/ContentRenderer.vue index 2a273147e..07699f53e 100644 --- a/src/runtime/components/ContentRenderer.vue +++ b/src/runtime/components/ContentRenderer.vue @@ -60,6 +60,15 @@ export default defineComponent({ const { value, excerpt, tag } = ctx + if (!value && slots?.empty) { + // Fallback on `empty` slot. + return slots.empty({ value, excerpt, tag, ...this.$attrs }) + } + + if (slots?.default) { + return slots.default({ value, excerpt, tag, ...this.$attrs }) + } + // Use built-in ContentRendererMarkdown if (value && value?._type === 'markdown' && value?.body?.children?.length) { return h( @@ -73,16 +82,6 @@ export default defineComponent({ ) } - if (value && slots?.default) { - return slots.default({ value, excerpt, tag, ...this.$attrs }) - } else if (slots?.empty) { - // Fallback on `empty` slot. - return slots.empty({ value, excerpt, tag, ...this.$attrs }) - } else if (slots?.default) { - // Fallback on `default` slot with undefined `value` if no `empty` slot. - return slots.default({ value, excerpt, tag, ...this.$attrs }) - } - // Fallback on JSON.stringify if no slot at all. return h( 'pre', diff --git a/test/features/renderer-markdown.ts b/test/features/renderer-markdown.ts index 4aacc0a45..ea711bbc0 100644 --- a/test/features/renderer-markdown.ts +++ b/test/features/renderer-markdown.ts @@ -62,5 +62,10 @@ export const testMarkdownRenderer = () => { const html = await $fetch('/features/custom-paragraph') expect(html).contains('[Paragraph]') }) + + test('override default slot', async () => { + const html = await $fetch('/features/slotted-content-renderer') + expect(html).contains('The default slot is overridden') + }) }) } diff --git a/test/fixtures/basic/pages/features/slotted-content-renderer.vue b/test/fixtures/basic/pages/features/slotted-content-renderer.vue new file mode 100644 index 000000000..6ae8cd125 --- /dev/null +++ b/test/fixtures/basic/pages/features/slotted-content-renderer.vue @@ -0,0 +1,18 @@ + + +