Skip to content

Commit

Permalink
Merge pull request #324 from preactjs/mapped-precompile-children
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Nov 13, 2023
2 parents fd43550 + 6bf321d commit 5570d10
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-beers-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-render-to-string': patch
---

Fix mapped children not working with Deno's new precompile JSX transform.
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
const value = props.exprs[i];
if (value == null) continue;

// Check if we're dealing with a vnode
if (typeof value === 'object' && value.constructor === undefined) {
// Check if we're dealing with a vnode or an array of nodes
if (
typeof value === 'object' &&
(value.constructor === undefined || isArray(value))
) {
out += _renderToString(
value,
context,
Expand All @@ -203,7 +206,7 @@ function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
);
} else {
// Values are pre-escaped by the JSX transform
out += props.exprs[i];
out += value;
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1673,5 +1673,18 @@ describe('render', () => {
let rendered = render(vnode);
expect(rendered).to.equal('<div>foo<span>bar</span></div>');
});

it('should render mapped children', () => {
let vnode = (
<Fragment
tpl={['<div>foo', '', '</div>']}
exprs={[<span>bar</span>, [<p>foo</p>, <p>bar</p>]]}
/>
);
let rendered = render(vnode);
expect(rendered).to.equal(
'<div>foo<span>bar</span><p>foo</p><p>bar</p></div>'
);
});
});
});

0 comments on commit 5570d10

Please sign in to comment.