@@ -23,6 +23,12 @@ type PreactLikeModule = {
2323 h ( type : unknown , props : unknown , ...children : unknown [ ] ) : unknown ;
2424} ;
2525
26+ type PreactLikeClassComponent = new (
27+ ...args : unknown [ ]
28+ ) => {
29+ render ( ...args : unknown [ ] ) : unknown ;
30+ } ;
31+
2632export type RuntimeComponentFactory = (
2733 props : Record < string , JsonValue > ,
2834 context : RuntimeExecutionContext ,
@@ -73,7 +79,7 @@ export async function createPreactRenderArtifact(input: {
7379
7480 try {
7581 const component = isPreactClassComponent ( input . sourceExport )
76- ? input . sourceExport
82+ ? wrapPreactClassComponent ( input . sourceExport as PreactLikeClassComponent )
7783 : wrapPreactFunctionComponent (
7884 input . sourceExport as ( props : Record < string , JsonValue > ) => unknown ,
7985 ) ;
@@ -235,6 +241,22 @@ function isPreactClassComponent(value: unknown): boolean {
235241 return typeof prototype ?. render === "function" ;
236242}
237243
244+ function wrapPreactClassComponent (
245+ sourceComponent : PreactLikeClassComponent ,
246+ ) : PreactLikeClassComponent {
247+ return class RenderifyPreactSourceClassWrapper extends sourceComponent {
248+ render ( ...args : unknown [ ] ) : unknown {
249+ const output = super . render ( ...args ) ;
250+ if ( isPlainObjectPreactOutput ( output ) ) {
251+ throw new Error (
252+ 'source.runtime=preact component returned a plain object; return JSX/h() output or use source.runtime="renderify"' ,
253+ ) ;
254+ }
255+ return output ;
256+ }
257+ } ;
258+ }
259+
238260function wrapPreactFunctionComponent (
239261 sourceComponent : ( props : Record < string , JsonValue > ) => unknown ,
240262) : ( props : Record < string , JsonValue > ) => unknown {
0 commit comments