@timber-js/app 0.2.0-alpha.219 → 0.2.0-alpha.220

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 (164) hide show
  1. package/dist/_chunks/chains-CDK1AWZQ.js +1 -0
  2. package/dist/_chunks/{chains-YKZ8WpIW.js → chains-e_Buf9vg.js} +2 -7
  3. package/dist/_chunks/{chains-YKZ8WpIW.js.map → chains-e_Buf9vg.js.map} +1 -1
  4. package/dist/_chunks/{cli-check-D2WtbNqo.js → cli-check-DDwCkeDY.js} +2 -2
  5. package/dist/_chunks/{cli-check-D2WtbNqo.js.map → cli-check-DDwCkeDY.js.map} +1 -1
  6. package/dist/_chunks/cli-context-BJQB6rtF.js +1 -0
  7. package/dist/_chunks/{cli-context-By7k2xVo.js → cli-context-_mPttGGY.js} +3 -3
  8. package/dist/_chunks/{cli-context-By7k2xVo.js.map → cli-context-_mPttGGY.js.map} +1 -1
  9. package/dist/_chunks/{cli-schema-sync-CySLKrO3.js → cli-schema-sync-BdIebmk3.js} +3 -12
  10. package/dist/_chunks/{cli-schema-sync-CySLKrO3.js.map → cli-schema-sync-BdIebmk3.js.map} +1 -1
  11. package/dist/_chunks/cli-schema-sync-CLNfXQDK.js +1 -0
  12. package/dist/_chunks/dev-server-DkytOEG2.js +1 -0
  13. package/dist/_chunks/{dev-server-B8zsT-ee.js → dev-server-DnODXuNM.js} +31 -14
  14. package/dist/_chunks/{dev-server-B8zsT-ee.js.map → dev-server-DnODXuNM.js.map} +1 -1
  15. package/dist/_chunks/flight-source-node-0dE-t3kq.js +519 -0
  16. package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +1 -0
  17. package/dist/_chunks/{live-graph-BhtrZpRd.js → live-graph-tSWrv8eH.js} +2 -2
  18. package/dist/_chunks/{live-graph-BhtrZpRd.js.map → live-graph-tSWrv8eH.js.map} +1 -1
  19. package/dist/_chunks/node-response-Dibufw_b.js +187 -0
  20. package/dist/_chunks/node-response-Dibufw_b.js.map +1 -0
  21. package/dist/_chunks/{plugin-context-BPBPc3lL.js → plugin-context-DxMMvjUt.js} +2 -18
  22. package/dist/_chunks/{plugin-context-BPBPc3lL.js.map → plugin-context-DxMMvjUt.js.map} +1 -1
  23. package/dist/_chunks/plugin-context-uDHFqHHJ.js +1 -0
  24. package/dist/_chunks/{walkers-Ber9bamD.js → walkers-qu8TpiLh.js} +2 -2
  25. package/dist/_chunks/{walkers-Ber9bamD.js.map → walkers-qu8TpiLh.js.map} +1 -1
  26. package/dist/adapters/nitro-preview.d.ts.map +1 -1
  27. package/dist/adapters/nitro.js +40 -1
  28. package/dist/adapters/nitro.js.map +1 -1
  29. package/dist/analyze/crawl-entry.js +2 -2
  30. package/dist/analyze/graph-command.js +3 -3
  31. package/dist/analyze/graph-command.js.map +1 -1
  32. package/dist/cli.js +5 -5
  33. package/dist/cli.js.map +1 -1
  34. package/dist/client/browser-entry/form-state.d.ts.map +1 -1
  35. package/dist/client/browser-entry/index.d.ts +1 -1
  36. package/dist/client/browser-entry/rsc-stream.d.ts +4 -1
  37. package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -1
  38. package/dist/client/react-root.d.ts +6 -0
  39. package/dist/client/react-root.d.ts.map +1 -1
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +36 -5
  42. package/dist/index.js.map +1 -1
  43. package/dist/plugins/encryption-runtime.d.ts +13 -0
  44. package/dist/plugins/encryption-runtime.d.ts.map +1 -0
  45. package/dist/plugins/entries.d.ts +1 -0
  46. package/dist/plugins/entries.d.ts.map +1 -1
  47. package/dist/plugins/server-bundle.d.ts +1 -1
  48. package/dist/plugins/server-bundle.d.ts.map +1 -1
  49. package/dist/routing/index.js +1 -1
  50. package/dist/rsc-runtime/encryption-runtime.d.ts +25 -0
  51. package/dist/rsc-runtime/encryption-runtime.d.ts.map +1 -0
  52. package/dist/rsc-runtime/render-flight.d.ts +14 -0
  53. package/dist/rsc-runtime/render-flight.d.ts.map +1 -0
  54. package/dist/rsc-runtime/rsc.d.ts +6 -2
  55. package/dist/rsc-runtime/rsc.d.ts.map +1 -1
  56. package/dist/rsc-runtime/ssr.d.ts +6 -12
  57. package/dist/rsc-runtime/ssr.d.ts.map +1 -1
  58. package/dist/server/action-handler.d.ts.map +1 -1
  59. package/dist/server/compress.d.ts +2 -0
  60. package/dist/server/compress.d.ts.map +1 -1
  61. package/dist/server/deny-renderer.d.ts +2 -1
  62. package/dist/server/deny-renderer.d.ts.map +1 -1
  63. package/dist/server/flight-injector-core.d.ts +125 -0
  64. package/dist/server/flight-injector-core.d.ts.map +1 -0
  65. package/dist/server/flight-scripts.d.ts +9 -0
  66. package/dist/server/flight-scripts.d.ts.map +1 -1
  67. package/dist/server/flight-source-node.d.ts +105 -0
  68. package/dist/server/flight-source-node.d.ts.map +1 -0
  69. package/dist/server/flight-source.d.ts +136 -0
  70. package/dist/server/flight-source.d.ts.map +1 -0
  71. package/dist/server/head-response.d.ts.map +1 -1
  72. package/dist/server/html-injector-core.d.ts +3 -91
  73. package/dist/server/html-injector-core.d.ts.map +1 -1
  74. package/dist/server/html-injectors.d.ts +5 -17
  75. package/dist/server/html-injectors.d.ts.map +1 -1
  76. package/dist/server/internal.js +78 -138
  77. package/dist/server/internal.js.map +1 -1
  78. package/dist/server/node-body-response.d.ts +55 -0
  79. package/dist/server/node-body-response.d.ts.map +1 -0
  80. package/dist/server/node-response.d.ts +62 -0
  81. package/dist/server/node-response.d.ts.map +1 -0
  82. package/dist/server/node-stream-transforms.d.ts +24 -21
  83. package/dist/server/node-stream-transforms.d.ts.map +1 -1
  84. package/dist/server/node-streams-platform.d.ts +21 -0
  85. package/dist/server/node-streams-platform.d.ts.map +1 -0
  86. package/dist/server/pipeline-helpers.d.ts.map +1 -1
  87. package/dist/server/pipeline.d.ts.map +1 -1
  88. package/dist/server/prebuilt-runtime.d.ts +2 -3
  89. package/dist/server/prebuilt-runtime.d.ts.map +1 -1
  90. package/dist/server/rsc-entry/index.d.ts.map +1 -1
  91. package/dist/server/rsc-entry/render-route.d.ts +4 -1
  92. package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
  93. package/dist/server/rsc-entry/rsc-payload.d.ts +9 -6
  94. package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
  95. package/dist/server/rsc-entry/rsc-stream.d.ts +9 -4
  96. package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
  97. package/dist/server/rsc-entry/ssr-bridge.d.ts +2 -1
  98. package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
  99. package/dist/server/rsc-entry/ssr-renderer.d.ts +2 -1
  100. package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
  101. package/dist/server/ssr-bridge-types.d.ts +9 -4
  102. package/dist/server/ssr-bridge-types.d.ts.map +1 -1
  103. package/dist/server/ssr-entry.d.ts +8 -5
  104. package/dist/server/ssr-entry.d.ts.map +1 -1
  105. package/dist/server/ssr-render.d.ts +7 -16
  106. package/dist/server/ssr-render.d.ts.map +1 -1
  107. package/dist/server/stream-utils.d.ts +44 -10
  108. package/dist/server/stream-utils.d.ts.map +1 -1
  109. package/dist/shared/flight-base64.d.ts +13 -0
  110. package/dist/shared/flight-base64.d.ts.map +1 -0
  111. package/dist/shared/flight-segment.d.ts +18 -0
  112. package/dist/shared/flight-segment.d.ts.map +1 -0
  113. package/dist/shared/form-state-flight.d.ts +0 -4
  114. package/dist/shared/form-state-flight.d.ts.map +1 -1
  115. package/docs/learn/12-error-handling.mdx +1 -1
  116. package/package.json +1 -1
  117. package/src/adapters/nitro-preview.ts +39 -0
  118. package/src/client/browser-entry/form-state.ts +3 -2
  119. package/src/client/browser-entry/index.ts +14 -8
  120. package/src/client/browser-entry/rsc-stream.ts +14 -14
  121. package/src/client/react-root.ts +25 -2
  122. package/src/index.ts +2 -0
  123. package/src/plugins/encryption-runtime.ts +31 -0
  124. package/src/plugins/entries.ts +1 -1
  125. package/src/plugins/server-bundle.ts +17 -2
  126. package/src/rsc-runtime/encryption-runtime.ts +78 -0
  127. package/src/rsc-runtime/render-flight.ts +26 -0
  128. package/src/rsc-runtime/rsc.ts +7 -4
  129. package/src/rsc-runtime/ssr.ts +10 -48
  130. package/src/rsc-runtime/vendor-types.d.ts +31 -2
  131. package/src/server/action-handler.ts +43 -44
  132. package/src/server/compress.ts +49 -12
  133. package/src/server/deny-renderer.ts +14 -7
  134. package/src/server/flight-injector-core.ts +328 -0
  135. package/src/server/flight-scripts.ts +14 -2
  136. package/src/server/flight-source-node.ts +430 -0
  137. package/src/server/flight-source.ts +288 -0
  138. package/src/server/form-state-flight.ts +4 -4
  139. package/src/server/head-response.ts +6 -10
  140. package/src/server/html-injector-core.ts +24 -216
  141. package/src/server/html-injectors.ts +12 -71
  142. package/src/server/node-body-response.ts +236 -0
  143. package/src/server/node-response.ts +93 -0
  144. package/src/server/node-stream-transforms.ts +70 -53
  145. package/src/server/node-streams-platform.ts +23 -0
  146. package/src/server/pipeline-helpers.ts +3 -1
  147. package/src/server/pipeline.ts +14 -6
  148. package/src/server/prebuilt/capture-render.ts +5 -5
  149. package/src/server/prebuilt-runtime.ts +7 -10
  150. package/src/server/rsc-entry/error-renderer.ts +8 -4
  151. package/src/server/rsc-entry/index.ts +4 -2
  152. package/src/server/rsc-entry/render-route.ts +5 -2
  153. package/src/server/rsc-entry/rsc-payload.ts +52 -73
  154. package/src/server/rsc-entry/rsc-stream.ts +102 -106
  155. package/src/server/rsc-entry/ssr-bridge.ts +32 -10
  156. package/src/server/rsc-entry/ssr-renderer.ts +15 -18
  157. package/src/server/ssr-bridge-types.ts +10 -4
  158. package/src/server/ssr-entry.ts +56 -52
  159. package/src/server/ssr-render.ts +41 -76
  160. package/src/server/stream-utils.ts +125 -70
  161. package/src/shared/flight-base64.ts +23 -0
  162. package/src/shared/flight-segment.ts +35 -0
  163. package/src/shared/form-state-flight.ts +0 -15
  164. package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +0 -13
