0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-13 22:11:20 -05:00

Fix component render in markdoc when nodes.document.render is null (#12967)

This commit is contained in:
Bjorn Lu 2025-01-13 23:59:56 +08:00 committed by GitHub
parent 7a0855b264
commit 0ef1613ea3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---
Fixes rendering components when the `nodes.document.render` Markdoc config is set to `null`

View file

@ -40,7 +40,11 @@ export type TreeNode =
function renderTreeNodeToFactoryResult(result: SSRResult, treeNode: TreeNode) {
if (Array.isArray(treeNode)) {
return Promise.all(treeNode.map((node) => renderTreeNodeToFactoryResult(result, node)));
return Promise.all(
treeNode.map((node) =>
renderComponent(result, 'ComponentNode', ComponentNode, { treeNode: node }),
),
);
}
if (treeNode.type === 'text') return render`${treeNode.content}`;

View file

@ -1,10 +1,15 @@
import { defineMarkdocConfig, nodes } from '@astrojs/markdoc/config';
import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
export default defineMarkdocConfig({
nodes: {
document: {
...nodes.document,
render: null,
}
}
})
},
},
tags: {
'div-wrapper': {
render: component('./src/components/DivWrapper.astro'),
},
},
});

View file

@ -0,0 +1 @@
<div class="div-wrapper"><slot /></div>

View file

@ -5,3 +5,9 @@ title: Post with render null
## Post with render null
This should render the contents inside a fragment!
{% div-wrapper %}
I'm inside a div wrapper
{% /div-wrapper %}

View file

@ -137,6 +137,8 @@ function renderNullChecks(html) {
const h2 = document.querySelector('h2');
assert.equal(h2.textContent, 'Post with render null');
assert.equal(h2.parentElement?.tagName, 'BODY');
const divWrapper = document.querySelector('.div-wrapper');
assert.equal(divWrapper.textContent, "I'm inside a div wrapper");
}
/** @param {string} html */