feat: improve support for third-party React packages (#1701)
This commit is contained in:
parent
6becdc8cc0
commit
cb733cf689
2 changed files with 12 additions and 1 deletions
5
.changeset/tall-crabs-care.md
Normal file
5
.changeset/tall-crabs-care.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/renderer-react': patch
|
||||
---
|
||||
|
||||
Improve support for third-party React packages
|
|
@ -9,6 +9,12 @@ function errorIsComingFromPreactComponent(err) {
|
|||
}
|
||||
|
||||
function check(Component, props, children) {
|
||||
// Note: there are packages that do some unholy things to create "components".
|
||||
// Checking the $$typeof property catches most of these patterns.
|
||||
if (typeof Component === 'object') {
|
||||
const $$typeof = Component['$$typeof'];
|
||||
return $$typeof && $$typeof.toString().slice('Symbol('.length).startsWith('react');
|
||||
}
|
||||
if (typeof Component !== 'function') return false;
|
||||
|
||||
if (Component.prototype != null && typeof Component.prototype.render === 'function') {
|
||||
|
@ -41,10 +47,10 @@ function check(Component, props, children) {
|
|||
}
|
||||
|
||||
function renderToStaticMarkup(Component, props, children, metadata) {
|
||||
delete props['class'];
|
||||
const vnode = React.createElement(Component, {
|
||||
...props,
|
||||
children: React.createElement(StaticHtml, { value: children }),
|
||||
innerHTML: children,
|
||||
});
|
||||
let html;
|
||||
if (metadata && metadata.hydrate) {
|
||||
|
|
Loading…
Reference in a new issue