@mandujs/core 0.54.10 → 0.54.11

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.
Files changed (67) hide show
  1. package/package.json +200 -200
  2. package/scripts/postinstall-lock.ts +153 -153
  3. package/src/a11y/run-audit.ts +15 -15
  4. package/src/agent/__tests__/context.test.ts +17 -65
  5. package/src/agent/context.ts +535 -535
  6. package/src/agent/index.ts +6 -6
  7. package/src/agent/plan.ts +282 -282
  8. package/src/agent/repair.ts +171 -171
  9. package/src/agent/sync.ts +200 -200
  10. package/src/agent/types.ts +10 -18
  11. package/src/agent/verify.ts +17 -115
  12. package/src/brain/doctor/analyzer.ts +7 -7
  13. package/src/bundler/__tests__/build-runner.ts +81 -62
  14. package/src/bundler/__tests__/cold-start.test.ts +60 -60
  15. package/src/bundler/__tests__/css.test.ts +20 -20
  16. package/src/bundler/analyzer.ts +15 -15
  17. package/src/bundler/build.test.ts +120 -88
  18. package/src/bundler/build.ts +511 -511
  19. package/src/bundler/css.ts +42 -42
  20. package/src/bundler/manifest-schema.ts +21 -21
  21. package/src/bundler/plugins/__tests__/block-generated-imports.test.ts +13 -13
  22. package/src/bundler/plugins/block-generated-imports.ts +13 -13
  23. package/src/bundler/types.ts +31 -31
  24. package/src/client/island.ts +79 -79
  25. package/src/config/validate.ts +1 -1
  26. package/src/deploy/inference/context.ts +82 -82
  27. package/src/devtools/client/components/panel/islands-panel.tsx +16 -16
  28. package/src/devtools/client/components/panel/panel-container.tsx +1 -1
  29. package/src/error/formatter.ts +22 -31
  30. package/src/filling/context.ts +17 -17
  31. package/src/generator/generate.ts +30 -30
  32. package/src/generator/index.ts +3 -3
  33. package/src/generator/templates.test.ts +66 -65
  34. package/src/generator/templates.ts +210 -210
  35. package/src/guard/check.ts +9 -9
  36. package/src/guard/config-guard.ts +13 -13
  37. package/src/guard/fs-routes-policy.ts +51 -51
  38. package/src/guard/index.ts +11 -11
  39. package/src/index.ts +3 -3
  40. package/src/kitchen/api/file-api.ts +11 -11
  41. package/src/report/index.ts +1 -1
  42. package/src/resource/__tests__/generator.test.ts +6 -6
  43. package/src/resource/__tests__/schema.test.ts +14 -14
  44. package/src/resource/ddl/__tests__/emit.test.ts +165 -165
  45. package/src/resource/ddl/emit.ts +146 -146
  46. package/src/resource/generator-schema.ts +11 -11
  47. package/src/resource/generators/slot.ts +72 -72
  48. package/src/resource/schema.ts +21 -21
  49. package/src/router/client-entry.test.ts +192 -140
  50. package/src/router/client-entry.ts +516 -486
  51. package/src/router/fs-routes.ts +16 -16
  52. package/src/router/fs-scanner.ts +16 -28
  53. package/src/runtime/__tests__/devtools-adapter.test.ts +68 -68
  54. package/src/runtime/__tests__/observability-lifecycle.test.ts +103 -103
  55. package/src/runtime/__tests__/page-render-response.test.ts +103 -103
  56. package/src/runtime/__tests__/request-middleware.test.ts +70 -70
  57. package/src/runtime/devtools-adapter.ts +68 -68
  58. package/src/runtime/escape.ts +34 -34
  59. package/src/runtime/observability-lifecycle.ts +290 -290
  60. package/src/runtime/page-render-response.ts +106 -106
  61. package/src/runtime/request-middleware.ts +31 -31
  62. package/src/runtime/server.ts +243 -243
  63. package/src/runtime/ssr.ts +59 -59
  64. package/src/runtime/static-files.ts +289 -289
  65. package/src/runtime/streaming-ssr.ts +22 -22
  66. package/src/watcher/__tests__/watcher.test.ts +59 -59
  67. package/src/watcher/watcher.ts +61 -61
@@ -14,11 +14,11 @@ import { DEFAULT_SCANNER_CONFIG } from "./fs-types";
14
14
  import { scanRoutes } from "./fs-scanner";
