@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.
- package/dist/_chunks/chains-CDK1AWZQ.js +1 -0
- package/dist/_chunks/{chains-YKZ8WpIW.js → chains-e_Buf9vg.js} +2 -7
- package/dist/_chunks/{chains-YKZ8WpIW.js.map → chains-e_Buf9vg.js.map} +1 -1
- package/dist/_chunks/{cli-check-D2WtbNqo.js → cli-check-DDwCkeDY.js} +2 -2
- package/dist/_chunks/{cli-check-D2WtbNqo.js.map → cli-check-DDwCkeDY.js.map} +1 -1
- package/dist/_chunks/cli-context-BJQB6rtF.js +1 -0
- package/dist/_chunks/{cli-context-By7k2xVo.js → cli-context-_mPttGGY.js} +3 -3
- package/dist/_chunks/{cli-context-By7k2xVo.js.map → cli-context-_mPttGGY.js.map} +1 -1
- package/dist/_chunks/{cli-schema-sync-CySLKrO3.js → cli-schema-sync-BdIebmk3.js} +3 -12
- package/dist/_chunks/{cli-schema-sync-CySLKrO3.js.map → cli-schema-sync-BdIebmk3.js.map} +1 -1
- package/dist/_chunks/cli-schema-sync-CLNfXQDK.js +1 -0
- package/dist/_chunks/dev-server-DkytOEG2.js +1 -0
- package/dist/_chunks/{dev-server-B8zsT-ee.js → dev-server-DnODXuNM.js} +31 -14
- package/dist/_chunks/{dev-server-B8zsT-ee.js.map → dev-server-DnODXuNM.js.map} +1 -1
- package/dist/_chunks/flight-source-node-0dE-t3kq.js +519 -0
- package/dist/_chunks/flight-source-node-0dE-t3kq.js.map +1 -0
- package/dist/_chunks/{live-graph-BhtrZpRd.js → live-graph-tSWrv8eH.js} +2 -2
- package/dist/_chunks/{live-graph-BhtrZpRd.js.map → live-graph-tSWrv8eH.js.map} +1 -1
- package/dist/_chunks/node-response-Dibufw_b.js +187 -0
- package/dist/_chunks/node-response-Dibufw_b.js.map +1 -0
- package/dist/_chunks/{plugin-context-BPBPc3lL.js → plugin-context-DxMMvjUt.js} +2 -18
- package/dist/_chunks/{plugin-context-BPBPc3lL.js.map → plugin-context-DxMMvjUt.js.map} +1 -1
- package/dist/_chunks/plugin-context-uDHFqHHJ.js +1 -0
- package/dist/_chunks/{walkers-Ber9bamD.js → walkers-qu8TpiLh.js} +2 -2
- package/dist/_chunks/{walkers-Ber9bamD.js.map → walkers-qu8TpiLh.js.map} +1 -1
- package/dist/adapters/nitro-preview.d.ts.map +1 -1
- package/dist/adapters/nitro.js +40 -1
- package/dist/adapters/nitro.js.map +1 -1
- package/dist/analyze/crawl-entry.js +2 -2
- package/dist/analyze/graph-command.js +3 -3
- package/dist/analyze/graph-command.js.map +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/client/browser-entry/form-state.d.ts.map +1 -1
- package/dist/client/browser-entry/index.d.ts +1 -1
- package/dist/client/browser-entry/rsc-stream.d.ts +4 -1
- package/dist/client/browser-entry/rsc-stream.d.ts.map +1 -1
- package/dist/client/react-root.d.ts +6 -0
- package/dist/client/react-root.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -5
- package/dist/index.js.map +1 -1
- package/dist/plugins/encryption-runtime.d.ts +13 -0
- package/dist/plugins/encryption-runtime.d.ts.map +1 -0
- package/dist/plugins/entries.d.ts +1 -0
- package/dist/plugins/entries.d.ts.map +1 -1
- package/dist/plugins/server-bundle.d.ts +1 -1
- package/dist/plugins/server-bundle.d.ts.map +1 -1
- package/dist/routing/index.js +1 -1
- package/dist/rsc-runtime/encryption-runtime.d.ts +25 -0
- package/dist/rsc-runtime/encryption-runtime.d.ts.map +1 -0
- package/dist/rsc-runtime/render-flight.d.ts +14 -0
- package/dist/rsc-runtime/render-flight.d.ts.map +1 -0
- package/dist/rsc-runtime/rsc.d.ts +6 -2
- package/dist/rsc-runtime/rsc.d.ts.map +1 -1
- package/dist/rsc-runtime/ssr.d.ts +6 -12
- package/dist/rsc-runtime/ssr.d.ts.map +1 -1
- package/dist/server/action-handler.d.ts.map +1 -1
- package/dist/server/compress.d.ts +2 -0
- package/dist/server/compress.d.ts.map +1 -1
- package/dist/server/deny-renderer.d.ts +2 -1
- package/dist/server/deny-renderer.d.ts.map +1 -1
- package/dist/server/flight-injector-core.d.ts +125 -0
- package/dist/server/flight-injector-core.d.ts.map +1 -0
- package/dist/server/flight-scripts.d.ts +9 -0
- package/dist/server/flight-scripts.d.ts.map +1 -1
- package/dist/server/flight-source-node.d.ts +105 -0
- package/dist/server/flight-source-node.d.ts.map +1 -0
- package/dist/server/flight-source.d.ts +136 -0
- package/dist/server/flight-source.d.ts.map +1 -0
- package/dist/server/head-response.d.ts.map +1 -1
- package/dist/server/html-injector-core.d.ts +3 -91
- package/dist/server/html-injector-core.d.ts.map +1 -1
- package/dist/server/html-injectors.d.ts +5 -17
- package/dist/server/html-injectors.d.ts.map +1 -1
- package/dist/server/internal.js +78 -138
- package/dist/server/internal.js.map +1 -1
- package/dist/server/node-body-response.d.ts +55 -0
- package/dist/server/node-body-response.d.ts.map +1 -0
- package/dist/server/node-response.d.ts +62 -0
- package/dist/server/node-response.d.ts.map +1 -0
- package/dist/server/node-stream-transforms.d.ts +24 -21
- package/dist/server/node-stream-transforms.d.ts.map +1 -1
- package/dist/server/node-streams-platform.d.ts +21 -0
- package/dist/server/node-streams-platform.d.ts.map +1 -0
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts +2 -3
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/rsc-entry/index.d.ts.map +1 -1
- package/dist/server/rsc-entry/render-route.d.ts +4 -1
- package/dist/server/rsc-entry/render-route.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-payload.d.ts +9 -6
- package/dist/server/rsc-entry/rsc-payload.d.ts.map +1 -1
- package/dist/server/rsc-entry/rsc-stream.d.ts +9 -4
- package/dist/server/rsc-entry/rsc-stream.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-bridge.d.ts +2 -1
- package/dist/server/rsc-entry/ssr-bridge.d.ts.map +1 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts +2 -1
- package/dist/server/rsc-entry/ssr-renderer.d.ts.map +1 -1
- package/dist/server/ssr-bridge-types.d.ts +9 -4
- package/dist/server/ssr-bridge-types.d.ts.map +1 -1
- package/dist/server/ssr-entry.d.ts +8 -5
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/ssr-render.d.ts +7 -16
- package/dist/server/ssr-render.d.ts.map +1 -1
- package/dist/server/stream-utils.d.ts +44 -10
- package/dist/server/stream-utils.d.ts.map +1 -1
- package/dist/shared/flight-base64.d.ts +13 -0
- package/dist/shared/flight-base64.d.ts.map +1 -0
- package/dist/shared/flight-segment.d.ts +18 -0
- package/dist/shared/flight-segment.d.ts.map +1 -0
- package/dist/shared/form-state-flight.d.ts +0 -4
- package/dist/shared/form-state-flight.d.ts.map +1 -1
- package/docs/learn/12-error-handling.mdx +1 -1
- package/package.json +1 -1
- package/src/adapters/nitro-preview.ts +39 -0
- package/src/client/browser-entry/form-state.ts +3 -2
- package/src/client/browser-entry/index.ts +14 -8
- package/src/client/browser-entry/rsc-stream.ts +14 -14
- package/src/client/react-root.ts +25 -2
- package/src/index.ts +2 -0
- package/src/plugins/encryption-runtime.ts +31 -0
- package/src/plugins/entries.ts +1 -1
- package/src/plugins/server-bundle.ts +17 -2
- package/src/rsc-runtime/encryption-runtime.ts +78 -0
- package/src/rsc-runtime/render-flight.ts +26 -0
- package/src/rsc-runtime/rsc.ts +7 -4
- package/src/rsc-runtime/ssr.ts +10 -48
- package/src/rsc-runtime/vendor-types.d.ts +31 -2
- package/src/server/action-handler.ts +43 -44
- package/src/server/compress.ts +49 -12
- package/src/server/deny-renderer.ts +14 -7
- package/src/server/flight-injector-core.ts +328 -0
- package/src/server/flight-scripts.ts +14 -2
- package/src/server/flight-source-node.ts +430 -0
- package/src/server/flight-source.ts +288 -0
- package/src/server/form-state-flight.ts +4 -4
- package/src/server/head-response.ts +6 -10
- package/src/server/html-injector-core.ts +24 -216
- package/src/server/html-injectors.ts +12 -71
- package/src/server/node-body-response.ts +236 -0
- package/src/server/node-response.ts +93 -0
- package/src/server/node-stream-transforms.ts +70 -53
- package/src/server/node-streams-platform.ts +23 -0
- package/src/server/pipeline-helpers.ts +3 -1
- package/src/server/pipeline.ts +14 -6
- package/src/server/prebuilt/capture-render.ts +5 -5
- package/src/server/prebuilt-runtime.ts +7 -10
- package/src/server/rsc-entry/error-renderer.ts +8 -4
- package/src/server/rsc-entry/index.ts +4 -2
- package/src/server/rsc-entry/render-route.ts +5 -2
- package/src/server/rsc-entry/rsc-payload.ts +52 -73
- package/src/server/rsc-entry/rsc-stream.ts +102 -106
- package/src/server/rsc-entry/ssr-bridge.ts +32 -10
- package/src/server/rsc-entry/ssr-renderer.ts +15 -18
- package/src/server/ssr-bridge-types.ts +10 -4
- package/src/server/ssr-entry.ts +56 -52
- package/src/server/ssr-render.ts +41 -76
- package/src/server/stream-utils.ts +125 -70
- package/src/shared/flight-base64.ts +23 -0
- package/src/shared/flight-segment.ts +35 -0
- package/src/shared/form-state-flight.ts +0 -15
- package/dist/_chunks/rolldown-runtime-D7D4PA-g.js +0 -13
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* HTML injector core — pure stateful helpers for streaming HTML post-processing.
|
|
3
3
|
*
|
|
4
4
|
* These helpers contain the actual byte/string logic for the held-flush
|
|
5
|
-
* streaming pipeline (buffered transforms, suffix moving, head injection
|
|
6
|
-
* RSC flight interleaving
|
|
5
|
+
* streaming pipeline (buffered transforms, suffix moving, head injection;
|
|
6
|
+
* RSC flight interleaving has its own core, `flight-injector-core.ts`).
|
|
7
|
+
* They are stream-shape agnostic: they know
|
|
7
8
|
* nothing about Web `TransformStream` or Node.js `Transform` and contain
|
|
8
9
|
* no `setImmediate` scheduling or controller plumbing.
|
|
9
10
|
*
|
|
@@ -23,14 +24,10 @@
|
|
|
23
24
|
*
|
|
24
25
|
* Design docs: 02-rendering-pipeline.md §"Streaming Constraints", 18-build-system.md §"Entry Files"
|
|
25
26
|
*/
|
|
26
|
-
import { type Machine } from '../utils/state-machine.ts';
|
|
27
|
-
import { type FlightInjectionState, type FlightInjectionEvent } from './flight-injection-state.ts';
|
|
28
27
|
/** Closing tags React Fizz emits inside the shell chunk. */
|
|
29
28
|
export declare const SUFFIX = "</body></html>";
|
|
30
29
|
/** UTF-8 bytes of {@link SUFFIX}. Cached so wrappers don't re-encode per request. */
|
|
31
30
|
export declare const SUFFIX_BYTES: Uint8Array;
|
|
32
|
-
/** Encode a UTF-8 string. Convenience for wrappers that need a single source of truth. */
|
|
33
|
-
export declare function encodeUtf8(text: string): Uint8Array;
|
|
34
31
|
/**
|
|
35
32
|
* Pure buffer state for the buffered transform.
|
|
36
33
|
*
|
|
@@ -169,89 +166,4 @@ export declare function processInjectorChunk(state: InjectorState, chunk: Uint8A
|
|
|
169
166
|
* itself is silently skipped — same behaviour as before extraction.)
|
|
170
167
|
*/
|
|
171
168
|
export declare function injectorFlush(state: InjectorState): Uint8Array | null;
|
|
172
|
-
/**
|
|
173
|
-
* Pure async core of the RSC flight-injection transform.
|
|
174
|
-
*
|
|
175
|
-
* Both wrappers (Web `TransformStream` and Node `Transform`) implement the
|
|
176
|
-
* exact same protocol around an RSC reader:
|
|
177
|
-
*
|
|
178
|
-
* 1. On the first HTML chunk, send `FIRST_CHUNK` and start the pull loop.
|
|
179
|
-
* 2. The pull loop reads from `rscReader` (timeout-guarded), wraps each
|
|
180
|
-
* chunk in a `<script>` via `flightChunkScript`, and pushes it onto a
|
|
181
|
-
* pending queue. Between reads, it yields with a single-shot
|
|
182
|
-
* `setImmediate` so HTML chunks get event-loop priority — and after
|
|
183
|
-
* yielding, it drains the queue (via the wrapper's `onYieldDrain`)
|
|
184
|
-
* so flight data reaches the client at shell-flush time.
|
|
185
|
-
* 3. After every emitted HTML chunk, the wrapper drains the queue.
|
|
186
|
-
* 4. On `flush()` the wrapper sends `HTML_DONE` and awaits `pullPromise`.
|
|
187
|
-
* No polling — just `.then()`.
|
|
188
|
-
*
|
|
189
|
-
* The wrappers only differ in:
|
|
190
|
-
* - How they push bytes (controller.enqueue vs transform.push).
|
|
191
|
-
* - How they signal a terminal error (controller.error vs transform.destroy).
|
|
192
|
-
*
|
|
193
|
-
* This class owns the state machine, the pending queue, and the pull
|
|
194
|
-
* loop itself. The wrapper supplies the drain callback and consumes the
|
|
195
|
-
* pending queue + machine state to decide what to push.
|
|
196
|
-
*
|
|
197
|
-
* **No polling.** See design/02-rendering-pipeline.md §"No Polling".
|
|
198
|
-
* **Always timeout-guarded reads.** Per design/02 §"Streaming Constraints".
|
|
199
|
-
*/
|
|
200
|
-
export interface FlightInjectorOptions {
|
|
201
|
-
/**
|
|
202
|
-
* Timeout in milliseconds for individual RSC stream reads. If a single
|
|
203
|
-
* `rscReader.read()` call does not resolve within this duration, the
|
|
204
|
-
* read is aborted and the stream errors with a `RenderTimeoutError`.
|
|
205
|
-
* Default: 30000 (30s). `0` ("disabled") still enforces a 120s ceiling
|
|
206
|
-
* so a stalled RSC stream can never hang the connection forever.
|
|
207
|
-
*/
|
|
208
|
-
renderTimeoutMs?: number;
|
|
209
|
-
/** Signal that fires when an unhandled RSC error is detected. */
|
|
210
|
-
errorSignal?: AbortSignal;
|
|
211
|
-
/** Request CSP nonce, stamped on every emitted `<script>` (TIM-1414). */
|
|
212
|
-
nonce?: string;
|
|
213
|
-
}
|
|
214
|
-
export declare class FlightInjectorCore {
|
|
215
|
-
readonly machine: Machine<FlightInjectionState, FlightInjectionEvent>;
|
|
216
|
-
/** Script chunks waiting to be drained between HTML chunks. */
|
|
217
|
-
readonly pending: Uint8Array[];
|
|
218
|
-
private readonly rscReader;
|
|
219
|
-
private readonly timeoutMs;
|
|
220
|
-
private readonly errorSignal?;
|
|
221
|
-
private readonly nonce?;
|
|
222
|
-
private readonly decoder;
|
|
223
|
-
private pullPromise;
|
|
224
|
-
private _aborted;
|
|
225
|
-
constructor(rscStream: ReadableStream<Uint8Array>, options?: FlightInjectorOptions);
|
|
226
|
-
/** Tell the machine the first HTML chunk has arrived. Idempotent-ish: caller checks. */
|
|
227
|
-
notifyFirstChunk(): void;
|
|
228
|
-
/** Tell the machine HTML output is finished — pull loop will stop yielding. */
|
|
229
|
-
notifyHtmlDone(): void;
|
|
230
|
-
get isInit(): boolean;
|
|
231
|
-
get isPullDone(): boolean;
|
|
232
|
-
get hasPullPromise(): boolean;
|
|
233
|
-
/**
|
|
234
|
-
* Get (or start) the pull-loop promise. The wrapper calls this from
|
|
235
|
-
* `flush()` and chains `.then()` onto it — never `await` without an
|
|
236
|
-
* existing finish callback (we don't want to block transform()).
|
|
237
|
-
*
|
|
238
|
-
* `onYieldDrain` is invoked between RSC reads while HTML is still
|
|
239
|
-
* streaming. It must drain the pending queue into the output stream.
|
|
240
|
-
*/
|
|
241
|
-
ensurePullLoop(onYieldDrain: () => void): Promise<void>;
|
|
242
|
-
/**
|
|
243
|
-
* Get the current terminal error if the machine is in the error phase,
|
|
244
|
-
* else `null`. Wrappers use this after a drain to decide whether to
|
|
245
|
-
* `controller.error()` / `transform.destroy()`.
|
|
246
|
-
*/
|
|
247
|
-
get terminalError(): unknown;
|
|
248
|
-
/**
|
|
249
|
-
* Abort the pull loop and release the RSC reader. Called by stream
|
|
250
|
-
* wrappers when the HTML pipeline is torn down (Node `destroy()`,
|
|
251
|
-
* Web `cancel()`). Safe to call multiple times.
|
|
252
|
-
*/
|
|
253
|
-
abort(reason?: unknown): void;
|
|
254
|
-
get isAborted(): boolean;
|
|
255
|
-
private runPullLoop;
|
|
256
|
-
}
|
|
257
169
|
//# sourceMappingURL=html-injector-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injector-core.d.ts","sourceRoot":"","sources":["../../src/server/html-injector-core.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"html-injector-core.d.ts","sourceRoot":"","sources":["../../src/server/html-injector-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH,4DAA4D;AAC5D,eAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,qFAAqF;AACrF,eAAO,MAAM,YAAY,EAAE,UAAmC,CAAC;AAI/D;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAE7C,YAAY,mBAAmB,GAAE,MAAiB,EAEjD;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAIjC;IAED,6EAA6E;IAC7E,KAAK,IAAI,UAAU,GAAG,IAAI,CAYzB;IAED,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,IAAI,OAAO,IAAI,OAAO,CAErB;CACF;AAID;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;CAAE,CAAC;AAEjF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,wEAAwE;IACxE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,IAAI,WAAW,CAM/C;AAkCD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,iBAAiB,CA2B3F;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CAQ1D;AAID;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAU3E;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAA;CAAE,CAAC;AAE/C,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,GAAG,mBAAmB,CAwBjG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,UAAU,GAAG,IAAI,CAGrE"}
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
*
|
|
18
18
|
* Design docs: 02-rendering-pipeline.md, 18-build-system.md §"Entry Files"
|
|
19
19
|
*/
|
|
20
|
-
import { type FlightInjectorOptions } from './
|
|
20
|
+
import { type FlightInjectorOptions } from './flight-injector-core.ts';
|
|
21
|
+
import type { FlightSource } from './flight-source.ts';
|
|
21
22
|
export interface BufferedTransformOptions {
|
|
22
23
|
/**
|
|
23
24
|
* Flush synchronously once the buffer reaches this many bytes.
|
|
@@ -63,17 +64,6 @@ export declare function injectHead(stream: ReadableStream<Uint8Array>, headHtml:
|
|
|
63
64
|
* disabled mode). If no `</body>` is found, the buffer is emitted as-is.
|
|
64
65
|
*/
|
|
65
66
|
export declare function injectScripts(stream: ReadableStream<Uint8Array>, scriptsHtml: string): ReadableStream<Uint8Array>;
|
|
66
|
-
/**
|
|
67
|
-
* Transform an RSC Flight stream into a stream of inline `<script>` tags.
|
|
68
|
-
*
|
|
69
|
-
* Uses a **pull-based** ReadableStream — the consumer (the injection
|
|
70
|
-
* transform) drives reads from the RSC stream on demand. No background
|
|
71
|
-
* reader, no shared mutable arrays, no race conditions. Each RSC chunk
|
|
72
|
-
* becomes `<script>self.__timber_f.push([1,"data"])</script>`. The
|
|
73
|
-
* init script (which creates `__timber_f`) is in `<head>` via
|
|
74
|
-
* `flightInitScript()` — see flight-scripts.ts.
|
|
75
|
-
*/
|
|
76
|
-
export declare function createInlinedRscStream(rscStream: ReadableStream<Uint8Array>, renderTimeoutMs?: number, nonce?: string): ReadableStream<Uint8Array>;
|
|
77
67
|
/**
|
|
78
68
|
* Progressively inline RSC Flight payload chunks into the HTML stream.
|
|
79
69
|
*
|
|
@@ -85,17 +75,15 @@ export declare function createInlinedRscStream(rscStream: ReadableStream<Uint8Ar
|
|
|
85
75
|
* 2. moveSuffix strips `</body></html>` and re-emits at end so injected
|
|
86
76
|
* scripts appear before the closing tags.
|
|
87
77
|
*
|
|
88
|
-
* Wrapping happens inside `FlightInjectorCore
|
|
89
|
-
*
|
|
90
|
-
* — do not pre-wrap with `createInlinedRscStream` (that helper still
|
|
91
|
-
* exists for callers that want a standalone scripted stream).
|
|
78
|
+
* Wrapping happens inside `FlightInjectorCore`; the inline Flight source is
|
|
79
|
+
* passed to it as is.
|
|
92
80
|
*
|
|
93
81
|
* The client reads these script tags via `self.__timber_f` and feeds
|
|
94
82
|
* them to `createFromReadableStream` for progressive hydration. Stream
|
|
95
83
|
* completion is signaled by the `DOMContentLoaded` event on the client
|
|
96
84
|
* side — no custom done flag needed.
|
|
97
85
|
*/
|
|
98
|
-
export declare function injectRscPayload(htmlStream: ReadableStream<Uint8Array>,
|
|
86
|
+
export declare function injectRscPayload(htmlStream: ReadableStream<Uint8Array>, rscSource: FlightSource | undefined, options?: FlightInjectorOptions): ReadableStream<Uint8Array>;
|
|
99
87
|
/**
|
|
100
88
|
* Client bootstrap configuration returned by buildClientScripts.
|
|
101
89
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-injectors.d.ts","sourceRoot":"","sources":["../../src/server/html-injectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"html-injectors.d.ts","sourceRoot":"","sources":["../../src/server/html-injectors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKvD,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CACvC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,wBAA6B,GACrC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CA8BzC;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAqBhF;AAuCD;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,QAAQ,EAAE,MAAM,GACf,cAAc,CAAC,UAAU,CAAC,CAE5B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,WAAW,EAAE,MAAM,GAClB,cAAc,CAAC,UAAU,CAAC,CAE5B;AA+ED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,CAAC,UAAU,CAAC,EACtC,SAAS,EAAE,YAAY,GAAG,SAAS,EACnC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,cAAc,CAAC,UAAU,CAAC,CAK5B;AAID;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,qBAAqB;IACpC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;CACtB;AAqBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IACjE,GAAG,EAAE,OAAO,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,qBAAqB,EAAE,aAAa,CAAC;CAC7D,GAAG,qBAAqB,CAqExB"}
|
package/dist/server/internal.js
CHANGED
|
@@ -11,6 +11,7 @@ import { i as isRscCacheKeyShape, n as RSC_KEY_PARAM, r as appVisibleSearch, s a
|
|
|
11
11
|
import { C as setMutableCookieContext, S as setMatchedSegmentPath, T as runOutsideReactCacheScope, b as markResponseFlushed, f as getCookie, g as getHeader, h as applyRequestHeaderOverlay, i as coerce, m as getSetCookieHeaders, o as DenySignal, s as RedirectSignal, t as executeAction, v as getSearchParams, w as setSegmentParams, x as runWithRequestContext, y as getSegmentParams } from "../_chunks/actions-BwkmAYXq.js";
|
|
12
12
|
import { a as getManifestEntry, b as wasInvalidatedSince, c as lookupPrebuiltPayload, d as checkVersionSkew, i as storeOverlayEntry, l as setPrebuiltPayloadSource, n as lookupOverlay, o as hasPrebuiltPayloadSource, r as overlayKey, s as isParamIndependent, u as applyReloadHeaders, v as currentInvalidationEpoch, x as getWaitUntil, y as lastInvalidationEpochFor } from "../_chunks/cache-api-LA3sBpUS.js";
|
|
13
13
|
import { n as createSingleflight } from "../_chunks/singleflight-BeVMMKi0.js";
|
|
14
|
+
import { c as drainWithDeadline, i as withResponseInit, n as discardResponseBody, o as concatBytes, r as nodeBodyOps, u as wrapResponseWithStreamTiming } from "../_chunks/node-response-Dibufw_b.js";
|
|
14
15
|
import { n as toBracketKey } from "../_chunks/resolve-schema-CBR6Lm4i.js";
|
|
15
16
|
import { t as normalizeParamValue } from "../_chunks/param-value-C8TNYchQ.js";
|
|
16
17
|
import { l as TIMBER_ERROR_HEADER, t as StatusPageMarker } from "../_chunks/status-page-marker-BRX9Ib-d.js";
|
|
@@ -107,131 +108,6 @@ function getServerTimingHeader() {
|
|
|
107
108
|
return result || null;
|
|
108
109
|
}
|
|
109
110
|
//#endregion
|
|
110
|
-
//#region src/server/stream-utils.ts
|
|
111
|
-
/**
|
|
112
|
-
* Stream utilities for the RSC rendering pipeline.
|
|
113
|
-
*
|
|
114
|
-
* teeWithErrorPropagation — wraps native ReadableStream.tee() with:
|
|
115
|
-
* 1. Cross-branch error propagation (error on one branch cancels the other)
|
|
116
|
-
* 2. Buffer divergence monitoring (warns + cancels when threshold exceeded)
|
|
117
|
-
*
|
|
118
|
-
* This prevents two classes of bugs:
|
|
119
|
-
* - Silent stalls when one tee branch errors and the other hangs indefinitely
|
|
120
|
-
* - Unbounded memory growth when one consumer (SSR) is much slower than the other
|
|
121
|
-
*
|
|
122
|
-
* Design doc: 02-rendering-pipeline.md §"RSC → SSR → Client Hydration"
|
|
123
|
-
*/
|
|
124
|
-
/**
|
|
125
|
-
* Wrap a response body with stream-lifecycle timing instrumentation.
|
|
126
|
-
*
|
|
127
|
-
* Logs firstChunk, lastChunk, close, maxGap (largest inter-chunk gap),
|
|
128
|
-
* chunk count, and byte count on stream termination (clean close OR
|
|
129
|
-
* cancellation/disconnect). Gated behind `serverTiming: 'detailed'`.
|
|
130
|
-
*
|
|
131
|
-
* Uses a manual reader pump to guarantee logging on all termination
|
|
132
|
-
* paths — TransformStream.flush() is not called on cancellation.
|
|
133
|
-
*/
|
|
134
|
-
function wrapResponseWithStreamTiming(body, startTime) {
|
|
135
|
-
let firstChunkMs = 0;
|
|
136
|
-
let lastChunkMs = 0;
|
|
137
|
-
let maxGapMs = 0;
|
|
138
|
-
let prevChunkTime = 0;
|
|
139
|
-
let chunks = 0;
|
|
140
|
-
let bytes = 0;
|
|
141
|
-
let cancelled = false;
|
|
142
|
-
function emitLog() {
|
|
143
|
-
const closeMs = Math.round(performance.now() - startTime);
|
|
144
|
-
getLogger().debug("stream-lifecycle", {
|
|
145
|
-
firstChunkMs,
|
|
146
|
-
lastChunkMs,
|
|
147
|
-
closeMs,
|
|
148
|
-
maxGapMs,
|
|
149
|
-
chunks,
|
|
150
|
-
bytes,
|
|
151
|
-
...cancelled ? { cancelled: true } : {}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
const reader = body.getReader();
|
|
155
|
-
return new ReadableStream({
|
|
156
|
-
async pull(controller) {
|
|
157
|
-
try {
|
|
158
|
-
const { done, value } = await reader.read();
|
|
159
|
-
if (done) {
|
|
160
|
-
emitLog();
|
|
161
|
-
controller.close();
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const now = performance.now();
|
|
165
|
-
const relativeMs = Math.round(now - startTime);
|
|
166
|
-
if (chunks === 0) firstChunkMs = relativeMs;
|
|
167
|
-
else {
|
|
168
|
-
const gap = Math.round(now - prevChunkTime);
|
|
169
|
-
if (gap > maxGapMs) maxGapMs = gap;
|
|
170
|
-
}
|
|
171
|
-
prevChunkTime = now;
|
|
172
|
-
lastChunkMs = relativeMs;
|
|
173
|
-
chunks++;
|
|
174
|
-
bytes += value.byteLength;
|
|
175
|
-
controller.enqueue(value);
|
|
176
|
-
} catch (err) {
|
|
177
|
-
emitLog();
|
|
178
|
-
controller.error(err);
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
cancel(reason) {
|
|
182
|
-
cancelled = true;
|
|
183
|
-
emitLog();
|
|
184
|
-
reader.cancel(reason).catch(() => {});
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Read a byte stream to completion under one overall deadline and return
|
|
190
|
-
* the concatenated bytes. Every read is raced against the time remaining,
|
|
191
|
-
* and the reader is cancelled on every exit, so a stalled upstream never
|
|
192
|
-
* outlives the deadline. See design/02-rendering-pipeline.md §"Always
|
|
193
|
-
* Timeout-Guard Stream Reads".
|
|
194
|
-
*
|
|
195
|
-
* @param label - Prefix for the timeout error message. Both ways the deadline
|
|
196
|
-
* can pass (between reads, or while a read is pending) reject with the same
|
|
197
|
-
* `${label} did not complete within ${timeoutMs}ms`.
|
|
198
|
-
*/
|
|
199
|
-
async function readAllBytesWithDeadline(stream, timeoutMs, label) {
|
|
200
|
-
const reader = stream.getReader();
|
|
201
|
-
const chunks = [];
|
|
202
|
-
let totalLength = 0;
|
|
203
|
-
const deadline = Date.now() + timeoutMs;
|
|
204
|
-
const deadlineError = () => /* @__PURE__ */ new Error(`${label} did not complete within ${timeoutMs}ms`);
|
|
205
|
-
try {
|
|
206
|
-
for (;;) {
|
|
207
|
-
const remaining = deadline - Date.now();
|
|
208
|
-
if (remaining <= 0) throw deadlineError();
|
|
209
|
-
let timer;
|
|
210
|
-
const timeout = new Promise((_, reject) => {
|
|
211
|
-
timer = setTimeout(() => reject(deadlineError()), remaining);
|
|
212
|
-
});
|
|
213
|
-
let result;
|
|
214
|
-
try {
|
|
215
|
-
result = await Promise.race([reader.read(), timeout]);
|
|
216
|
-
} finally {
|
|
217
|
-
clearTimeout(timer);
|
|
218
|
-
}
|
|
219
|
-
if (result.done) break;
|
|
220
|
-
chunks.push(result.value);
|
|
221
|
-
totalLength += result.value.byteLength;
|
|
222
|
-
}
|
|
223
|
-
} finally {
|
|
224
|
-
reader.cancel().catch(() => {});
|
|
225
|
-
}
|
|
226
|
-
const bytes = new Uint8Array(totalLength);
|
|
227
|
-
let offset = 0;
|
|
228
|
-
for (const chunk of chunks) {
|
|
229
|
-
bytes.set(chunk, offset);
|
|
230
|
-
offset += chunk.byteLength;
|
|
231
|
-
}
|
|
232
|
-
return bytes;
|
|
233
|
-
}
|
|
234
|
-
//#endregion
|
|
235
111
|
//#region src/server/instrumentation.ts
|
|
236
112
|
/**
|
|
237
113
|
* Instrumentation — loads and runs the user's instrumentation.ts file.
|
|
@@ -712,7 +588,7 @@ function mergeMissingHeaders(target, source) {
|
|
|
712
588
|
* rewrap at the framework boundary instead.
|
|
713
589
|
*/
|
|
714
590
|
function cloneWithMutableHeaders(response) {
|
|
715
|
-
return
|
|
591
|
+
return withResponseInit(response, {
|
|
716
592
|
status: response.status,
|
|
717
593
|
statusText: response.statusText,
|
|
718
594
|
headers: new Headers(response.headers)
|
|
@@ -2014,11 +1890,9 @@ async function enforceRscCacheKey(req, response) {
|
|
|
2014
1890
|
*/
|
|
2015
1891
|
function stripHeadBody(response, method) {
|
|
2016
1892
|
if (method.toUpperCase() !== "HEAD") return response;
|
|
2017
|
-
const
|
|
2018
|
-
if (body === null) return response;
|
|
2019
|
-
|
|
2020
|
-
body.cancel().catch(() => {});
|
|
2021
|
-
} catch {}
|
|
1893
|
+
const nodeBody = nodeBodyOps(response);
|
|
1894
|
+
if (nodeBody ? !nodeBody.hasBody : response.body === null) return response;
|
|
1895
|
+
discardResponseBody(response);
|
|
2022
1896
|
return new Response(null, {
|
|
2023
1897
|
status: response.status,
|
|
2024
1898
|
statusText: response.statusText,
|
|
@@ -2116,11 +1990,15 @@ function createPipeline(config) {
|
|
|
2116
1990
|
const totalMs = Math.round(performance.now() - startTime);
|
|
2117
1991
|
result.headers.set("Server-Timing", `total;dur=${totalMs}`);
|
|
2118
1992
|
}
|
|
2119
|
-
if (serverTiming === "detailed"
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
1993
|
+
if (serverTiming === "detailed") {
|
|
1994
|
+
const nodeBody = nodeBodyOps(result);
|
|
1995
|
+
if (nodeBody) result = nodeBody.timed(startTime);
|
|
1996
|
+
else if (result.body) result = new Response(wrapResponseWithStreamTiming(result.body, startTime), {
|
|
1997
|
+
status: result.status,
|
|
1998
|
+
statusText: result.statusText,
|
|
1999
|
+
headers: result.headers
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2124
2002
|
return result;
|
|
2125
2003
|
});
|
|
2126
2004
|
} finally {
|
|
@@ -4318,6 +4196,68 @@ function noteWrapperRender(innerId, options, props) {
|
|
|
4318
4196
|
}
|
|
4319
4197
|
}
|
|
4320
4198
|
//#endregion
|
|
4199
|
+
//#region src/server/flight-source.ts
|
|
4200
|
+
var nodeFlight = typeof process !== "undefined" && process.release?.name === "node" && !(typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers") ? await import("../_chunks/flight-source-node-0dE-t3kq.js") : null;
|
|
4201
|
+
/** The Node helpers, which a `kind: 'node'` source can only exist alongside. */
|
|
4202
|
+
function requireNodeFlight() {
|
|
4203
|
+
if (!nodeFlight) throw new Error("[timber] a Node Flight source reached a runtime without node:stream");
|
|
4204
|
+
return nodeFlight;
|
|
4205
|
+
}
|
|
4206
|
+
/**
|
|
4207
|
+
* A pull reader over either kind. `read()` is unguarded: every caller races
|
|
4208
|
+
* it against a timeout (design/02 §"Always Timeout-Guard Stream Reads").
|
|
4209
|
+
* `cancel()` releases the source, which aborts the render.
|
|
4210
|
+
*/
|
|
4211
|
+
function openFlightReader(source) {
|
|
4212
|
+
if (source.kind === "web") {
|
|
4213
|
+
const reader = source.stream.getReader();
|
|
4214
|
+
return {
|
|
4215
|
+
read: () => reader.read(),
|
|
4216
|
+
takeBuffered: () => [],
|
|
4217
|
+
cancel: (reason) => void reader.cancel(reason).catch(() => {})
|
|
4218
|
+
};
|
|
4219
|
+
}
|
|
4220
|
+
const { destroyNodeFlight } = requireNodeFlight();
|
|
4221
|
+
const stream = source.stream;
|
|
4222
|
+
const iterator = stream[Symbol.asyncIterator]();
|
|
4223
|
+
return {
|
|
4224
|
+
read: async () => {
|
|
4225
|
+
const result = await iterator.next();
|
|
4226
|
+
return result.done ? {
|
|
4227
|
+
done: true,
|
|
4228
|
+
value: void 0
|
|
4229
|
+
} : {
|
|
4230
|
+
done: false,
|
|
4231
|
+
value: result.value
|
|
4232
|
+
};
|
|
4233
|
+
},
|
|
4234
|
+
takeBuffered: () => {
|
|
4235
|
+
const chunks = [];
|
|
4236
|
+
while (stream.readableLength > 0 && !stream.destroyed) {
|
|
4237
|
+
const chunk = stream.read();
|
|
4238
|
+
if (chunk === null) break;
|
|
4239
|
+
chunks.push(chunk);
|
|
4240
|
+
}
|
|
4241
|
+
return chunks;
|
|
4242
|
+
},
|
|
4243
|
+
cancel: (reason) => destroyNodeFlight(stream, reason)
|
|
4244
|
+
};
|
|
4245
|
+
}
|
|
4246
|
+
/** A chunk as bytes. */
|
|
4247
|
+
function flightChunkBytes(chunk) {
|
|
4248
|
+
return typeof chunk === "string" ? encoder.encode(chunk) : chunk;
|
|
4249
|
+
}
|
|
4250
|
+
var encoder = new TextEncoder();
|
|
4251
|
+
/**
|
|
4252
|
+
* Read a whole Flight source into bytes under one overall deadline, cancelling
|
|
4253
|
+
* it on every exit (`drainWithDeadline`). For renders whose payload is stored
|
|
4254
|
+
* rather than streamed: the no-JS form state and both prebuilt captures.
|
|
4255
|
+
*/
|
|
4256
|
+
async function collectFlightBytes(source, timeoutMs, label) {
|
|
4257
|
+
const chunks = await drainWithDeadline(openFlightReader(source), timeoutMs, label);
|
|
4258
|
+
return concatBytes(chunks.map(flightChunkBytes));
|
|
4259
|
+
}
|
|
4260
|
+
//#endregion
|
|
4321
4261
|
//#region src/server/prebuilt-runtime.ts
|
|
4322
4262
|
/**
|
|
4323
4263
|
* Prebuilt component runtime — registration target for the timber-prebuilt
|
|
@@ -4477,14 +4417,14 @@ function getCaptureTimeoutMs() {
|
|
|
4477
4417
|
* expiry (design/13 A2, A3).
|
|
4478
4418
|
*/
|
|
4479
4419
|
async function captureComponentPayload(id, component, props, options) {
|
|
4480
|
-
const {
|
|
4420
|
+
const { renderFlight } = requireRscFunctions();
|
|
4481
4421
|
const element = createElement(component, props);
|
|
4482
4422
|
const capture = createCaptureScope(id, options, props);
|
|
4483
4423
|
let renderError;
|
|
4484
4424
|
const store = requestContextAls.getStore();
|
|
4485
4425
|
const discipline = store && shouldCheckKeyDiscipline(id) ? createKeyDisciplineProxy(store) : null;
|
|
4486
4426
|
const doCapture = () => capture.run(async () => {
|
|
4487
|
-
const bytes = await
|
|
4427
|
+
const bytes = await collectFlightBytes(runOutsideReactCacheScope(() => renderFlight(element, { onError(error) {
|
|
4488
4428
|
renderError ??= { error };
|
|
4489
4429
|
return "";
|
|
4490
4430
|
} })), getCaptureTimeoutMs(), "[timber] component re-render capture");
|