Skip to content

Commit

Permalink
Fix Preact Forwarded Ref components not working in astro files when R…
Browse files Browse the repository at this point in the history
…eact 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 <[email protected]>
  • Loading branch information
knpwrs and natemoo-re authored Dec 18, 2023
1 parent 1e98438 commit 7eb9fe8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-hairs-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/react': patch
---

Prevents unsupported `forwardRef` components created by Preact from being rendered by React
3 changes: 3 additions & 0 deletions packages/integrations/react/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7eb9fe8

Please sign in to comment.