Fix usage of arrow functions as components (#426)
* Fix usage of arrow functions as components This fixes the React and Preact component as arrow function use-case by checking for the prototype property (arrow functions don't) * Check the prototype
This commit is contained in:
parent
5602aabfe0
commit
af03c90c2b
8 changed files with 18 additions and 2 deletions
5
packages/astro/test/fixtures/preact-component/src/components/ArrowFunction.jsx
vendored
Normal file
5
packages/astro/test/fixtures/preact-component/src/components/ArrowFunction.jsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { h, Component } from 'preact';
|
||||
|
||||
export default () => {
|
||||
return <div id="arrow-fn-component"></div>;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
import FunctionComponent from '../components/Function.jsx';
|
||||
import ArrowFunctionComponent from '../components/ArrowFunction.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
|
@ -8,5 +9,6 @@ import FunctionComponent from '../components/Function.jsx';
|
|||
</head>
|
||||
<body>
|
||||
<FunctionComponent />
|
||||
<ArrowFunctionComponent />
|
||||
</body>
|
||||
</html>
|
5
packages/astro/test/fixtures/react-component/src/components/ArrowFunction.jsx
vendored
Normal file
5
packages/astro/test/fixtures/react-component/src/components/ArrowFunction.jsx
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import React from 'react';
|
||||
|
||||
export default () => {
|
||||
return <div id="arrow-fn-component"></div>;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
import Hello from '../components/Hello.jsx';
|
||||
import Later from '../components/Goodbye.vue'; // use different specifier
|
||||
import ArrowFunction from '../components/ArrowFunction.jsx';
|
||||
---
|
||||
|
||||
<html>
|
||||
|
@ -10,5 +11,6 @@ import Later from '../components/Goodbye.vue'; // use different specifier
|
|||
<body>
|
||||
<Hello name="world" />
|
||||
<Later name="baby" />
|
||||
<ArrowFunction />
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -21,6 +21,7 @@ PreactComponent('Can load function component', async ({ runtime }) => {
|
|||
|
||||
const $ = doc(result.contents);
|
||||
assert.equal($('#fn-component').length, 1, 'Can use function components');
|
||||
assert.equal($('#arrow-fn-component').length, 1, 'Can use function components');
|
||||
});
|
||||
|
||||
PreactComponent('Can use hooks', async ({ runtime }) => {
|
||||
|
|
|
@ -39,6 +39,7 @@ React('Can load React', async () => {
|
|||
|
||||
const $ = doc(result.contents);
|
||||
assert.equal($('#react-h2').text(), 'Hello world!');
|
||||
assert.equal($('#arrow-fn-component').length, 1, 'Can use function components');
|
||||
});
|
||||
|
||||
React('Can load Vue', async () => {
|
||||
|
|
|
@ -5,7 +5,7 @@ import StaticHtml from './static-html.js';
|
|||
function check(Component, props, children) {
|
||||
if (typeof Component !== 'function') return false;
|
||||
|
||||
if (typeof Component.prototype.render === 'function') {
|
||||
if (Component.prototype != null && typeof Component.prototype.render === 'function') {
|
||||
return BaseComponent.isPrototypeOf(Component);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ const reactTypeof = Symbol.for('react.element');
|
|||
function check(Component, props, children) {
|
||||
if (typeof Component !== 'function') return false;
|
||||
|
||||
if (typeof Component.prototype.render === 'function') {
|
||||
if (Component.prototype != null && typeof Component.prototype.render === 'function') {
|
||||
return BaseComponent.isPrototypeOf(Component);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue