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:
parent
7a0855b264
commit
0ef1613ea3
6 changed files with 28 additions and 5 deletions
5
.changeset/nasty-pandas-unite.md
Normal file
5
.changeset/nasty-pandas-unite.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/markdoc': patch
|
||||
---
|
||||
|
||||
Fixes rendering components when the `nodes.document.render` Markdoc config is set to `null`
|
|
@ -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}`;
|
||||
|
|
|
@ -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'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
1
packages/integrations/markdoc/test/fixtures/render-null/src/components/DivWrapper.astro
vendored
Normal file
1
packages/integrations/markdoc/test/fixtures/render-null/src/components/DivWrapper.astro
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
<div class="div-wrapper"><slot /></div>
|
|
@ -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 %}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue