@useavalon/avalon 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/nitro/renderer.ts +24 -11
package/package.json
CHANGED
package/src/nitro/renderer.ts
CHANGED
|
@@ -44,6 +44,8 @@ import {
|
|
|
44
44
|
discoverErrorPages,
|
|
45
45
|
type ErrorHandlerOptions,
|
|
46
46
|
} from './error-handler.ts';
|
|
47
|
+
import { h } from 'preact';
|
|
48
|
+
import preactRenderToString from 'preact-render-to-string';
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Resolved page route information
|
|
@@ -626,17 +628,27 @@ async function renderPageComponent(
|
|
|
626
628
|
context: NitroRenderContext,
|
|
627
629
|
_options: SSRRenderOptions,
|
|
628
630
|
): Promise<string> {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
+
const Component = pageModule.default as (props?: Record<string, unknown>) => unknown;
|
|
632
|
+
const metadata = pageModule.metadata || {};
|
|
631
633
|
|
|
632
|
-
//
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
634
|
+
// Call the page component (supports async components)
|
|
635
|
+
let vnode: unknown;
|
|
636
|
+
try {
|
|
637
|
+
const result = Component(pageProps);
|
|
638
|
+
vnode = result instanceof Promise ? await result : result;
|
|
639
|
+
} catch (err) {
|
|
640
|
+
console.error('[renderer] Error calling page component:', err);
|
|
641
|
+
vnode = h('div', null, 'Error rendering page');
|
|
642
|
+
}
|
|
637
643
|
|
|
638
|
-
|
|
639
|
-
|
|
644
|
+
// Render the vnode to HTML string using Preact SSR
|
|
645
|
+
let pageHtml: string;
|
|
646
|
+
try {
|
|
647
|
+
pageHtml = preactRenderToString(vnode as any);
|
|
648
|
+
} catch (err) {
|
|
649
|
+
console.error('[renderer] Error in preactRenderToString:', err);
|
|
650
|
+
pageHtml = '<div>Error rendering page</div>';
|
|
651
|
+
}
|
|
640
652
|
|
|
641
653
|
return `<!DOCTYPE html>
|
|
642
654
|
<html lang="en">
|
|
@@ -647,9 +659,10 @@ async function renderPageComponent(
|
|
|
647
659
|
${metadata.description ? `<meta name="description" content="${escapeHtml(String(metadata.description))}">` : ''}
|
|
648
660
|
</head>
|
|
649
661
|
<body>
|
|
650
|
-
<div id="app"
|
|
651
|
-
|
|
662
|
+
<div id="app">
|
|
663
|
+
${pageHtml}
|
|
652
664
|
</div>
|
|
665
|
+
<script type="module" src="/src/client/main.js"></script>
|
|
653
666
|
</body>
|
|
654
667
|
</html>`;
|
|
655
668
|
}
|