@mandujs/core 0.9.17 → 0.9.19

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.
@@ -4,7 +4,7 @@ import type { BundleManifest } from "../bundler/types";
4
4
  import type { ManduFilling } from "../filling/filling";
5
5
  import { ManduContext } from "../filling/context";
6
6
  import { Router } from "./router";
7
- import { renderSSR } from "./ssr";
7
+ import { renderSSR, renderStreamingResponse } from "./ssr";
8
8
  import React from "react";
9
9
  import path from "path";
10
10
  import {
@@ -94,6 +94,12 @@ export interface ServerOptions {
94
94
  * - CorsOptions: 세부 설정
95
95
  */
96
96
  cors?: boolean | CorsOptions;
97
+ /**
98
+ * Streaming SSR 활성화
99
+ * - true: 모든 페이지에 Streaming SSR 적용
100
+ * - false: 기존 renderToString 사용 (기본값)
101
+ */
102
+ streaming?: boolean;
97
103
  }
98
104
 
99
105
  export interface ManduServer {
@@ -146,11 +152,13 @@ let serverSettings: {
146
152
  rootDir: string;
147
153
  publicDir: string;
148
154
  cors?: CorsOptions | false;
155
+ streaming: boolean;
149
156
  } = {
150
157
  isDev: false,
151
158
  rootDir: process.cwd(),
152
159
  publicDir: "public",
153
160
  cors: false,
161
+ streaming: false,
154
162
  };
155
163
 
156
164
  export function registerApiHandler(routeId: string, handler: ApiHandler): void {
@@ -377,7 +385,7 @@ async function handleRequest(req: Request, router: Router): Promise<Response> {
377
385
  });
378
386
  }
379
387
 
380
- // SSR 렌더링 (기존 로직)
388
+ // SSR 렌더링
381
389
  const appCreator = createAppFn || defaultCreateApp;
382
390
  try {
383
391
  const app = appCreator({
@@ -392,6 +400,41 @@ async function handleRequest(req: Request, router: Router): Promise<Response> {
392
400
  ? { [route.id]: { serverData: loaderData } }
393
401
  : undefined;
394
402
 
403
+ // Streaming SSR 모드 결정
404
+ // 우선순위: route.streaming > serverSettings.streaming
405
+ const useStreaming = route.streaming !== undefined
406
+ ? route.streaming
407
+ : serverSettings.streaming;
408
+
409
+ if (useStreaming) {
410
+ return await renderStreamingResponse(app, {
411
+ title: `${route.id} - Mandu`,
412
+ isDev: serverSettings.isDev,
413
+ hmrPort: serverSettings.hmrPort,
414
+ routeId: route.id,
415
+ routePattern: route.pattern,
416
+ hydration: route.hydration,
417
+ bundleManifest: serverSettings.bundleManifest,
418
+ criticalData: loaderData as Record<string, unknown> | undefined,
419
+ enableClientRouter: true,
420
+ onShellReady: () => {
421
+ if (serverSettings.isDev) {
422
+ console.log(`[Mandu Streaming] Shell ready: ${route.id}`);
423
+ }
424
+ },
425
+ onMetrics: (metrics) => {
426
+ if (serverSettings.isDev) {
427
+ console.log(`[Mandu Streaming] Metrics for ${route.id}:`, {
428
+ shellReadyTime: `${metrics.shellReadyTime}ms`,
429
+ allReadyTime: `${metrics.allReadyTime}ms`,
430
+ hasError: metrics.hasError,
431
+ });
432
+ }
433
+ },
434
+ });
435
+ }
436
+
437
+ // 기존 renderToString 방식
395
438
  return renderSSR(app, {
396
439
  title: `${route.id} - Mandu`,
397
440
  isDev: serverSettings.isDev,
@@ -447,6 +490,7 @@ export function startServer(manifest: RoutesManifest, options: ServerOptions = {
447
490
  bundleManifest,
448
491
  publicDir = "public",
449
492
  cors = false,
493
+ streaming = false,
450
494
  } = options;
451
495
 
452
496
  // CORS 옵션 파싱
@@ -460,6 +504,7 @@ export function startServer(manifest: RoutesManifest, options: ServerOptions = {
460
504
  rootDir,
461
505
  publicDir,
462
506
  cors: corsOptions,
507
+ streaming,
463
508
  };
464
509
 
465
510
  const router = new Router(manifest.routes);
@@ -491,8 +536,14 @@ export function startServer(manifest: RoutesManifest, options: ServerOptions = {
491
536
  if (corsOptions) {
492
537
  console.log(`🌐 CORS enabled`);
493
538
  }
539
+ if (streaming) {
540
+ console.log(`🌊 Streaming SSR enabled`);
541
+ }
494
542
  } else {
495
543
  console.log(`🥟 Mandu server running at http://${hostname}:${port}`);
544
+ if (streaming) {
545
+ console.log(`🌊 Streaming SSR enabled`);
546
+ }
496
547
  }
497
548
 
498
549
  return {