@torpor/view 1.3.3 → 1.4.1

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 (60) hide show
  1. package/dist/{Effect-Bp-BIDDm.d.cts → Effect-Bi_nt6cx.d.cts} +16 -3
  2. package/dist/Effect-Bi_nt6cx.d.cts.map +1 -0
  3. package/dist/{Effect-VsIY2vPx.d.mts → Effect-Bi_nt6cx.d.mts} +16 -3
  4. package/dist/Effect-Bi_nt6cx.d.mts.map +1 -0
  5. package/dist/ListItemSpec-DFkYr2TE.d.cts +28 -0
  6. package/dist/ListItemSpec-DFkYr2TE.d.cts.map +1 -0
  7. package/dist/ListItemSpec-DFkYr2TE.d.mts +28 -0
  8. package/dist/ListItemSpec-DFkYr2TE.d.mts.map +1 -0
  9. package/dist/{AsyncOptions-BDtArmeL.d.mts → WatchOptions--xq-Gn4e.d.cts} +77 -4
  10. package/dist/WatchOptions--xq-Gn4e.d.cts.map +1 -0
  11. package/dist/{AsyncOptions-C_7mWR6F.d.cts → WatchOptions-DWF4EqB6.d.mts} +77 -4
  12. package/dist/WatchOptions-DWF4EqB6.d.mts.map +1 -0
  13. package/dist/compile.cjs +1399 -406
  14. package/dist/compile.d.cts +26 -12
  15. package/dist/compile.d.cts.map +1 -1
  16. package/dist/compile.d.mts +26 -12
  17. package/dist/compile.d.mts.map +1 -1
  18. package/dist/compile.mjs +1399 -406
  19. package/dist/compile.mjs.map +1 -1
  20. package/dist/dev.cjs +101 -51
  21. package/dist/dev.d.cts +33 -2
  22. package/dist/dev.d.cts.map +1 -1
  23. package/dist/dev.d.mts +33 -2
  24. package/dist/dev.d.mts.map +1 -1
  25. package/dist/dev.mjs +51 -2
  26. package/dist/dev.mjs.map +1 -1
  27. package/dist/{fromWebSocket-ERhd9KZR.mjs → fromWebSocket-B22DIys7.mjs} +11 -2
  28. package/dist/fromWebSocket-B22DIys7.mjs.map +1 -0
  29. package/dist/{fromWebSocket-Cdoghvmh.cjs → fromWebSocket-C56rkQpZ.cjs} +15 -0
  30. package/dist/index.cjs +605 -266
  31. package/dist/index.d.cts +36 -129
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.mts +36 -129
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs +593 -255
  36. package/dist/index.mjs.map +1 -1
  37. package/dist/runtime.iife.js +1 -1
  38. package/dist/ssr.cjs +122 -22
  39. package/dist/ssr.d.cts +46 -12
  40. package/dist/ssr.d.cts.map +1 -1
  41. package/dist/ssr.d.mts +46 -12
  42. package/dist/ssr.d.mts.map +1 -1
  43. package/dist/ssr.mjs +121 -23
  44. package/dist/ssr.mjs.map +1 -1
  45. package/dist/titleWarning-BMjLAXpn.mjs +72 -0
  46. package/dist/titleWarning-BMjLAXpn.mjs.map +1 -0
  47. package/dist/titleWarning-DXp4fK7q.cjs +87 -0
  48. package/package.json +2 -1
  49. package/dist/AsyncOptions-BDtArmeL.d.mts.map +0 -1
  50. package/dist/AsyncOptions-C_7mWR6F.d.cts.map +0 -1
  51. package/dist/Cleanup-D0wvGW5d.d.cts +0 -9
  52. package/dist/Cleanup-D0wvGW5d.d.cts.map +0 -1
  53. package/dist/Cleanup-D0wvGW5d.d.mts +0 -9
  54. package/dist/Cleanup-D0wvGW5d.d.mts.map +0 -1
  55. package/dist/Effect-Bp-BIDDm.d.cts.map +0 -1
  56. package/dist/Effect-VsIY2vPx.d.mts.map +0 -1
  57. package/dist/devContext-BulTn3U5.cjs +0 -27
  58. package/dist/devContext-ZNsPyOgB.mjs +0 -24
  59. package/dist/devContext-ZNsPyOgB.mjs.map +0 -1
  60. package/dist/fromWebSocket-ERhd9KZR.mjs.map +0 -1
package/dist/ssr.d.mts CHANGED
@@ -1,6 +1,16 @@
1
- import { t as Cleanup } from "./Cleanup-D0wvGW5d.mjs";
2
- import { a as StreamSource, i as fromElement, n as fromWebSocket, o as StyleValue, r as fromServer, s as ClassValue, t as AsyncOptions } from "./AsyncOptions-BDtArmeL.mjs";
1
+ import { a as Cleanup, t as Effect } from "./Effect-Bi_nt6cx.mjs";
2
+ import { a as fromWebSocket, c as StreamSource, d as ClassValue, i as AsyncOptions, l as formatText, o as fromServer, r as RefreshOptions, s as fromElement, t as WatchOptions, u as StyleValue } from "./WatchOptions-DWF4EqB6.mjs";
3
3
  //#region src/render/formatAttributeText.d.ts