@@ -11,6 +11,8 @@
11
11
  *
12
12
  * Design doc: 02-rendering-pipeline.md §"RSC → SSR → Client Hydration"
13
13
  */
14
+ /** Default maximum buffer divergence before cancellation (5MB). */
15
+ export declare const DEFAULT_MAX_BUFFER_BYTES: number;
14
16
  export interface TeeOptions {
15
17
  /**
16
18
  * Maximum byte divergence between the two branches before both are
@@ -34,26 +36,58 @@ export interface TeeOptions {
34
36
  */
35
37
  export declare function teeWithErrorPropagation(stream: ReadableStream<Uint8Array>, options?: TeeOptions): [ReadableStream<Uint8Array>, ReadableStream<Uint8Array>];
36
38
  /**
37
- * Wrap a response body with stream-lifecycle timing instrumentation.
38
- *
39
- * Logs firstChunk, lastChunk, close, maxGap (largest inter-chunk gap),
40
- * chunk count, and byte count on stream termination (clean close OR
41
- * cancellation/disconnect). Gated behind `serverTiming: 'detailed'`.
39
+ * Stream-lifecycle timing for one response body: firstChunk, lastChunk,
40
+ * close, maxGap (largest inter-chunk gap), chunk count, and byte count,
41
+ * logged once when the stream terminates (clean close OR
42
+ * cancellation/disconnect). Gated behind `serverTiming: 'detailed'`. The
43
+ * Web body wrapper below and the Node body (`node-body-response.ts`) feed
44
+ * the same recorder, so the two report identically.
45
+ */
46
+ export interface StreamTimingRecorder {
47
+ chunk(byteLength: number): void;
48
+ end(cancelled: boolean): void;
49
+ }
50
+ export declare function createStreamTimingRecorder(startTime: number): StreamTimingRecorder;
51
+ /**
52
+ * Wrap a Web response body with stream-lifecycle timing instrumentation
53
+ * ({@link createStreamTimingRecorder}).
42
54
  *
43
55
  * Uses a manual reader pump to guarantee logging on all termination
44
56
  * paths — TransformStream.flush() is not called on cancellation.
45
57
  */
46
58
  export declare function wrapResponseWithStreamTiming(body: ReadableStream<Uint8Array>, startTime: number): ReadableStream<Uint8Array>;
47
59
  /**
48
- * Read a byte stream to completion under one overall deadline and return
49
- * the concatenated bytes. Every read is raced against the time remaining,
50
- * and the reader is cancelled on every exit, so a stalled upstream never
51
- * outlives the deadline. See design/02-rendering-pipeline.md §"Always
52
- * Timeout-Guard Stream Reads".
60
+ * The error both tee implementations (this Web one and the Node one in
61
+ * `flight-source-node.ts`) cancel with when one branch lags the other by more
62
+ * than `maxBuffer` bytes. Warns once, here, so the two cannot drift.
63
+ */
64
+ export declare function teeBufferExceeded(maxBuffer: number, divergence: number): Error;
65
+ /**
66
+ * A pull reader over any chunk stream: a Web reader, or the Flight reader in
67
+ * `flight-source.ts`, which reads a Node or Web Flight source.
68
+ */
69
+ export interface ChunkReader<T> {
70
+ read(): Promise<ReadableStreamReadResult<T>>;
71
+ cancel(reason?: unknown): void;
72
+ }
73
+ /**
74
+ * Read a chunk stream to completion under one overall deadline. Every read
75
+ * is raced against the time remaining, and the reader is cancelled on every
76
+ * exit, so a stalled upstream never outlives the deadline. See
77
+ * design/02-rendering-pipeline.md §"Always Timeout-Guard Stream Reads".
53
78
  *
54
79
  * @param label - Prefix for the timeout error message. Both ways the deadline
55
80
  * can pass (between reads, or while a read is pending) reject with the same
56
81
  * `${label} did not complete within ${timeoutMs}ms`.
57
82
  */
83
+ export declare function drainWithDeadline<T>(reader: ChunkReader<T>, timeoutMs: number, label: string): Promise<T[]>;
84
+ /** Concatenate byte chunks into one array. */
85
+ export declare function concatBytes(chunks: readonly Uint8Array[]): Uint8Array<ArrayBuffer>;
86
+ /**
87
+ * Read a byte stream to completion under one overall deadline and return
88
+ * the concatenated bytes ({@link drainWithDeadline}). The static generator's
89
+ * body drain uses it; Flight renders use `collectFlightBytes`
90
+ * (`flight-source.ts`), which reads either source kind the same way.
91
+ */
58
92
  export declare function readAllBytesWithDeadline(stream: ReadableStream<Uint8Array>, timeoutMs: number, label: string): Promise<Uint8Array>;
59
93
  //# sourceMappingURL=stream-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-utils.d.ts","sourceRoot":"","sources":["../../src/server/stream-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,OAAO,CAAC,EAAE,UAAU,GACnB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,CAmK1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,SAAS,EAAE,MAAM,GAChB,cAAc,CAAC,UAAU,CAAC,CA8D5B;AASD;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,CAkCrB"}
1
+ {"version":3,"file":"stream-utils.d.ts","sourceRoot":"","sources":["../../src/server/stream-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,mEAAmE;AACnE,eAAO,MAAM,wBAAwB,QAAkB,CAAC;AAExD,MAAM,WAAW,UAAU;IACzB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,OAAO,CAAC,EAAE,UAAU,GACnB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC,CA4J1D;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,GAAG,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B;AAED,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAuClF;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,SAAS,EAAE,MAAM,GAChB,cAAc,CAAC,UAAU,CAAC,CA0B5B;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,CAS9E;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,IAAI,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,CAAC,EAAE,CAAC,CAwBd;AAED,8CAA8C;AAC9C,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAUlF;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,UAAU,CAAC,CAQrB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Flight bytes as base64, for the two places a page embeds Flight that a
3
+ * text chunk cannot carry: a no-JS action's form state
4
+ * (server/form-state-flight.ts) and an inlined Flight chunk that is not valid
5
+ * UTF-8, the binary row of a typed array or ArrayBuffer (the `[3, base64]`
6
+ * tuple, server/flight-injector-core.ts). Base64 has no character that can end
7
+ * a `<script>` element or a JS string, so it embeds without escaping.
8
+ */
9
+ /** Flight bytes as base64. */
10
+ export declare function flightBytesToBase64(bytes: Uint8Array): string;
11
+ /** Embedded base64 back to the Flight bytes. */
12
+ export declare function flightBytesFromBase64(text: string): Uint8Array<ArrayBuffer>;
13
+ //# sourceMappingURL=flight-base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flight-base64.d.ts","sourceRoot":"","sources":["../../src/shared/flight-base64.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,8BAA8B;AAC9B,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI7D;AAED,gDAAgD;AAChD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAK3E"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The inline Flight tuples a page pushes onto `self.__timber_f`, and how the
3
+ * browser turns each back into Flight bytes. The server writes them
4
+ * (server/flight-scripts.ts, server/flight-injector-core.ts); the browser
5
+ * reads them (client/browser-entry/rsc-stream.ts).
6
+ *
7
+ * - `[0]` — bootstrap signal: Flight data is active for this page.
8
+ * - `[1, text]` — Flight text, UTF-8 encoded back to bytes.
9
+ * - `[3, base64]` — Flight bytes that are not valid UTF-8 (a typed array's
10
+ * binary row), base64-decoded back to the same bytes.
11
+ *
12
+ * Both data tuples become bytes, enqueued in order, so the decoder sees the
13
+ * byte stream the server rendered whichever tuple carried each run.
14
+ */
15
+ export type FlightSegment = [isBootstrap: 0] | [isData: 1, data: string] | [isBinaryData: 3, base64: string];
16
+ /** A data tuple's Flight bytes; `null` for the bootstrap signal. */
17
+ export declare function flightSegmentBytes(segment: FlightSegment): Uint8Array | null;
18
+ //# sourceMappingURL=flight-segment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flight-segment.d.ts","sourceRoot":"","sources":["../../src/shared/flight-segment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,MAAM,aAAa,GACrB,CAAC,WAAW,EAAE,CAAC,CAAC,GAChB,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GACzB,CAAC,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAItC,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,GAAG,IAAI,CAS5E"}
@@ -29,8 +29,4 @@ export type FormStateFlightDecoder = (stream: ReadableStream<Uint8Array>) => Pro
29
29
  * stall it, and the caller falls back to rendering without form state.
30
30
  */
31
31
  export declare function decodeFormState(bytes: Uint8Array, decode: FormStateFlightDecoder, timeoutMs: number): Promise<ReactFormState>;
32
- /** The form state's Flight bytes as the base64 the page embeds. */
33
- export declare function formStateToBase64(bytes: Uint8Array): string;
34
- /** The embedded base64 back to the Flight bytes. */
35
- export declare function formStateFromBase64(text: string): Uint8Array;
36
32
  //# sourceMappingURL=form-state-flight.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-state-flight.d.ts","sourceRoot":"","sources":["../../src/shared/form-state-flight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,KAC/B,WAAW,CAAC,cAAc,CAAC,CAAC;AAEjC;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,sBAAsB,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,CAAC,CAmBzB;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAI3D;AAED,oDAAoD;AACpD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAK5D"}
1
+ {"version":3,"file":"form-state-flight.d.ts","sourceRoot":"","sources":["../../src/shared/form-state-flight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,KAC/B,WAAW,CAAC,cAAc,CAAC,CAAC;AAEjC;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,sBAAsB,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,cAAc,CAAC,CAmBzB"}
@@ -170,7 +170,7 @@ The HTTP status stays correct either way — `deny(404)` falling through to `err
170
170
 
171
171
  When a user refreshes the page or navigates away while Suspense boundaries are still streaming, the aborted connection would normally cause errors in both the RSC and SSR streams. timber detects these aborts and suppresses them at multiple layers:
172
172
 
173
- - **Server-side:** The request's `AbortSignal` is passed to React's `renderToReadableStream`. React stops rendering on abort without firing `onError`. SSR detects the abort and closes the stream silently.
173
+ - **Server-side:** The request's `AbortSignal` aborts React's render. React stops rendering on abort without firing `onError`. SSR detects the abort and closes the stream silently.
174
174
  - **Client-side:** The error boundary checks for page unload (`beforeunload`/`pagehide`) and suppresses error boundary activation. The client router silently discards `AbortError` from aborted fetches.
175
175
 
176
176
  A page refresh during streaming never shows a flash of an error boundary. This is a common issue in Next.js where mid-stream refreshes can briefly display error UI.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timber-js/app",
3
- "version": "0.2.0-alpha.219",
3
+ "version": "0.2.0-alpha.220",
4
4
  "description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
5
5
  "keywords": [
6
6
  "cloudflare-workers",
@@ -446,6 +446,39 @@ export function sendNodeResponse(nodeRes, webRes) {
446
446
  nodeRes.statusCode = 500;
447
447
  return new Promise((resolve) => nodeRes.end(resolve));
448
448
  }
449
+ // A response with a Node body (timber's NodeBodyResponse, srvx's protocol):
450
+ // pipe it straight to the socket, no Web Streams round trip. pipe() rather
451
+ // than pipeline(), which allocates an AbortController and an error on every
452
+ // finish; a client that disconnects early destroys the body (aborting the
453
+ // render), and a body that errors destroys the socket.
454
+ if (typeof webRes._toNodeResponse === 'function') {
455
+ const res = webRes._toNodeResponse();
456
+ if (res.body && typeof res.body.pipe === 'function') {
457
+ if (!nodeRes.headersSent) {
458
+ if (nodeRes.req?.httpVersion === '2.0') {
459
+ nodeRes.writeHead(res.status, res.headers);
460
+ } else {
461
+ nodeRes.writeHead(res.status, res.statusText, res.headers);
462
+ }
463
+ }
464
+ const body = res.body;
465
+ // The client already left: 'close' has fired and will not again.
466
+ if (nodeRes.destroyed) {
467
+ body.destroy();
468
+ return;
469
+ }
470
+ return new Promise((resolve) => {
471
+ nodeRes.once('close', () => {
472
+ if (!body.readableEnded) body.destroy();
473
+ resolve();
474
+ });
475
+ nodeRes.on('error', () => body.destroy());
476
+ body.once('error', (error) => nodeRes.destroy(error));
477
+ body.pipe(nodeRes);
478
+ });
479
+ }
480
+ webRes = new Response(res.body, { status: res.status, statusText: res.statusText, headers: pairs(res.headers) });
481
+ }
449
482
  const rawHeaders = [...webRes.headers];
450
483
  const writeHeaders = rawHeaders.flat();
451
484
  if (!nodeRes.headersSent) {
@@ -490,5 +523,11 @@ export function sendNodeResponse(nodeRes, webRes) {
490
523
  nodeRes.off('error', streamCancel);
491
524
  });
492
525
  }
526
+
527
+ function pairs(flat) {
528
+ const out = [];
529
+ for (let i = 0; i < flat.length; i += 2) out.push([flat[i], flat[i + 1]]);
530
+ return out;
531
+ }
493
532
  `;
494
533
  }
@@ -14,7 +14,8 @@
14
14
 
15
15
  import type { ReactFormState } from 'react-dom/client';
16
16
  import { createFromReadableStream } from '../../rsc-runtime/browser.ts';
17
- import { decodeFormState, formStateFromBase64 } from '../../shared/form-state-flight.ts';
17
+ import { decodeFormState } from '../../shared/form-state-flight.ts';
18
+ import { flightBytesFromBase64 } from '../../shared/flight-base64.ts';
18
19
 
19
20
  /**
20
21
  * Every byte is already in the document, so decoding takes microtasks. The
@@ -36,7 +37,7 @@ export function takeEmbeddedFormState(): Promise<ReactFormState | null> | null {
36
37
  return Promise.resolve(embedded)
37
38
  .then((text) =>
38
39
  decodeFormState(
39
- formStateFromBase64(text),
40
+ flightBytesFromBase64(text),
40
41
  (stream) => createFromReadableStream(stream),
41
42
  DECODE_TIMEOUT_MS
42
43
  )
@@ -24,7 +24,7 @@
24
24
  * hydrate the root (no root without a payload)
25
25
  * 5. setupPostHydration() — popstate, scroll
26
26
  * 6. setupHmr() — dev-only HMR wiring
27
- * 7. timber-ready signal — E2E test readiness indicator
27
+ * 7. timber-ready signal — E2E readiness: React has committed the page
28
28
  *
29
29
  * Design docs: 18-build-system.md §"Entry Files", 19-client-navigation.md
30
30
  */
@@ -97,6 +97,9 @@ function bootstrap(runtimeConfig: typeof config, formState: ReactFormState | nul
97
97
  const reactRoot = createReactRoot({
98
98
  container: document,
99
99
  topLoaderConfig: (runtimeConfig as { topLoader?: TopLoaderConfig }).topLoader,
100
+ // With a payload, the page is ready when React commits it — hydration
101
+ // is concurrent and finishes after this bootstrap returns.
102
+ onFirstCommit: rscResult ? signalReady : undefined,
100
103
  });
101
104
  const { router, navApiController, hydrate } = createTimberRouter({
102
105
  render: reactRoot.render,
@@ -112,12 +115,19 @@ function bootstrap(runtimeConfig: typeof config, formState: ReactFormState | nul
112
115
 
113
116
  // Step 6: HMR (dev-only, no-op in production)
114
117
  setupHmr(router);
118
+
119
+ // Step 7: Without a payload there is nothing to hydrate: the page is the
120
+ // server's HTML until the first navigation, and is ready now.
121
+ if (!rscResult) signalReady();
115
122
  }
116
123
 
117
124
  // ─── 7. Ready Signal ────────────────────────────────────────────
118
125
 
119
- // Signal that the client runtime has been initialized.
120
- // Used by E2E tests to wait for hydration before interacting.
126
+ // Signal that React has committed the page (hydration, or the client render
127
+ // that replaced it), so the router and every component are live. Used by E2E
128
+ // tests to wait before interacting: signalling when the bootstrap returned
129
+ // instead let a test click a link mid-hydration, start a navigation, and
130
+ // hit a hydration mismatch on the top loader (TIM-1585).
121
131
  // We append a <meta name="timber-ready"> tag rather than setting a
122
132
  // data attribute on <html>. Since React owns the entire document
123
133
  // via hydrateRoot(document, ...), mutating <html> attributes causes
@@ -134,11 +144,7 @@ function signalReady(): void {
134
144
  // Every other page bootstraps synchronously, as it always has.
135
145
  const embeddedFormState = takeEmbeddedFormState();
136
146
  if (embeddedFormState) {
137
- void embeddedFormState.then((formState) => {
138
- bootstrap(config, formState);
139
- signalReady();
140
- });
147
+ void embeddedFormState.then((formState) => bootstrap(config, formState));
141
148
  } else {
142
149
  bootstrap(config, null);
143
- signalReady();
144
150
  }
@@ -3,7 +3,10 @@
3
3
  *
4
4
  * The RSC payload is embedded in the HTML as progressive inline script
5
5
  * tags that call `self.__timber_f.push([type, data])` as RSC chunks arrive.
6
- * Typed tuples: [0] = bootstrap signal, [1, string] = Flight data chunk.
6
+ * Typed tuples (shared/flight-segment.ts): [0] = bootstrap signal,
7
+ * [1, string] = Flight text, [3, base64] = Flight bytes that are not valid
8
+ * UTF-8. Both data tuples are enqueued as bytes, in order, so the decoder
9
+ * sees the server's byte stream.
7
10
  *
8
11
  * This module sets up a ReadableStream fed by those push() calls so
9
12
  * `createFromReadableStream` can decode the Flight protocol progressively.
@@ -14,8 +17,7 @@
14
17
  import { createFromReadableStream } from '../../rsc-runtime/browser.ts';
15
18
  import { isPageUnloading } from '../unload-guard.ts';
16
19
  import { splitPayloadRoot, type PublishedParams } from '../../shared/payload-root.ts';
17
-
18
- type FlightSegment = [isBootstrap: 0] | [isData: 1, data: string];
20
+ import { flightSegmentBytes, type FlightSegment } from '../../shared/flight-segment.ts';
19
21
 
20
22
  export interface RscStreamResult {
21
23
  /** The decoded RSC element (thenable/lazy — resolved by React during render) */
@@ -45,25 +47,23 @@ export function createRscPayloadStream(): RscStreamResult | null {
45
47
  const timberChunks = (self as unknown as Record<string, FlightSegment[] | undefined>).__timber_f;
46
48
  if (!timberChunks) return null;
47
49
 
48
- const encoder = new TextEncoder();
49
-
50
- // Buffer to hold string data until the stream writer is ready.
50
+ // Buffer to hold Flight bytes until the stream writer is ready.
51
51
  // Scripts that execute before hydration starts push data here.
52
- let dataBuffer: string[] | undefined = [];
52
+ let dataBuffer: Uint8Array[] | undefined = [];
53
53
  let streamWriter: ReadableStreamDefaultController<Uint8Array> | null = null;
54
54
  let streamFlushed = false;
55
55
 
56
56
  /** Process a typed tuple from __timber_f. */
57
57
  function handleSegment(seg: FlightSegment): void {
58
- if (seg[0] === 0) {
58
+ const bytes = flightSegmentBytes(seg);
59
+ if (bytes === null) {
59
60
  // Bootstrap signal — initialize buffer (already done above)
60
61
  if (!dataBuffer) dataBuffer = [];
61
- } else if (seg[0] === 1) {
62
- // Flight data chunk
62
+ } else {
63
63
  if (streamWriter) {
64
- streamWriter.enqueue(encoder.encode(seg[1]));
64
+ streamWriter.enqueue(bytes);
65
65
  } else if (dataBuffer) {
66
- dataBuffer.push(seg[1]);
66
+ dataBuffer.push(bytes);
67
67
  }
68
68
  }
69
69
  }
@@ -83,8 +83,8 @@ export function createRscPayloadStream(): RscStreamResult | null {
83
83
  streamWriter = controller;
84
84
  // Flush buffered data into the stream.
85
85
  if (dataBuffer) {
86
- for (const data of dataBuffer) {
87
- controller.enqueue(encoder.encode(data));
86
+ for (const bytes of dataBuffer) {
87
+ controller.enqueue(bytes);
88
88
  }
89
89
  dataBuffer = undefined;
90
90
  }
@@ -44,12 +44,35 @@ export interface ReactRootHost {
44
44
  export function createReactRoot(options: {
45
45
  container: Document | Element;
46
46
  topLoaderConfig?: TopLoaderConfig;
47
+ /**
48
+ * Runs once, when React first commits a tree on this root — hydration's,
49
+ * or the client render that replaced it. Until then the page is the
50
+ * server's HTML with no React behind it.
51
+ */
52
+ onFirstCommit?: () => void;
47
53
  }): ReactRootHost {
48
54
  const { container, topLoaderConfig } = options;
49
55
  let root: Root | null = null;
56
+ let onFirstCommit = options.onFirstCommit ?? null;
50
57
 
51
- const rootElement = (rendered: RenderedTree) =>
52
- createElement(NavigationRoot, { rendered, topLoaderConfig });
58
+ // Consumed by whichever tree commits first, at its commit — not when a
59
+ // tree is built: a suspended hydration can be replaced by a navigation's
60
+ // render before it commits, and never commit at all (codex on #1228).
61
+ const rootElement = ({ element, publish }: RenderedTree) => {
62
+ const rendered: RenderedTree =
63
+ onFirstCommit === null
64
+ ? { element, publish }
65
+ : {
66
+ element,
67
+ publish: () => {
68
+ publish?.();
69
+ const first = onFirstCommit;
70
+ onFirstCommit = null;
71
+ first?.();
72
+ },
73
+ };
74
+ return createElement(NavigationRoot, { rendered, topLoaderConfig });
75
+ };
53
76
 
54
77
  return {
55
78
  hydrate(element, hydrationOptions) {
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ import { timberReactResolve } from './plugins/react-resolve.ts';
32
32
  import { timberChunks } from './plugins/chunks.ts';
33
33
  import { clientChunkGroup } from './plugins/client-chunks.ts';
34
34
  import { timberServerBundle } from './plugins/server-bundle.ts';
35
+ import { timberEncryptionRuntime } from './plugins/encryption-runtime.ts';
35
36
  import { timberCacheTransform } from './plugins/cache.ts';
36
37
  import { timberRequestDep } from './plugins/request-dep/index.ts';
37
38
  import { timberPrebuilt } from './plugins/prebuilt.ts';
@@ -569,6 +570,7 @@ export function timber(config?: TimberUserConfig): PluginOption[] {
569
570
  })
570
571
  ),
571
572
  vitePluginRsc(createRscOptions(ctx, encryptionKeyExpr)),
573
+ timberEncryptionRuntime(), // plugin-rsc's bound-args encryption → renderFlight
572
574
  timberShims(ctx),
573
575
  timberRouting(ctx),
574
576
  timberEntries(ctx),
@@ -0,0 +1,31 @@
1
+ /**
2
+ * timber-encryption-runtime — route plugin-rsc's server-action encryption
3
+ * runtime to timber's (`rsc-runtime/encryption-runtime.ts`), which serializes
4
+ * through `renderFlight`.
5
+ *
6
+ * plugin-rsc prepends an import of `@vitejs/plugin-rsc/utils/encryption-runtime`
7
+ * (as a resolved `file://` URL) to every module with an inline `'use server'`
8
+ * closure. Its runtime renders with the edge Flight server, which cannot
9
+ * render in a process where the Node Flight server already has (TIM-1585).
10
+ */
11
+
12
+ import { resolve } from 'node:path';
13
+ import type { Plugin } from 'vite';
14
+ import { SRC_DIR } from './entries.ts';
15
+
16
+ const PLUGIN_RUNTIME_SUFFIX = '/@vitejs/plugin-rsc/dist/utils/encryption-runtime.js';
17
+ const TIMBER_RUNTIME = resolve(SRC_DIR, 'rsc-runtime', 'encryption-runtime.ts');
18
+
19
+ export function timberEncryptionRuntime(): Plugin {
20
+ return {
21
+ name: 'timber-encryption-runtime',
22
+ enforce: 'pre',
23
+ applyToEnvironment: (environment) => environment.name === 'rsc',
24
+ resolveId: {
25
+ filter: { id: /plugin-rsc\/dist\/utils\/encryption-runtime\.js$/ },
26
+ handler(id) {
27
+ if (id.endsWith(PLUGIN_RUNTIME_SUFFIX)) return TIMBER_RUNTIME;
28
+ },
29
+ },
30
+ };
31
+ }
@@ -23,7 +23,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
23
23
  // In workspace dev, __dirname is src/plugins/ and src/ is the parent.
24
24
  // In published package, entries.ts is bundled into dist/index.js so
25
25
  // __dirname is dist/ and src/ is a sibling directory.
26
- const SRC_DIR = existsSync(resolve(__dirname, '..', 'server', 'rsc-entry', 'index.ts'))
26
+ export const SRC_DIR = existsSync(resolve(__dirname, '..', 'server', 'rsc-entry', 'index.ts'))
27
27
  ? resolve(__dirname, '..')
28
28
  : resolve(__dirname, '..', 'src');
29
29
 
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  import { builtinModules } from 'node:module';
15
- import type { Plugin } from 'vite';
15
+ import { esmExternalRequirePlugin, type Plugin } from 'vite';
16
16
  import { EXPLICIT_MARKERS } from '../analyze/poison-rules.ts';
17
17
 
18
18
  // The poison-pill marker packages (server-only, client-only) must never be
@@ -129,7 +129,22 @@ export function timberServerBundle(): Plugin[] {
129
129
  },
130
130
  ssr: {
131
131
  resolve: { noExternal: true, external: BUILD_ONLY_EXTERNALS },
132
- build: { rolldownOptions: { external: [/^cloudflare:/] } },
132
+ build: {
133
+ rolldownOptions: {
134
+ external: [/^cloudflare:/],
135
+ // The webworker target gives the SSR bundle a `__require`
136
+ // shim that throws, so a bundled CJS module that requires a
137
+ // Node built-in fails to evaluate. React's Node entries do
138
+ // (`react-dom/server.node`, the Flight client behind
139
+ // `@vitejs/plugin-rsc/ssr.node`): without this, SSR on Node
140
+ // silently fell back to Web Streams in production. Rewriting
141
+ // those requires as ESM imports loads them from the runtime,
142
+ // natively on Node and through nodejs_compat on Workers.
143
+ // The RSC bundle targets node, whose createRequire shim
144
+ // already resolves them (see createRequireFixPlugin).
145
+ plugins: [esmExternalRequirePlugin({ external: NODE_BUILTINS })],
146
+ },
147
+ },
133
148
  define: serverDefine,
134
149
  },
135
150
  },
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Server action bound-args encryption, rendered through `renderFlight`.
3
+ *
4
+ * plugin-rsc injects `@vitejs/plugin-rsc/utils/encryption-runtime` into every
5
+ * inline `'use server'` closure to encrypt its captured variables. That
6
+ * runtime serializes with plugin-rsc's `renderToReadableStream` — the edge
7
+ * Flight server — even from `rsc.node`. On Node every other render uses the
8
+ * Node Flight server, and React allows one Flight server build to render per
9
+ * process ("Currently React only supports one RSC renderer at a time"), so
10
+ * every page with such a closure failed to render. `timber-encryption-runtime`
11
+ * (plugins/encryption-runtime.ts) resolves plugin-rsc's runtime to this
12
+ * module instead (TIM-1585).
13
+ *
14
+ * Same wire format as plugin-rsc's runtime: Flight bytes, AES-GCM under the
15
+ * build's key (`virtual:vite-rsc/encryption-key`), with a 16-byte random IV
16
+ * prepended, as base64. Decryption decodes with the Flight client, which
17
+ * installs no server dispatcher.
18
+ *
19
+ * See design/08-forms-and-actions.md §"Bound Args Encryption".
20
+ */
21
+
22
+ import { createFromReadableStream } from '@vitejs/plugin-rsc/rsc';
23
+ import encryptionKeySource from 'virtual:vite-rsc/encryption-key';
24
+ import { collectFlightBytes } from '../server/flight-source.ts';
25
+ import { flightBytesFromBase64, flightBytesToBase64 } from '../shared/flight-base64.ts';
26
+ import { renderFlight } from './render-flight.ts';
27
+
28
+ /**
29
+ * Ceiling on serializing bound args. They are values already in hand, so
30
+ * only a nested promise that never settles could reach it.
31
+ */
32
+ const SERIALIZE_TIMEOUT_MS = 30_000;
33
+
34
+ let keyPromise: Promise<CryptoKey> | undefined;
35
+ function encryptionKey(): Promise<CryptoKey> {
36
+ keyPromise ??= Promise.resolve(encryptionKeySource()).then((key) =>
37
+ crypto.subtle.importKey('raw', flightBytesFromBase64(key), { name: 'AES-GCM' }, true, [
38
+ 'encrypt',
39
+ 'decrypt',
40
+ ])
41
+ );
42
+ return keyPromise;
43
+ }
44
+
45
+ /** Serialize bound args with Flight and encrypt them. */
46
+ export async function encryptActionBoundArgs(value: unknown): Promise<string> {
47
+ const serialized = await collectFlightBytes(
48
+ renderFlight(value),
49
+ SERIALIZE_TIMEOUT_MS,
50
+ '[timber] server action bound args encryption'
51
+ );
52
+ const iv = crypto.getRandomValues(new Uint8Array(16));
53
+ const encrypted = new Uint8Array(
54
+ await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, await encryptionKey(), serialized)
55
+ );
56
+ const out = new Uint8Array(iv.byteLength + encrypted.byteLength);
57
+ out.set(iv, 0);
58
+ out.set(encrypted, iv.byteLength);
59
+ return flightBytesToBase64(out);
60
+ }
61
+
62
+ /** Decrypt bound args and decode them with the Flight client. */
63
+ export async function decryptActionBoundArgs(encrypted: unknown): Promise<unknown> {
64
+ const bytes = flightBytesFromBase64(String(await encrypted));
65
+ const decrypted = await crypto.subtle.decrypt(
66
+ { name: 'AES-GCM', iv: bytes.slice(0, 16) },
67
+ await encryptionKey(),
68
+ bytes.slice(16)
69
+ );
70
+ return createFromReadableStream(
71
+ new ReadableStream<Uint8Array>({
72
+ start(controller) {
73
+ controller.enqueue(new Uint8Array(decrypted));
74
+ controller.close();
75
+ },
76
+ })
77
+ );
78
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `renderFlight` — the only way to render Flight in the RSC environment.
3
+ *
4
+ * Kept apart from `rsc.ts` so the action-encryption runtime
5
+ * (`encryption-runtime.ts`), which `rsc.ts` re-exports, can import it without
6
+ * a cycle. See server/flight-source.ts.
7
+ */
8
+
9
+ import { renderToReadableStream } from '@vitejs/plugin-rsc/rsc';
10
+ import { createRenderFlight } from '../server/flight-source.ts';
11
+ import { nodeStreamsPlatform } from '../server/node-streams-platform.ts';
12
+
13
+ // Behind the one platform probe SSR also reads, so both environments of one
14
+ // process agree on the source kind, and Workers never evaluate the Node
15
+ // renderer.
16
+ const nodeServer = nodeStreamsPlatform ? await import('@vitejs/plugin-rsc/rsc.node') : null;
17
+
18
+ /**
19
+ * Render a model to Flight. On Node: `renderToPipeableStream` from
20
+ * `@vitejs/plugin-rsc/rsc.node`, into an object-mode Node stream. Everywhere
21
+ * else: `renderToReadableStream`.
22
+ */
23
+ export const renderFlight = createRenderFlight(
24
+ renderToReadableStream,
25
+ nodeServer ? nodeServer.renderToPipeableStream : null
26
+ );
@@ -8,19 +8,22 @@
8
8
  * touches the RSC runtime.
9
9
  *
10
10
  * Keep this as thin pass-through re-exports — the value is the single choke
11
- * point, not abstraction.
11
+ * point, not abstraction. The exception is `renderFlight`, the only way to
12
+ * render Flight (render-flight.ts). Bound-args encryption is plugin-rsc's
13
+ * injected runtime, resolved to encryption-runtime.ts so it renders through
14
+ * `renderFlight` too.
12
15
  */
13
16
 
17
+ // The only way to render Flight; see render-flight.ts.
18
+ export { renderFlight } from './render-flight.ts';
19
+
14
20
  export {
15
- renderToReadableStream,
16
21
  loadServerAction,
17
22
  decodeReply,
18
23
  decodeAction,
19
24
  // No-JS action result → the `useActionState` hook that submitted it
20
25
  // (server/action-handler.ts), as Next.js does in its action handler.
21
26
  decodeFormState,
22
- encryptActionBoundArgs,
23
- decryptActionBoundArgs,
24
27
  // Flight client running INSIDE the RSC environment — decodes a cached
25
28
  // flight payload back into React elements. Client references revive as
26
29
  // re-serializable reference proxies via plugin-rsc's server-decode