diff --git a/.changeset/chilly-ladybugs-think.md b/.changeset/chilly-ladybugs-think.md
new file mode 100644
index 00000000..94172cfc
--- /dev/null
+++ b/.changeset/chilly-ladybugs-think.md
@@ -0,0 +1,5 @@
+---
+'preact-render-to-string': patch
+---
+
+Support `dangerouslySetInnerHTML={undefined}` with `renderToStringAsync`
diff --git a/src/index.js b/src/index.js
index 743f25aa..ab4146fc 100644
--- a/src/index.js
+++ b/src/index.js
@@ -125,7 +125,9 @@ export async function renderToStringAsync(vnode, context) {
// Resolving nested Promises with a maximum depth of 25
while (
- resolved.some((element) => typeof element.then === 'function') &&
+ resolved.some(
+ (element) => element && typeof element.then === 'function'
+ ) &&
count++ < 25
) {
resolved = (await Promise.all(resolved)).flat();
diff --git a/test/compat/async.test.jsx b/test/compat/async.test.jsx
index 968c12b1..12e9ac5a 100644
--- a/test/compat/async.test.jsx
+++ b/test/compat/async.test.jsx
@@ -226,4 +226,47 @@ describe('Async renderToString', () => {
expect(rendered).to.equal(`
2
`);
});
+
+ describe('dangerouslySetInnerHTML', () => {
+ it('should support dangerouslySetInnerHTML', async () => {
+ // some invalid HTML to make sure we're being flakey:
+ let html = 'asdf some text ';
+ let rendered = await renderToStringAsync(
+
+ );
+ expect(rendered).to.equal(`${html}
`);
+ });
+
+ it('should accept undefined dangerouslySetInnerHTML', async () => {
+ const Test = () => (
+
+ hi
+
+
+ );
+
+ const rendered = await renderToStringAsync();
+ expect(rendered).to.equal('hi
');
+ });
+
+ it('should accept null __html', async () => {
+ const Test = () => (
+
+ hi
+
+
+ );
+ const rendered = await renderToStringAsync();
+ expect(rendered).to.equal('hi
');
+ });
+
+ it('should override children', async () => {
+ let rendered = await renderToStringAsync(
+
+ bar
+
+ );
+ expect(rendered).to.equal('foo
');
+ });
+ });
});
diff --git a/test/render.test.jsx b/test/render.test.jsx
index 134bdb0d..db418c2b 100644
--- a/test/render.test.jsx
+++ b/test/render.test.jsx
@@ -387,16 +387,6 @@ describe('render', () => {
);
});
- it('should accept nullish __html', () => {
- const Test = (props) => (
-
- hi
-
-
- );
- expect(render()).to.equal('hi
');
- });
-
it('should apply defaultProps', () => {
const Test = (props) => ;
Test.defaultProps = {
@@ -835,6 +825,26 @@ describe('render', () => {
expect(rendered).to.equal(`${html}
`);
});
+ it('should accept undefined dangerouslySetInnerHTML', () => {
+ const Test = () => (
+
+ hi
+
+
+ );
+ expect(render()).to.equal('hi
');
+ });
+
+ it('should accept null __html', () => {
+ const Test = () => (
+
+ hi
+
+
+ );
+ expect(render()).to.equal('hi
');
+ });
+
it('should override children', () => {
let rendered = render(