4
+ /**
5
+ * Formats a value for inclusion in a double-quoted HTML attribute in
6
+ * server-rendered markup. The escaping rules (and why `&` goes first) live in
7
+ * `ssr/escape.ts`.
8
+ *
9
+ * Exported as `t_attr` from `@torpor/view/ssr`, so generated server code can
10
+ * use it for interpolated attribute values; the other server helpers
11
+ * (`ssr/buildAttribute`, `ssr/buildClasses`, `ssr/buildStyles`) use
12
+ * `escapeAttribute` directly.
13
+ */
4
14
  declare function formatAttributeText(value: any): string;
5
15
  //#endregion
6
16
  //#region src/ssr/buildAttribute.d.ts
@@ -20,7 +30,8 @@ declare function buildServerAttribute(name: string, value: any): string;
20
30
  *
21
31
  * Unlike the client version (which assigns to `textContent` and so needs no
22
32
  * escaping), the server interpolates values into an HTML string, so the
23
- * characters that would otherwise be parsed as markup are escaped here.
33
+ * characters that would otherwise be parsed as markup are escaped here — the
34
+ * rules live in `ssr/escape.ts`.
24
35
  */
25
36
  declare function formatServerText(value: any): string;
26
37
  //#endregion
@@ -30,7 +41,8 @@ declare function formatServerText(value: any): string;
30
41
  * wraps it in a `class="..."` attribute, or returns `""` when there are no
31
42
  * classes, so the attribute is omitted rather than rendered empty. Exported
32
43
  * as `t_class` from `@torpor/view/ssr` — the only way server-compiled code
33
- * uses it is to interpolate the attribute into a tag.
44
+ * uses it is to interpolate the attribute into a tag. The value is
45
+ * HTML-escaped, so a class name can't break out of the attribute.
34
46
  */
35
47
  declare function buildServerClasses(value: ClassValue, styleHash?: string): string;
36
48
  //#endregion
@@ -40,7 +52,8 @@ declare function buildServerClasses(value: ClassValue, styleHash?: string): stri
40
52
  * wraps it in a `style="..."` attribute, or returns `""` when there are no
41
53
  * styles, so the attribute is omitted rather than rendered empty. Exported
42
54
  * as `t_style` from `@torpor/view/ssr` — the only way server-compiled code
43
- * uses it is to interpolate the attribute into a tag.
55
+ * uses it is to interpolate the attribute into a tag. The value is
56
+ * HTML-escaped, so a style value can't break out of the attribute.
44
57
  */
45
58
  declare function buildServerStyles(value: StyleValue): string;
46
59
  //#endregion
@@ -142,12 +155,20 @@ declare function $serverPending(_fn: () => any): boolean;
142
155
  /**
143
156
  * Server no-op for the client-side `$refresh` primitive. A refresh is an
144
157
  * imperative action that never runs during SSR. The stub exists so server
145
- * builds importing `$refresh` don't emit a dangling import.
158
+ * builds importing `$refresh` don't emit a dangling import, and its signature
159
+ * matches the client primitive exactly (see
160
+ * `test/types/server-twin-signatures.test.ts`).
146
161
  */
147
- declare function $serverRefresh(_fn: () => any): void;
162
+ declare function $serverRefresh(_fn: () => any, _options?: RefreshOptions): void;
148
163
  //#endregion
149
164
  //#region src/ssr/$serverRun.d.ts
150
- declare function $serverRun(_fn: () => Cleanup | void): void;
165
+ /**
166
+ * Server no-op for the client-side `$run` primitive. Effects never run during
167
+ * SSR, but the stub signature matches the client primitive exactly (so the two
168
+ * can't drift — see `test/types/server-twin-signatures.test.ts`). The returned
169
+ * `Effect` is never meaningful here, because nothing is created.
170
+ */
171
+ declare function $serverRun(_fn: () => Cleanup | void, _name?: string, _options?: Pick<Effect, "isMountEffect" | "forVarMask">): Effect;
151
172
  //#endregion
152
173
  //#region src/ssr/$serverStream.d.ts
153
174
  /**
@@ -174,7 +195,7 @@ declare function $serverUnwrap<T extends Record<PropertyKey, any>>(object: T): T
174
195
  * untouched — proxying them would break internal slots or private fields, and
175
196
  * they rarely carry async getters.
176
197
  */
177
- declare function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T;
198
+ declare function $serverWatch<T extends object>(object: T, _options?: WatchOptions): T;
178
199
  //#endregion
179
200
  //#region src/ssr/runServerAwait.d.ts
180
201
  /**
@@ -197,7 +218,8 @@ declare function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T;
197
218
  * or by the component flush (which replaces top-level sentinels directly).
198
219
  *
199
220
  * The lifecycle: render content once to start the `source: "server"` fetches
200
- * (discarding the output), wait for them with a per-getter timeout, then
221
+ * (discarding the output), wait for them until each getter's timeout (counted
222
+ * from the start of the server render, so nested boundaries share it), then
201
223
  * render again with the settled values. Reads are matched by getter identity,
202
224
  * so the render pass may read a getter more than once (e.g. branch on it).
203
225
  * The second pass ships wrapped in hydration markers plus a
@@ -209,6 +231,8 @@ declare function $serverWatch<T extends Record<PropertyKey, any>>(object: T): T;
209
231
  * @param id The boundary's site id (unique per `@await` in the component)
210
232
  * @param renderContent Renders the content branch (may read `$async` getters)
211
233
  * @param renderWith Renders the `with` branch, or null for empty
234
+ * @param context The rendering component's context, carrying the render's
235
+ * start time
212
236
  */
213
237
  declare function runServerAwait(id: string, renderContent: () => Promise<{
214
238
  body: string;
@@ -216,7 +240,7 @@ declare function runServerAwait(id: string, renderContent: () => Promise<{
216
240
  }>, renderWith: (() => Promise<{
217
241
  body: string;
218
242
  head: string;
219
- }>) | null): {
243
+ }>) | null, context?: Record<PropertyKey, any>): {
220
244
  body: string;
221
245
  head: string;
222
246
  } | Promise<{
@@ -224,6 +248,16 @@ declare function runServerAwait(id: string, renderContent: () => Promise<{
224
248
  head: string;
225
249
  }>;
226
250
  //#endregion
251
+ //#region src/ssr/renderContext.d.ts
252
+ /**
253
+ * Returns the context for a server component's render (compiled as
254
+ * `t_render_context`). The component at the root of a render stamps the
255
+ * start time into a copy of the context it was given, so the caller's object
256
+ * isn't changed and a later render with the same context starts afresh; its
257
+ * descendants receive the stamped context and keep it.
258
+ */
259
+ declare function renderContext(context: Record<PropertyKey, any> | undefined): Record<PropertyKey, any>;
260
+ //#endregion
227
261
  //#region src/ssr/serverSentinels.d.ts
228
262
  /** The body/head pair that server components and boundaries render into. */
229
263
  interface ServerHtml {
@@ -314,5 +348,5 @@ export declare const t_run_try: Unavailable;
314
348
  export declare const t_save_hydration: Unavailable;
315
349
  export declare const t_skip: Unavailable;
316
350
  //#endregion
317
- export { $serverAsync as $async, $serverBatch as $batch, $serverBind as $bind, $serverCache as $cache, $serverOnmount as $onmount, $serverPeek as $peek, $serverPending as $pending, $serverRefresh as $refresh, $serverRun as $run, $serverStream as $stream, $serverUnwrap as $unwrap, $serverWatch as $watch, type AsyncOptions, type ServerComponent, type ServerSlotRender, type StreamSource, fromElement, fromServer, fromWebSocket, formatAttributeText as t_attr, buildServerAttribute as t_attr_if, runServerAwait as t_await_server, buildServerClasses as t_class, formatServerText as t_fmt, serverFlush as t_server_flush, slotGuard as t_slot_guard, buildServerStyles as t_style };
351
+ export { $serverAsync as $async, $serverBatch as $batch, $serverBind as $bind, $serverCache as $cache, $serverOnmount as $onmount, $serverPeek as $peek, $serverPending as $pending, $serverRefresh as $refresh, $serverRun as $run, $serverStream as $stream, $serverUnwrap as $unwrap, $serverWatch as $watch, type AsyncOptions, type ServerComponent, type ServerSlotRender, type StreamSource, fromElement, fromServer, fromWebSocket, formatAttributeText as t_attr, buildServerAttribute as t_attr_if, runServerAwait as t_await_server, buildServerClasses as t_class, formatServerText as t_fmt, formatText as t_fmt_raw, renderContext as t_render_context, serverFlush as t_server_flush, slotGuard as t_slot_guard, buildServerStyles as t_style };
318
352
  //# sourceMappingURL=ssr.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ssr.d.mts","names":[],"sources":["../src/render/formatAttributeText.ts","../src/ssr/buildAttribute.ts","../src/ssr/formatText.ts","../src/ssr/buildClasses.ts","../src/ssr/buildStyles.ts","../src/ssr/slotGuard.ts","../src/compile/utils/slotAutoClose.ts","../src/ssr/$serverAsync.ts","../src/ssr/$serverBatch.ts","../src/ssr/$serverBind.ts","../src/ssr/$serverCache.ts","../src/ssr/$serverOnmount.ts","../src/ssr/$serverPeek.ts","../src/ssr/$serverPending.ts","../src/ssr/$serverRefresh.ts","../src/ssr/$serverRun.ts","../src/ssr/$serverStream.ts","../src/ssr/$serverUnwrap.ts","../src/ssr/$serverWatch.ts","../src/ssr/runServerAwait.ts","../src/ssr/serverSentinels.ts","../src/types/ServerSlotRender.ts","../src/types/ServerComponent.ts","../src/ssr/unavailable.ts"],"mappings":";;;iBAAwB,oBAAoB;;;;;;;;;;;iBCUpB,qBAAqB,cAAc;;;;;;;;;;iBCKnC,iBAAiB;;;;;;;;;;iBCLjB,mBAAmB,OAAO,YAAY;;;;;;;;;;iBCAtC,kBAAkB,OAAO;;;;;;;;;;;;;;;iBCIzB,UAAU,qBAAqB,iBAAiB;;;;qBC6D3D,gBAAgB;;wBAGb,gBAAgB;;;;;wBAShB,eAAe,kBAAkB;;;;;wBAUjC,iBAAiB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBClD3B,aAAa,GACpC,KAAK,cAAc,MAAM,QAAQ,IACjC,UAAU,eACR;;;iBClDqB,aAAa,GAAG,UAAU,IAAI;;;;;;;;;iBCM9B,YACvB,QAAQ,OAAO,mBACf,QAAQ,OAAO,kCACZ;;;iBCToB,aAAa,GAAG,UAAU,IAAI;;;iBCE9B,eAAe,WAAW;;;iBCF1B,YAAY,GAAG,UAAU,IAAI;;;;;;;;iBCK7B,eAAe;;;;;;;;iBCAf,eAAe;;;iBCHf,WAAW,WAAW;;;;;;;;iBCKtB,cAAc,GACrC,SAAS,aAAa,IACtB,WAAW,OAAO,YAClB;EAAa;;;;iBCVU,cAAc,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;;;;;;;;;iBC8B9D,aAAa,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCmB7D,eACvB,YACA,qBAAqB;EAAU;EAAc;IAC7C,mBAAmB;EAAU;EAAc;;EACvC;EAAc;IAAiB;EAAU;EAAc;;;;;UC9C3C;EAChB;EACA;;;;;;;;;;;;;;;;iBAiBqB,YAAY,cAAc,QAAQ,cAAc,QAAQ;;;;;;;KCtBzE,oBACJ,QAAQ,OAAO,mBACf,WAAW,OAAO,sBACd;;;;;;;;;;KCEA,mBACJ,SAAS,OAAO,mBAChB,WAAW,OAAO,mBAClB,SAAS,eAAe,sBACpB;EAAU;EAAc;;;;;;;;;;;;;;;KCFxB,kBAAkB;qBAQV,OAAO;qBACP,SAAS;qBACT,SAAS;qBACT,gBAAgB;qBAChB,iBAAiB;qBAEjB,eAAe;qBACf,gBAAgB;qBAChB,UAAU;qBACV,WAAW;qBACX,eAAe;qBACf,aAAa;qBACb,SAAS;qBACT,WAAW;qBACX,SAAS;qBACT,gBAAgB;qBAChB,YAAY;qBACZ,eAAe;qBACf,gBAAgB;qBAChB,aAAa;qBACb,QAAQ;qBACR,cAAc;qBACd,eAAe;qBACf,UAAU;qBACV,wBAAwB;qBACxB,qBAAqB;qBACrB,QAAQ;qBACR,WAAW;qBACX,aAAa;qBACb,cAAc;qBACd,eAAe;qBACf,YAAY;qBACZ,WAAW;qBACX,kBAAkB;qBAClB,QAAQ"}
1
+ {"version":3,"file":"ssr.d.mts","names":[],"sources":["../src/render/formatAttributeText.ts","../src/ssr/buildAttribute.ts","../src/ssr/formatText.ts","../src/ssr/buildClasses.ts","../src/ssr/buildStyles.ts","../src/ssr/slotGuard.ts","../src/compile/utils/slotAutoClose.ts","../src/ssr/$serverAsync.ts","../src/ssr/$serverBatch.ts","../src/ssr/$serverBind.ts","../src/ssr/$serverCache.ts","../src/ssr/$serverOnmount.ts","../src/ssr/$serverPeek.ts","../src/ssr/$serverPending.ts","../src/ssr/$serverRefresh.ts","../src/ssr/$serverRun.ts","../src/ssr/$serverStream.ts","../src/ssr/$serverUnwrap.ts","../src/ssr/$serverWatch.ts","../src/ssr/runServerAwait.ts","../src/ssr/renderContext.ts","../src/ssr/serverSentinels.ts","../src/types/ServerSlotRender.ts","../src/types/ServerComponent.ts","../src/ssr/unavailable.ts"],"mappings":";;;;;;;;;;;;;iBAYwB,oBAAoB;;;;;;;;;;;iBCFpB,qBAAqB,cAAc;;;;;;;;;;;iBCAnC,iBAAiB;;;;;;;;;;;iBCEjB,mBAAmB,OAAO,YAAY;;;;;;;;;;;iBCAtC,kBAAkB,OAAO;;;;;;;;;;;;;;;iBCEzB,UAAU,qBAAqB,iBAAiB;;;;qBC6D3D,gBAAgB;;wBAGb,gBAAgB;;;;;wBAShB,eAAe,kBAAkB;;;;;wBAUjC,iBAAiB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBClD3B,aAAa,GACpC,KAAK,cAAc,MAAM,QAAQ,IACjC,UAAU,eACR;;;iBClDqB,aAAa,GAAG,UAAU,IAAI;;;;;;;;;iBCM9B,YACvB,QAAQ,OAAO,mBACf,QAAQ,OAAO,kCACZ;;;iBCToB,aAAa,GAAG,UAAU,IAAI;;;iBCE9B,eAAe,WAAW;;;iBCF1B,YAAY,GAAG,UAAU,IAAI;;;;;;;;iBCK7B,eAAe;;;;;;;;;;iBCIf,eAAe,gBAAgB,WAAW;;;;;;;;;iBCA1C,WACvB,WAAW,gBACX,gBACA,WAAW,KAAK,0CACd;;;;;;;;iBCNqB,cAAc,GACrC,SAAS,aAAa,IACtB,WAAW,OAAO,YAClB;EAAa;;;;iBCVU,cAAc,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;;;;;;;;;iBCgC9D,aAAa,kBAAkB,QAAQ,GAAG,WAAW,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqBpE,eACvB,YACA,qBAAqB;EAAU;EAAc;IAC7C,mBAAmB;EAAU;EAAc;YAC3C,UAAU,OAAO;EACb;EAAc;IAAiB;EAAU;EAAc;;;;;;;;;;;iBC1C5C,cACf,SAAS,OAAO,gCACd,OAAO;;;;UCXO;EAChB;EACA;;;;;;;;;;;;;;;;iBAiBqB,YAAY,cAAc,QAAQ,cAAc,QAAQ;;;;;;;KCtBzE,oBACJ,QAAQ,OAAO,mBACf,WAAW,OAAO,sBACd;;;;;;;;;;KCEA,mBACJ,SAAS,OAAO,mBAChB,WAAW,OAAO,mBAClB,SAAS,eAAe,sBACpB;EAAU;EAAc;;;;;;;;;;;;;;;KCFxB,kBAAkB;qBAQV,OAAO;qBACP,SAAS;qBACT,SAAS;qBACT,gBAAgB;qBAChB,iBAAiB;qBAEjB,eAAe;qBACf,gBAAgB;qBAChB,UAAU;qBACV,WAAW;qBACX,eAAe;qBACf,aAAa;qBACb,SAAS;qBACT,WAAW;qBACX,SAAS;qBACT,gBAAgB;qBAChB,YAAY;qBACZ,eAAe;qBACf,gBAAgB;qBAChB,aAAa;qBACb,QAAQ;qBACR,cAAc;qBACd,eAAe;qBACf,UAAU;qBACV,wBAAwB;qBACxB,qBAAqB;qBACrB,QAAQ;qBACR,WAAW;qBACX,aAAa;qBACb,cAAc;qBACd,eAAe;qBACf,YAAY;qBACZ,WAAW;qBACX,kBAAkB;qBAClB,QAAQ"}
package/dist/ssr.mjs CHANGED
@@ -1,8 +1,48 @@
1
- import { a as buildStyles, i as formatText, n as fromServer, o as buildClasses, r as fromElement, t as fromWebSocket } from "./fromWebSocket-ERhd9KZR.mjs";
1
+ import { a as buildStyles, i as formatText, n as fromServer, o as buildClasses, r as fromElement, t as fromWebSocket } from "./fromWebSocket-B22DIys7.mjs";
2
2
  import { i as firstElementTag, n as autoCloseMessage, r as closesAncestor, t as AUTO_CLOSEABLE } from "./slotAutoClose-CgDkf8fM.mjs";
3
+ //#region src/ssr/escape.ts
4
+ /**
5
+ * The single place the server-side escaping rules live.
6
+ *
7
+ * Client helpers assign to `textContent`/`setAttribute`, so they need no
8
+ * escaping; everything that interpolates into a server-rendered HTML string
9
+ * goes through one of these two functions instead.
10
+ */
11
+ const TEXT_ESCAPES = {
12
+ "&": "&amp;",
13
+ "<": "&lt;",
14
+ ">": "&gt;"
15
+ };
16
+ /**
17
+ * Escapes a value for HTML text content: `&`, `<` and `>` could otherwise be
18
+ * parsed as markup. Values are formatted with the shared `formatText` first
19
+ * (null/undefined become `""`, proxies are unwrapped).
20
+ */
21
+ function escapeText(value) {
22
+ return formatText(value).replace(/[&<>]/g, (c) => TEXT_ESCAPES[c]);
23
+ }
24
+ /**
25
+ * Escapes a value for a double-quoted HTML attribute. `&` is escaped first,
26
+ * so literal entity text in a value (`a&quot;b`) survives the browser's
27
+ * decoding unchanged, then `"` so the value can't close the attribute.
28
+ */
29
+ function escapeAttribute(value) {
30
+ return (value ?? "").toString().replaceAll("&", "&amp;").replaceAll("\"", "&quot;");
31
+ }
32
+ //#endregion
3
33
  //#region src/render/formatAttributeText.ts
34
+ /**
35
+ * Formats a value for inclusion in a double-quoted HTML attribute in
36
+ * server-rendered markup. The escaping rules (and why `&` goes first) live in
37
+ * `ssr/escape.ts`.
38
+ *
39
+ * Exported as `t_attr` from `@torpor/view/ssr`, so generated server code can
40
+ * use it for interpolated attribute values; the other server helpers
41
+ * (`ssr/buildAttribute`, `ssr/buildClasses`, `ssr/buildStyles`) use
42
+ * `escapeAttribute` directly.
43
+ */
4
44
  function formatAttributeText(value) {
5
- return (value ?? "").toString().replaceAll("\"", "&quot;");
45
+ return escapeAttribute(value);
6
46
  }
7
47
  //#endregion
8
48
  //#region src/ssr/buildAttribute.ts
@@ -16,24 +56,20 @@ function formatAttributeText(value) {
16
56
  */
17
57
  function buildServerAttribute(name, value) {
18
58
  if (value == null || value === false) return "";
19
- return `${name}="${formatAttributeText(value)}"`;
59
+ return `${name}="${escapeAttribute(value)}"`;
20
60
  }
21
61
  //#endregion
22
62
  //#region src/ssr/formatText.ts
23
- const ESCAPABLE = {
24
- "&": "&amp;",
25
- "<": "&lt;",
26
- ">": "&gt;"
27
- };
28
63
  /**
29
64
  * Formats a text value for inclusion in server-rendered HTML.
30
65
  *
31
66
  * Unlike the client version (which assigns to `textContent` and so needs no
32
67
  * escaping), the server interpolates values into an HTML string, so the
33
- * characters that would otherwise be parsed as markup are escaped here.
68
+ * characters that would otherwise be parsed as markup are escaped here — the
69
+ * rules live in `ssr/escape.ts`.
34
70
  */
35
71
  function formatServerText(value) {
36
- return formatText(value).replace(/[&<>]/g, (c) => ESCAPABLE[c]);
72
+ return escapeText(value);
37
73
  }
38
74
  //#endregion
39
75
  //#region src/ssr/buildClasses.ts
@@ -42,11 +78,12 @@ function formatServerText(value) {
42
78
  * wraps it in a `class="..."` attribute, or returns `""` when there are no
43
79
  * classes, so the attribute is omitted rather than rendered empty. Exported
44
80
  * as `t_class` from `@torpor/view/ssr` — the only way server-compiled code
45
- * uses it is to interpolate the attribute into a tag.
81
+ * uses it is to interpolate the attribute into a tag. The value is
82
+ * HTML-escaped, so a class name can't break out of the attribute.
46
83
  */
47
84
  function buildServerClasses(value, styleHash) {
48
85
  const classes = buildClasses(value, styleHash);
49
- return classes === "" ? "" : `class="${classes}"`;
86
+ return classes === "" ? "" : `class="${escapeAttribute(classes)}"`;
50
87
  }
51
88
  //#endregion
52
89
  //#region src/ssr/buildStyles.ts
@@ -55,11 +92,12 @@ function buildServerClasses(value, styleHash) {
55
92
  * wraps it in a `style="..."` attribute, or returns `""` when there are no
56
93
  * styles, so the attribute is omitted rather than rendered empty. Exported
57
94
  * as `t_style` from `@torpor/view/ssr` — the only way server-compiled code
58
- * uses it is to interpolate the attribute into a tag.
95
+ * uses it is to interpolate the attribute into a tag. The value is
96
+ * HTML-escaped, so a style value can't break out of the attribute.
59
97
  */
60
98
  function buildServerStyles(value) {
61
99
  const styles = buildStyles(value);
62
- return styles === "" ? "" : `style="${styles}"`;
100
+ return styles === "" ? "" : `style="${escapeAttribute(styles)}"`;
63
101
  }
64
102
  //#endregion
65
103
  //#region src/ssr/slotGuard.ts
@@ -101,7 +139,7 @@ function currentServerReadSite() {
101
139
  * untouched — proxying them would break internal slots or private fields, and
102
140
  * they rarely carry async getters.
103
141
  */
104
- function $serverWatch(object) {
142
+ function $serverWatch(object, _options) {
105
143
  if (object === null || object === void 0) return object;
106
144
  const prototype = Object.getPrototypeOf(object);
107
145
  if (!Array.isArray(object) && prototype !== Object.prototype && prototype !== null) return object;
@@ -161,6 +199,7 @@ function newServerAwaitState() {
161
199
  clientReads: 0,
162
200
  children: /* @__PURE__ */ new Map(),
163
201
  counters: /* @__PURE__ */ new Map(),
202
+ startedAt: Date.now(),
164
203
  degraded: false,
165
204
  isRoot: false,
166
205
  sentinels: /* @__PURE__ */ new Map()
@@ -295,12 +334,20 @@ function $serverPending(_fn) {
295
334
  /**
296
335
  * Server no-op for the client-side `$refresh` primitive. A refresh is an
297
336
  * imperative action that never runs during SSR. The stub exists so server
298
- * builds importing `$refresh` don't emit a dangling import.
337
+ * builds importing `$refresh` don't emit a dangling import, and its signature
338
+ * matches the client primitive exactly (see
339
+ * `test/types/server-twin-signatures.test.ts`).
299
340
  */
300
- function $serverRefresh(_fn) {}
341
+ function $serverRefresh(_fn, _options) {}
301
342
  //#endregion
302
343
  //#region src/ssr/$serverRun.ts
303
- function $serverRun(_fn) {}
344
+ /**
345
+ * Server no-op for the client-side `$run` primitive. Effects never run during
346
+ * SSR, but the stub signature matches the client primitive exactly (so the two
347
+ * can't drift — see `test/types/server-twin-signatures.test.ts`). The returned
348
+ * `Effect` is never meaningful here, because nothing is created.
349
+ */
350
+ function $serverRun(_fn, _name, _options) {}
304
351
  //#endregion
305
352
  //#region src/ssr/$serverStream.ts
306
353
  /**
@@ -314,6 +361,37 @@ function $serverStream(_source, _handler, _options) {}
314
361
  function $serverUnwrap(object) {
315
362
  return object;
316
363
  }
364
+ //#endregion
365
+ //#region src/ssr/renderContext.ts
366
+ /**
367
+ * The `$context` key holding the time (from `Date.now()`) a server render
368
+ * started. `source: "server"` `$async` timeouts count from it, so nested
369
+ * boundaries -- which only start once the boundary around them has resolved
370
+ * -- share one time limit rather than each adding its own wait to the
371
+ * response.
372
+ */
373
+ const RENDER_STARTED = Symbol.for("torp.RenderStarted");
374
+ /**
375
+ * Returns the context for a server component's render (compiled as
376
+ * `t_render_context`). The component at the root of a render stamps the
377
+ * start time into a copy of the context it was given, so the caller's object
378
+ * isn't changed and a later render with the same context starts afresh; its
379
+ * descendants receive the stamped context and keep it.
380
+ */
381
+ function renderContext(context) {
382
+ if (context?.[RENDER_STARTED] !== void 0) return context;
383
+ return {
384
+ ...context,
385
+ [RENDER_STARTED]: Date.now()
386
+ };
387
+ }
388
+ /**
389
+ * The time the server render started, or now when the context wasn't
390
+ * stamped (e.g. code compiled before the stamp existed).
391
+ */
392
+ function renderStarted(context) {
393
+ return context?.[RENDER_STARTED] ?? Date.now();
394
+ }
317
395
  /**
318
396
  * Renders a component's (or a degraded boundary's `with` branch's) markup
319
397
  * with a fresh flush root as the enclosing await state, then substitutes any
@@ -399,7 +477,8 @@ function nextSentinel() {
399
477
  * or by the component flush (which replaces top-level sentinels directly).
400
478
  *
401
479
  * The lifecycle: render content once to start the `source: "server"` fetches
402
- * (discarding the output), wait for them with a per-getter timeout, then
480
+ * (discarding the output), wait for them until each getter's timeout (counted
481
+ * from the start of the server render, so nested boundaries share it), then
403
482
  * render again with the settled values. Reads are matched by getter identity,
404
483
  * so the render pass may read a getter more than once (e.g. branch on it).
405
484
  * The second pass ships wrapped in hydration markers plus a
@@ -411,15 +490,19 @@ function nextSentinel() {
411
490
  * @param id The boundary's site id (unique per `@await` in the component)
412
491
  * @param renderContent Renders the content branch (may read `$async` getters)
413
492
  * @param renderWith Renders the `with` branch, or null for empty
493
+ * @param context The rendering component's context, carrying the render's
494
+ * start time
414
495
  */
415
- function runServerAwait(id, renderContent, renderWith) {
496
+ function runServerAwait(id, renderContent, renderWith, context) {
416
497
  const parent = currentServerAwait();
417
498
  if (parent !== null && parent.phase === "render") {
418
499
  const cached = parent.children.get(childKey(parent, id));
419
500
  if (cached === void 0) throw new ServerAwaitMisaligned();
420
501
  return cached;
421
502
  }
422
- const final = renderBoundary(newServerAwaitState(), renderContent, renderWith);
503
+ const state = newServerAwaitState();
504
+ state.startedAt = renderStarted(context);
505
+ const final = renderBoundary(state, renderContent, renderWith);
423
506
  const sentinel = nextSentinel();
424
507
  if (parent !== null) {
425
508
  if (parent.isRoot) parent.sentinels.set(sentinel, final);
@@ -438,8 +521,9 @@ function runServerAwait(id, renderContent, renderWith) {
438
521
  async function renderBoundary(state, renderContent, renderWith) {
439
522
  await withServerAwait(state, renderContent).catch(() => {});
440
523
  if (state.promises.length === 0) return renderWithBranch(renderWith);
441
- const timeout = Math.max(...state.promises.map((entry) => entry.timeout));
524
+ const timeout = Math.max(0, Math.max(...state.promises.map((entry) => entry.timeout)) - (Date.now() - state.startedAt));
442
525
  let degraded = await Promise.race([Promise.all(state.promises.map((entry) => entry.promise.then(() => true, () => true))).then(() => true, () => true), new Promise((resolve) => setTimeout(resolve, timeout, false))]) === false;
526
+ if (degraded) warnTimedOut(state);
443
527
  let content;
444
528
  if (!degraded) {
445
529
  state.phase = "render";
@@ -483,6 +567,20 @@ async function renderBoundary(state, renderContent, renderWith) {
483
567
  head: content.head
484
568
  };
485
569
  }
570
+ const warned = /* @__PURE__ */ new Set();
571
+ /**
572
+ * Warns (once per read) that a boundary gave up waiting for its server reads,
573
+ * so the slow read shows up somewhere other than the response time.
574
+ */
575
+ function warnTimedOut(state) {
576
+ for (const entry of state.promises) {
577
+ if (entry.result !== void 0) continue;
578
+ const name = typeof entry.key === "string" && entry.key.length < 50 ? entry.key : "(getter)";
579
+ if (warned.has(name)) continue;
580
+ warned.add(name);
581
+ console.warn(`[torpor] The source: "server" $async read "${name}" didn't settle within its ${entry.timeout}ms timeout (counted from the start of the render), so its @await boundary rendered its \`with\` branch and the client will fetch it. Raise the read's \`timeout\`, or load slow data without blocking the render (in @torpor/build, return a promise from the route's load).`);
582
+ }
583
+ }
486
584
  /**
487
585
  * The `<!--t-await:...-->` comment carrying the boundary's resolved values,
488
586
  * in the order the render pass first read them, for the client's `$async`
@@ -534,6 +632,6 @@ const t_run_try = unavailable("t_run_try");
534
632
  const t_save_hydration = unavailable("t_save_hydration");
535
633
  const t_skip = unavailable("t_skip");
536
634
  //#endregion
537
- export { $serverAsync as $async, $serverBatch as $batch, $serverBind as $bind, $serverCache as $cache, $serverOnmount as $onmount, $serverPeek as $peek, $serverPending as $pending, $serverRefresh as $refresh, $serverRun as $run, $serverStream as $stream, $serverUnwrap as $unwrap, $serverWatch as $watch, AUTO_CLOSEABLE, autoCloseMessage, clearLayoutSlot, closesAncestor, fillLayoutSlot, firstElementTag, fromElement, fromServer, fromWebSocket, hydrate, mount, t_add_element, t_add_fragment, t_anchor, t_animate, t_apply_props, formatAttributeText as t_attr, buildServerAttribute as t_attr_if, t_attribute, runServerAwait as t_await_server, t_child, buildServerClasses as t_class, t_dynamic, t_event, t_first_inside, formatServerText as t_fmt, t_fragment, t_fragment_el, t_head_element, t_list_item, t_next, t_pop_region, t_push_region, t_region, t_rerun_region_effects, t_restore_hydration, t_root, t_root_el, t_run_await, t_run_branch, t_run_control, t_run_list, t_run_try, t_save_hydration, serverFlush as t_server_flush, t_skip, slotGuard as t_slot_guard, buildServerStyles as t_style, unmount };
635
+ export { $serverAsync as $async, $serverBatch as $batch, $serverBind as $bind, $serverCache as $cache, $serverOnmount as $onmount, $serverPeek as $peek, $serverPending as $pending, $serverRefresh as $refresh, $serverRun as $run, $serverStream as $stream, $serverUnwrap as $unwrap, $serverWatch as $watch, AUTO_CLOSEABLE, autoCloseMessage, clearLayoutSlot, closesAncestor, fillLayoutSlot, firstElementTag, fromElement, fromServer, fromWebSocket, hydrate, mount, t_add_element, t_add_fragment, t_anchor, t_animate, t_apply_props, formatAttributeText as t_attr, buildServerAttribute as t_attr_if, t_attribute, runServerAwait as t_await_server, t_child, buildServerClasses as t_class, t_dynamic, t_event, t_first_inside, formatServerText as t_fmt, formatText as t_fmt_raw, t_fragment, t_fragment_el, t_head_element, t_list_item, t_next, t_pop_region, t_push_region, t_region, renderContext as t_render_context, t_rerun_region_effects, t_restore_hydration, t_root, t_root_el, t_run_await, t_run_branch, t_run_control, t_run_list, t_run_try, t_save_hydration, serverFlush as t_server_flush, t_skip, slotGuard as t_slot_guard, buildServerStyles as t_style, unmount };
538
636
 
539
637
  //# sourceMappingURL=ssr.mjs.map