15
15
  import { loadManduConfig } from "../config";
16
16
  import type { ManduPlugin, ManduHooks } from "../plugins/hooks";
17
- import {
18
- runOnRouteRegistered,
19
- runOnManifestBuilt,
20
- } from "../plugins/runner";
21
- import { shouldPreserveExistingClientModule } from "./client-entry";
17
+ import {
18
+ runOnRouteRegistered,
19
+ runOnManifestBuilt,
20
+ } from "../plugins/runner";
21
+ import { shouldPreserveExistingClientModule } from "./client-entry";
22
22
 
23
23
  // ═══════════════════════════════════════════════════════════════════════════
24
24
  // Types
@@ -309,17 +309,17 @@ export async function generateManifest(
309
309
  for (const route of manifest.routes) {
310
310
  const prev = existingMap.get(route.id);
311
311
  if (!prev) continue;
312
- // 사용자가 설정한 clientModule/hydration 보존.
313
- // If app/page.tsx used to be a client page and later becomes a server
314
- // page, preserving the old clientModule would leak the server graph into
315
- // the browser bundle.
316
- if (
317
- prev.clientModule &&
318
- !route.clientModule &&
319
- await shouldPreserveExistingClientModule(route, prev.clientModule, rootDir)
320
- ) {
321
- route.clientModule = prev.clientModule;
322
- }
312
+ // 사용자가 설정한 clientModule/hydration 보존.
313
+ // If app/page.tsx used to be a client page and later becomes a server
314
+ // page, preserving the old clientModule would leak the server graph into
315
+ // the browser bundle.
316
+ if (
317
+ prev.clientModule &&
318
+ !route.clientModule &&
319
+ await shouldPreserveExistingClientModule(route, prev.clientModule, rootDir)
320
+ ) {
321
+ route.clientModule = prev.clientModule;
322
+ }
323
323
  if (prev.hydration && !route.hydration) {
324
324
  route.hydration = prev.hydration;
325
325
  }
@@ -28,13 +28,12 @@ import {
28
28
  sortRoutesByPriority,
29
29
  getPatternShape,
30
30
  } from "./fs-patterns";
31
- import { mark, measure } from "../perf";
32
- import { METADATA_ROUTES } from "../routes/types";
33
- import {
34
- findRouteLevelClientComponentImports,
35
- hasUseClientDirective,
36
- resolveClientImportModulePath,
37
- } from "./client-entry";
31
+ import { mark, measure } from "../perf";
32
+ import { METADATA_ROUTES } from "../routes/types";
33
+ import {
34
+ hasUseClientDirective,
35
+ resolveRouteLevelClientEntryPath,
36
+ } from "./client-entry";
38
37
 
39
38
  // ═══════════════════════════════════════════════════════════════════════════
40
39
  // Scanner Class
@@ -233,7 +232,7 @@ export class FSScanner {
233
232
  */
234
233
  private async createRouteConfigs(
235
234
  files: ScannedFile[],
236
- rootDir: string
235
+ rootDir: string
237
236
  ): Promise<{ routes: FSRouteConfig[]; routeErrors: ScanError[] }> {
238
237
  const routes: FSRouteConfig[] = [];
239
238
  const routeErrors: ScanError[] = [];
@@ -393,26 +392,15 @@ export class FSScanner {
393
392
  conflictsWith: islands[0].absolutePath,
394
393
  });
395
394
  }
396
- } else if (file.type === "page" && pageFileContent) {
397
- // page 파일 자체에서 "use client" 확인
398
- const hasUseClient = hasUseClientDirective(pageFileContent);
399
- if (hasUseClient) {
400
- clientModule = modulePath;
401
- } else {
402
- const routeLevelClientImports = findRouteLevelClientComponentImports(pageFileContent);
403
- for (const routeLevelClientImport of routeLevelClientImports) {
404
- const resolvedClientImport = await resolveClientImportModulePath(
405
- rootDir,
406
- modulePath,
407
- routeLevelClientImport.module,
408
- );
409
- if (resolvedClientImport) {
410
- clientModule = modulePath;
411
- break;
412
- }
413
- }
414
- }
415
- }
395
+ } else if (file.type === "page" && pageFileContent) {
396
+ // page 파일 자체에서 "use client" 확인
397
+ const hasUseClient = hasUseClientDirective(pageFileContent);
398
+ if (hasUseClient) {
399
+ clientModule = modulePath;
400
+ } else {
401
+ clientModule = await resolveRouteLevelClientEntryPath(rootDir, modulePath, pageFileContent) ?? undefined;
402
+ }
403
+ }
416
404
 
417
405
  // 로딩/에러/404 모듈 찾기 — nearest-ancestor resolution.
418
406
  // Phase 18.β: `not-found.tsx` joins `loading.tsx`/`error.tsx` in
@@ -1,68 +1,68 @@
1
- import { afterEach, describe, expect, it } from "bun:test";
2
- import type { RoutesManifest } from "../../spec/schema";
3
- import {
4
- createRuntimeDevtoolsAdapter,
5
- shouldRecordRuntimeRequest,
6
- type RuntimeDevtoolsAdapter,
7
- } from "../devtools-adapter";
8
-
9
- const manifest: RoutesManifest = {
10
- version: 1,
11
- routes: [],
12
- };
13
-
14
- describe("runtime devtools adapter", () => {
15
- let adapter: RuntimeDevtoolsAdapter | null = null;
16
-
17
- afterEach(() => {
18
- adapter?.stop();
19
- adapter = null;
20
- });
21
-
22
- it("stays disabled outside dev mode", async () => {
23
- adapter = createRuntimeDevtoolsAdapter({
24
- isDev: false,
25
- rootDir: process.cwd(),
26
- manifest,
27
- guardConfig: null,
28
- });
29
-
30
- expect(adapter.kitchen).toBeNull();
31
- expect(adapter.dashboardPath).toBeNull();
32
- const response = await adapter.handleRequest(
33
- new Request("http://localhost:3000/__kitchen"),
34
- "/__kitchen"
35
- );
36
- expect(response).toBeNull();
37
- });
38
-
39
- it("dispatches Kitchen requests in dev mode", async () => {
40
- adapter = createRuntimeDevtoolsAdapter({
41
- isDev: true,
42
- rootDir: process.cwd(),
43
- manifest,
44
- guardConfig: null,
45
- });
46
-
47
- expect(adapter.kitchen).not.toBeNull();
48
- expect(adapter.dashboardPath).toBe("/__kitchen");
49
- await expect(
50
- adapter.handleRequest(new Request("http://localhost:3000/api/ping"), "/api/ping")
51
- ).resolves.toBeNull();
52
-
53
- const response = await adapter.handleRequest(
54
- new Request("http://localhost:3000/__kitchen"),
55
- "/__kitchen"
56
- );
57
- expect(response?.status).toBe(200);
58
- expect(await response?.text()).toContain("Mandu Kitchen");
59
- });
60
-
61
- it("keeps framework-internal request paths out of the Kitchen request log", () => {
62
- expect(shouldRecordRuntimeRequest("/api/ping")).toBe(true);
63
- expect(shouldRecordRuntimeRequest("/_mandu/heap")).toBe(true);
64
- expect(shouldRecordRuntimeRequest("/.mandu/client/runtime.js")).toBe(false);
65
- expect(shouldRecordRuntimeRequest("/__kitchen/api/events")).toBe(false);
66
- expect(shouldRecordRuntimeRequest("/__mandu/events/recent")).toBe(false);
67
- });
68
- });
1
+ import { afterEach, describe, expect, it } from "bun:test";
2
+ import type { RoutesManifest } from "../../spec/schema";
3
+ import {
4
+ createRuntimeDevtoolsAdapter,
5
+ shouldRecordRuntimeRequest,
6
+ type RuntimeDevtoolsAdapter,
7
+ } from "../devtools-adapter";
8
+
9
+ const manifest: RoutesManifest = {
10
+ version: 1,
11
+ routes: [],
12
+ };
13
+
14
+ describe("runtime devtools adapter", () => {
15
+ let adapter: RuntimeDevtoolsAdapter | null = null;
16
+
17
+ afterEach(() => {
18
+ adapter?.stop();
19
+ adapter = null;
20
+ });
21
+
22
+ it("stays disabled outside dev mode", async () => {
23
+ adapter = createRuntimeDevtoolsAdapter({
24
+ isDev: false,
25
+ rootDir: process.cwd(),
26
+ manifest,
27
+ guardConfig: null,
28
+ });
29
+
30
+ expect(adapter.kitchen).toBeNull();
31
+ expect(adapter.dashboardPath).toBeNull();
32
+ const response = await adapter.handleRequest(
33
+ new Request("http://localhost:3000/__kitchen"),
34
+ "/__kitchen"
35
+ );
36
+ expect(response).toBeNull();
37
+ });
38
+
39
+ it("dispatches Kitchen requests in dev mode", async () => {
40
+ adapter = createRuntimeDevtoolsAdapter({
41
+ isDev: true,
42
+ rootDir: process.cwd(),
43
+ manifest,
44
+ guardConfig: null,
45
+ });
46
+
47
+ expect(adapter.kitchen).not.toBeNull();
48
+ expect(adapter.dashboardPath).toBe("/__kitchen");
49
+ await expect(
50
+ adapter.handleRequest(new Request("http://localhost:3000/api/ping"), "/api/ping")
51
+ ).resolves.toBeNull();
52
+
53
+ const response = await adapter.handleRequest(
54
+ new Request("http://localhost:3000/__kitchen"),
55
+ "/__kitchen"
56
+ );
57
+ expect(response?.status).toBe(200);
58
+ expect(await response?.text()).toContain("Mandu Kitchen");
59
+ });
60
+
61
+ it("keeps framework-internal request paths out of the Kitchen request log", () => {
62
+ expect(shouldRecordRuntimeRequest("/api/ping")).toBe(true);
63
+ expect(shouldRecordRuntimeRequest("/_mandu/heap")).toBe(true);
64
+ expect(shouldRecordRuntimeRequest("/.mandu/client/runtime.js")).toBe(false);
65
+ expect(shouldRecordRuntimeRequest("/__kitchen/api/events")).toBe(false);
66
+ expect(shouldRecordRuntimeRequest("/__mandu/events/recent")).toBe(false);
67
+ });
68
+ });
@@ -1,103 +1,103 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
2
- import {
3
- INTERNAL_EVENTS_ENDPOINT,
4
- createRuntimeObservabilityLifecycle,
5
- } from "../observability-lifecycle";
6
- import { eventBus } from "../../observability/event-bus";
7
- import {
8
- resetTracer,
9
- type Span,
10
- type SpanExporter,
11
- } from "../../observability/tracing";
12
-
13
- class CaptureExporter implements SpanExporter {
14
- readonly spans: Span[] = [];
15
- export(spans: Span[]): void {
16
- this.spans.push(...spans);
17
- }
18
- }
19
-
20
- afterEach(() => {
21
- resetTracer();
22
- });
23
-
24
- describe("runtime observability lifecycle", () => {
25
- test("serves heap snapshots with perf data when exposed", async () => {
26
- const lifecycle = createRuntimeObservabilityLifecycle({ isDev: true });
27
- const response = lifecycle.handleEndpoint(
28
- new Request("http://localhost/_mandu/heap"),
29
- "/_mandu/heap"
30
- );
31
-
32
- expect(response?.status).toBe(200);
33
- const body = await response!.json() as {
34
- process: { heapUsed: number };
35
- perf: unknown;
36
- };
37
- expect(body.process.heapUsed).toBeGreaterThan(0);
38
- expect(body.perf).toBeDefined();
39
- });
40
-
41
- test("keeps metrics hidden in production unless explicitly enabled", () => {
42
- const hidden = createRuntimeObservabilityLifecycle({ isDev: false });
43
- const shown = createRuntimeObservabilityLifecycle({
44
- isDev: false,
45
- metricsEndpoint: true,
46
- });
47
-
48
- expect(hidden.handleEndpoint(new Request("http://localhost/_mandu/metrics"), "/_mandu/metrics")).toBeNull();
49
- expect(shown.handleEndpoint(new Request("http://localhost/_mandu/metrics"), "/_mandu/metrics")?.status).toBe(200);
50
- });
51
-
52
- test("serves recent EventBus snapshots from the lifecycle endpoint", async () => {
53
- const lifecycle = createRuntimeObservabilityLifecycle({ isDev: true });
54
- const source = `observability-lifecycle-${Date.now()}`;
55
- eventBus.emit({
56
- type: "http",
57
- severity: "info",
58
- source,
59
- message: "GET /observed 200",
60
- });
61
-
62
- const response = lifecycle.handleEndpoint(
63
- new Request(`http://localhost${INTERNAL_EVENTS_ENDPOINT}/recent?source=${source}`),
64
- `${INTERNAL_EVENTS_ENDPOINT}/recent`
65
- );
66
-
67
- expect(response?.status).toBe(200);
68
- const body = await response!.json() as {
69
- events: Array<{ source: string; message: string }>;
70
- };
71
- expect(body.events.some((event) => event.source === source)).toBe(true);
72
- });
73
-
74
- test("wraps requests in a root tracing span", async () => {
75
- const exporter = new CaptureExporter();
76
- const lifecycle = createRuntimeObservabilityLifecycle({
77
- isDev: false,
78
- tracing: {
79
- enabled: true,
80
- customExporter: exporter,
81
- },
82
- });
83
- const incomingTraceId = "4bf92f3577b34da6a3ce929d0e0e4736";
84
- const incomingSpanId = "00f067aa0ba902b7";
85
- const response = await lifecycle.runRequest(
86
- new Request("https://example.test/users", {
87
- headers: {
88
- traceparent: `00-${incomingTraceId}-${incomingSpanId}-01`,
89
- },
90
- }),
91
- Date.now(),
92
- "corr-1",
93
- async () => new Response("created", { status: 201 })
94
- );
95
-
96
- expect(response.status).toBe(201);
97
- expect(exporter.spans).toHaveLength(1);
98
- expect(exporter.spans[0].traceId).toBe(incomingTraceId);
99
- expect(exporter.spans[0].parentSpanId).toBe(incomingSpanId);
100
- expect(exporter.spans[0].attributes["http.status_code"]).toBe(201);
101
- expect(exporter.spans[0].status).toBe("ok");
102
- });
103
- });
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import {
3
+ INTERNAL_EVENTS_ENDPOINT,
4
+ createRuntimeObservabilityLifecycle,
5
+ } from "../observability-lifecycle";
6
+ import { eventBus } from "../../observability/event-bus";
7
+ import {
8
+ resetTracer,
9
+ type Span,
10
+ type SpanExporter,
11
+ } from "../../observability/tracing";
12
+
13
+ class CaptureExporter implements SpanExporter {
14
+ readonly spans: Span[] = [];
15
+ export(spans: Span[]): void {
16
+ this.spans.push(...spans);
17
+ }
18
+ }
19
+
20
+ afterEach(() => {
21
+ resetTracer();
22
+ });
23
+
24
+ describe("runtime observability lifecycle", () => {
25
+ test("serves heap snapshots with perf data when exposed", async () => {
26
+ const lifecycle = createRuntimeObservabilityLifecycle({ isDev: true });
27
+ const response = lifecycle.handleEndpoint(
28
+ new Request("http://localhost/_mandu/heap"),
29
+ "/_mandu/heap"
30
+ );
31
+
32
+ expect(response?.status).toBe(200);
33
+ const body = await response!.json() as {
34
+ process: { heapUsed: number };
35
+ perf: unknown;
36
+ };
37
+ expect(body.process.heapUsed).toBeGreaterThan(0);
38
+ expect(body.perf).toBeDefined();
39
+ });
40
+
41
+ test("keeps metrics hidden in production unless explicitly enabled", () => {
42
+ const hidden = createRuntimeObservabilityLifecycle({ isDev: false });
43
+ const shown = createRuntimeObservabilityLifecycle({
44
+ isDev: false,
45
+ metricsEndpoint: true,
46
+ });
47
+
48
+ expect(hidden.handleEndpoint(new Request("http://localhost/_mandu/metrics"), "/_mandu/metrics")).toBeNull();
49
+ expect(shown.handleEndpoint(new Request("http://localhost/_mandu/metrics"), "/_mandu/metrics")?.status).toBe(200);
50
+ });
51
+
52
+ test("serves recent EventBus snapshots from the lifecycle endpoint", async () => {
53
+ const lifecycle = createRuntimeObservabilityLifecycle({ isDev: true });
54
+ const source = `observability-lifecycle-${Date.now()}`;
55
+ eventBus.emit({
56
+ type: "http",
57
+ severity: "info",
58
+ source,
59
+ message: "GET /observed 200",
60
+ });
61
+
62
+ const response = lifecycle.handleEndpoint(
63
+ new Request(`http://localhost${INTERNAL_EVENTS_ENDPOINT}/recent?source=${source}`),
64
+ `${INTERNAL_EVENTS_ENDPOINT}/recent`
65
+ );
66
+
67
+ expect(response?.status).toBe(200);
68
+ const body = await response!.json() as {
69
+ events: Array<{ source: string; message: string }>;
70
+ };
71
+ expect(body.events.some((event) => event.source === source)).toBe(true);
72
+ });
73
+
74
+ test("wraps requests in a root tracing span", async () => {
75
+ const exporter = new CaptureExporter();
76
+ const lifecycle = createRuntimeObservabilityLifecycle({
77
+ isDev: false,
78
+ tracing: {
79
+ enabled: true,
80
+ customExporter: exporter,
81
+ },
82
+ });
83
+ const incomingTraceId = "4bf92f3577b34da6a3ce929d0e0e4736";
84
+ const incomingSpanId = "00f067aa0ba902b7";
85
+ const response = await lifecycle.runRequest(
86
+ new Request("https://example.test/users", {
87
+ headers: {
88
+ traceparent: `00-${incomingTraceId}-${incomingSpanId}-01`,
89
+ },
90
+ }),
91
+ Date.now(),
92
+ "corr-1",
93
+ async () => new Response("created", { status: 201 })
94
+ );
95
+
96
+ expect(response.status).toBe(201);
97
+ expect(exporter.spans).toHaveLength(1);
98
+ expect(exporter.spans[0].traceId).toBe(incomingTraceId);
99
+ expect(exporter.spans[0].parentSpanId).toBe(incomingSpanId);
100
+ expect(exporter.spans[0].attributes["http.status_code"]).toBe(201);
101
+ expect(exporter.spans[0].status).toBe("ok");
102
+ });
103
+ });
@@ -1,103 +1,103 @@
1
- import { describe, expect, it } from "bun:test";
2
- import React from "react";
3
- import { renderPageResponse } from "../page-render-response";
4
- import type { BundleManifest } from "../../bundler/types";
5
-
6
- const HYDRATED_MANIFEST: BundleManifest = {
7
- version: 1,
8
- buildTime: "2026-05-19T00:00:00.000Z",
9
- env: "production",
10
- bundles: {
11
- home: {
12
- js: "/.mandu/client/home.island.js",
13
- dependencies: ["_runtime", "_react"],
14
- priority: "visible",
15
- },
16
- },
17
- shared: {
18
- runtime: "/.mandu/client/_runtime.js",
19
- vendor: "/.mandu/client/_react.js",
20
- router: "/.mandu/client/_router.js",
21
- },
22
- importMap: {
23
- imports: {
24
- react: "/.mandu/client/_react.js",
25
- "react-dom": "/.mandu/client/_react-dom.js",
26
- "react-dom/client": "/.mandu/client/_react-dom-client.js",
27
- },
28
- },
29
- };
30
-
31
- describe("runtime page render response orchestration", () => {
32
- it("pre-resolves async components on the non-streaming path", async () => {
33
- async function AsyncPage() {
34
- return React.createElement("main", null, "resolved-page");
35
- }
36
-
37
- const response = await renderPageResponse({
38
- app: React.createElement(AsyncPage),
39
- useStreaming: false,
40
- title: "Async Page",
41
- headTags: "",
42
- isDev: false,
43
- routeId: "page/async",
44
- routePattern: "/async",
45
- loaderData: { ok: true },
46
- transitions: false,
47
- prefetch: false,
48
- spa: false,
49
- devtools: false,
50
- });
51
-
52
- expect(response.status).toBe(200);
53
- const html = await response.text();
54
- expect(html).toContain("resolved-page");
55
- expect(html).toContain("Async Page");
56
- });
57
-
58
- it("uses the streaming renderer when requested", async () => {
59
- const response = await renderPageResponse({
60
- app: React.createElement("main", null, "stream-page"),
61
- useStreaming: true,
62
- title: "Stream Page",
63
- headTags: "",
64
- isDev: false,
65
- routeId: "page/stream",
66
- routePattern: "/stream",
67
- loaderData: { ok: true },
68
- transitions: false,
69
- prefetch: false,
70
- spa: false,
71
- devtools: false,
72
- });
73
-
74
- expect(response.status).toBe(200);
75
- expect(response.headers.get("X-Accel-Buffering")).toBe("no");
76
- const html = await response.text();
77
- expect(html).toContain("stream-page");
78
- expect(html).toContain("Stream Page");
79
- });
80
-
81
- it("serializes non-streaming loaderData as the route server data exactly once", async () => {
82
- const response = await renderPageResponse({
83
- app: React.createElement("main", null, "hydrated-page"),
84
- useStreaming: false,
85
- title: "Hydrated Page",
86
- headTags: "",
87
- isDev: false,
88
- routeId: "home",
89
- routePattern: "/",
90
- loaderData: { items: ["a", "b"] },
91
- hydration: { strategy: "island", priority: "visible", preload: false },
92
- bundleManifest: HYDRATED_MANIFEST,
93
- transitions: false,
94
- prefetch: false,
95
- spa: false,
96
- devtools: false,
97
- });
98
-
99
- const html = await response.text();
100
- expect(html).toContain('"home":{"serverData":{"items":["a","b"]}');
101
- expect(html).not.toContain('"serverData":{"home"');
102
- });
103
- });
1
+ import { describe, expect, it } from "bun:test";
2
+ import React from "react";
3
+ import { renderPageResponse } from "../page-render-response";
4
+ import type { BundleManifest } from "../../bundler/types";
5
+
6
+ const HYDRATED_MANIFEST: BundleManifest = {
7
+ version: 1,
8
+ buildTime: "2026-05-19T00:00:00.000Z",
9
+ env: "production",
10
+ bundles: {
11
+ home: {
12
+ js: "/.mandu/client/home.island.js",
13
+ dependencies: ["_runtime", "_react"],
14
+ priority: "visible",
15
+ },
16
+ },
17
+ shared: {
18
+ runtime: "/.mandu/client/_runtime.js",
19
+ vendor: "/.mandu/client/_react.js",
20
+ router: "/.mandu/client/_router.js",
21
+ },
22
+ importMap: {
23
+ imports: {
24
+ react: "/.mandu/client/_react.js",
25
+ "react-dom": "/.mandu/client/_react-dom.js",
26
+ "react-dom/client": "/.mandu/client/_react-dom-client.js",
27
+ },
28
+ },
29
+ };
30
+
31
+ describe("runtime page render response orchestration", () => {
32
+ it("pre-resolves async components on the non-streaming path", async () => {
33
+ async function AsyncPage() {
34
+ return React.createElement("main", null, "resolved-page");
35
+ }
36
+
37
+ const response = await renderPageResponse({
38
+ app: React.createElement(AsyncPage),
39
+ useStreaming: false,
40
+ title: "Async Page",
41
+ headTags: "",
42
+ isDev: false,
43
+ routeId: "page/async",
44
+ routePattern: "/async",
45
+ loaderData: { ok: true },
46
+ transitions: false,
47
+ prefetch: false,
48
+ spa: false,
49
+ devtools: false,
50
+ });
51
+
52
+ expect(response.status).toBe(200);
53
+ const html = await response.text();
54
+ expect(html).toContain("resolved-page");
55
+ expect(html).toContain("Async Page");
56
+ });
57
+
58
+ it("uses the streaming renderer when requested", async () => {
59
+ const response = await renderPageResponse({
60
+ app: React.createElement("main", null, "stream-page"),
61
+ useStreaming: true,
62
+ title: "Stream Page",
63
+ headTags: "",
64
+ isDev: false,
65
+ routeId: "page/stream",
66
+ routePattern: "/stream",
67
+ loaderData: { ok: true },
68
+ transitions: false,
69
+ prefetch: false,
70
+ spa: false,
71
+ devtools: false,
72
+ });
73
+
74
+ expect(response.status).toBe(200);
75
+ expect(response.headers.get("X-Accel-Buffering")).toBe("no");
76
+ const html = await response.text();
77
+ expect(html).toContain("stream-page");
78
+ expect(html).toContain("Stream Page");
79
+ });
80
+
81
+ it("serializes non-streaming loaderData as the route server data exactly once", async () => {
82
+ const response = await renderPageResponse({
83
+ app: React.createElement("main", null, "hydrated-page"),
84
+ useStreaming: false,
85
+ title: "Hydrated Page",
86
+ headTags: "",
87
+ isDev: false,
88
+ routeId: "home",
89
+ routePattern: "/",
90
+ loaderData: { items: ["a", "b"] },
91
+ hydration: { strategy: "island", priority: "visible", preload: false },
92
+ bundleManifest: HYDRATED_MANIFEST,
93
+ transitions: false,
94
+ prefetch: false,
95
+ spa: false,
96
+ devtools: false,
97
+ });
98
+
99
+ const html = await response.text();
100
+ expect(html).toContain('"home":{"serverData":{"items":["a","b"]}');
101
+ expect(html).not.toContain('"serverData":{"home"');
102
+ });
103
+ });