mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Allow Preact components to return an empty Fragment (#599)
This commit is contained in:
parent
f83407e09a
commit
4b89f4ed08
4 changed files with 24 additions and 1 deletions
5
packages/astro/test/fixtures/preact-component/src/components/EmptyFrag.jsx
vendored
Normal file
5
packages/astro/test/fixtures/preact-component/src/components/EmptyFrag.jsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { h, Fragment } from 'preact';
|
||||
|
||||
export default function() {
|
||||
return <Fragment></Fragment>
|
||||
}
|
10
packages/astro/test/fixtures/preact-component/src/pages/frag.astro
vendored
Normal file
10
packages/astro/test/fixtures/preact-component/src/pages/frag.astro
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
import FragComponent from '../components/EmptyFrag.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Preact component returns fragment</title>
|
||||
</head>
|
||||
<body><FragComponent /></body>
|
||||
</html>
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue