Skip to content

Commit

Permalink
Fix component render in markdoc when nodes.document.render is null (
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jan 13, 2025
1 parent 7a0855b commit 0ef1613
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-pandas-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdoc': patch
---

Fixes rendering components when the `nodes.document.render` Markdoc config is set to `null`
6 changes: 5 additions & 1 deletion packages/integrations/markdoc/components/TreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="div-wrapper"><slot /></div>
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
2 changes: 2 additions & 0 deletions packages/integrations/markdoc/test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 0ef1613

Please sign in to comment.