@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/avalon",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Multi-framework islands architecture for the modern web",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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
- // This would integrate with the existing renderToHtml function
630
- // For now, return a basic structure showing the integration point
631
+ const Component = pageModule.default as (props?: Record<string, unknown>) => unknown;
632
+ const metadata = pageModule.metadata || {};
631
633
 
632
- // In the real implementation, this would:
633
- // 1. Import and use renderToHtml from '../render/ssr.ts'
634
- // 2. Create a RouteConfig from the pageModule
635
- // 3. Apply layouts using the layout resolver
636
- // 4. Return the fully rendered HTML
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
- const componentName = (pageModule.default as { name?: string })?.name || 'Page';
639
- const metadata = pageModule.metadata || {};
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" data-page="${escapeHtml(String(componentName))}" data-props='${escapeHtml(JSON.stringify(pageProps))}'>
651
- <!-- Page content rendered by Avalon SSR pipeline -->
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
  }