0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Fix Preact Forwarded Ref components not working in astro files when React integration is enabled (#9403)

* Fix Preact Forwarded Ref components not working in astro files when React integration is enabled

* Handle undefined $$typeof

* Add changeset

* Use Symbol.for

* 

* Update .changeset/breezy-hairs-yell.md

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Ken Powers 2023-12-18 08:41:44 -05:00 committed by GitHub
parent 1e984389ba
commit 7eb9fe8a71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/react': patch
---
Prevents unsupported `forwardRef` components created by Preact from being rendered by React

View file

@ -23,6 +23,9 @@ async function check(Component, props, children) {
}
if (typeof Component !== 'function') return false;
// Preact forwarded-ref components can be functions, which React does not support
if (typeof Component === 'function' && Component['$$typeof'] === Symbol.for('react.forward_ref')) return false;
if (Component.prototype != null && typeof Component.prototype.render === 'function') {
return React.Component.isPrototypeOf(Component) || React.PureComponent.isPrototypeOf(Component);
}