Allow Preact components to return an empty Fragment (#599)

This commit is contained in:
Matthew Phillips 2021-07-01 15:30:48 -04:00 committed by GitHub
parent f83407e09a
commit 4b89f4ed08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,5 @@
import { h, Fragment } from 'preact';
export default function() {
return <Fragment></Fragment>
}

View file

@ -0,0 +1,10 @@
---
import FragComponent from '../components/EmptyFrag.jsx';
---
<html>
<head>
<title>Preact component returns fragment</title>
</head>
<body><FragComponent /></body>
</html>

View file

@ -32,4 +32,12 @@ PreactComponent('Can use hooks', async ({ runtime }) => {
assert.equal($('#world').length, 1);
});
PreactComponent('Can export a Fragment', async ({ runtime }) => {
const result = await runtime.load('/frag');
if (result.error) throw new Error(result.error);
const $ = doc(result.contents);
assert.equal($('body').children().length, 0, 'nothing rendered but it didn\'t throw.');
});
PreactComponent.run();

View file

@ -10,7 +10,7 @@ function check(Component, props, children) {
}
const { html } = renderToStaticMarkup(Component, props, children);
return Boolean(html);
return typeof html === 'string';
}
function renderToStaticMarkup(Component, props, children) {