@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.
- package/README.ko.md +200 -200
- package/README.md +200 -200
- package/package.json +54 -53
- package/src/client/Link.tsx +227 -227
- package/src/client/hooks.ts +267 -267
- package/src/client/router.ts +443 -443
- package/src/client/serialize.ts +404 -404
- package/src/filling/auth.ts +308 -308
- package/src/filling/context.ts +438 -438
- package/src/generator/index.ts +3 -3
- package/src/report/index.ts +1 -1
- package/src/runtime/compose.ts +222 -222
- package/src/runtime/index.ts +3 -3
- package/src/runtime/lifecycle.ts +381 -381
- package/src/runtime/server.ts +53 -2
- package/src/runtime/ssr.ts +336 -321
- package/src/runtime/streaming-ssr.ts +864 -0
- package/src/runtime/trace.ts +144 -144
- package/src/spec/index.ts +3 -3
- package/src/spec/load.ts +76 -76
- package/src/spec/lock.ts +56 -56
- package/src/spec/schema.ts +6 -0
package/src/runtime/server.ts
CHANGED
|
@@ -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 {
|