@solidjs/web 2.0.0-rc.20 → 2.0.0-rc.22

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 (36) hide show
  1. package/dist/server.dev.js +521 -280
  2. package/dist/server.js +518 -279
  3. package/dist/server.observe.js +518 -279
  4. package/dist/web.dev.js +142 -106
  5. package/dist/web.js +120 -105
  6. package/dist/web.observe.js +120 -105
  7. package/frames/dist/client.dev.js +7 -2
  8. package/frames/dist/client.js +7 -2
  9. package/frames/dist/client.observe.js +7 -2
  10. package/frames/dist/server.dev.js +124 -68
  11. package/frames/dist/server.js +124 -68
  12. package/frames/dist/server.observe.js +124 -68
  13. package/frames/dist/wire.js +1 -1
  14. package/package.json +2 -2
  15. package/serialization/dist/serialization.js +53 -12
  16. package/serialization/types/index.d.ts +42 -0
  17. package/serialization/types/serializer.d.ts +42 -0
  18. package/server-functions/dist/client.dev.js +5 -3
  19. package/server-functions/dist/client.js +5 -3
  20. package/server-functions/dist/client.observe.js +5 -3
  21. package/server-functions/dist/rich-args.js +27 -9
  22. package/server-functions/dist/server.dev.js +122 -36
  23. package/server-functions/dist/server.js +122 -36
  24. package/server-functions/dist/server.observe.js +122 -36
  25. package/types/client.d.ts +54 -3
  26. package/types/constants.d.ts +2 -1
  27. package/types/frames/frame-client.d.ts +2 -0
  28. package/types/frames/serializer.d.ts +42 -0
  29. package/types/frames/tree-rewrite.d.ts +7 -0
  30. package/types/serializer.d.ts +42 -0
  31. package/types/server-functions/client.d.ts +0 -1
  32. package/types/server-functions/server.d.ts +0 -1
  33. package/types/server-functions/shared.d.ts +3 -2
  34. package/types/server-functions/uploads.d.ts +3 -0
  35. package/types/server-mock.d.ts +35 -8
  36. package/types/server.d.ts +89 -18
@@ -20,7 +20,15 @@ function rewriteTree(value, visit, withPath) {
20
20
  } catch (err) {
21
21
  if (err !== CYCLE) throw err;
22
22
  }
23
- return clone(value, visit, path, state.memo || (state.memo = new Map()));
23
+ const memo = state.memo || (state.memo = new Map());
24
+ const marks = {
25
+ at: new Map(),
26
+ stack: [],
27
+ changed: new Set(),
28
+ next: 0
29
+ };
30
+ mark(value, visit, path, memo, marks);
31
+ return clone(value, memo, marks.changed);
24
32
  }
25
33
  function shape(value) {
26
34
  return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
@@ -68,28 +76,73 @@ function cow(value, visit, path, depth, state) {
68
76
  if (ancestors !== undefined) ancestors.delete(value);
69
77
  return out;
70
78
  }
71
- function clone(value, visit, path, memo) {
72
- if (memo.has(value)) return memo.get(value);
79
+ function mark(value, visit, path, memo, m) {
80
+ const seen = m.at.get(value);
81
+ if (seen !== undefined) return seen;
82
+ if (memo.has(value)) return -1;
73
83
  const r = visit(value, path);
74
84
  if (r !== DESCEND) {
75
85
  memo.set(value, r);
76
- return r;
86
+ return -1;
77
87
  }
78
88
  const s = shape(value);
79
- if (s === 0) return value;
80
- const out = s === 1 ? value.slice() : {
89
+ if (s === 0) return -1;
90
+ const index = m.next++;
91
+ let low = index;
92
+ let changed = false;
93
+ let open = false;
94
+ const keys = s === 1 ? value : Object.keys(value);
95
+ for (let i = 0; i < keys.length; i++) {
96
+ const k = s === 1 ? i : keys[i];
97
+ const c = value[k];
98
+ if (c === null || typeof c !== "object") continue;
99
+ if (!open) {
100
+ open = true;
101
+ m.at.set(value, index);
102
+ m.stack.push(value);
103
+ }
104
+ const l = mark(c, visit, path === undefined ? undefined : s === 1 ? `${path}[${k}]` : `${path}.${k}`, memo, m);
105
+ if (l >= 0 && l < low) low = l;
106
+ if (memo.has(c) && memo.get(c) !== c || l === Infinity && m.changed.has(c)) changed = true;
107
+ }
108
+ if (!open) return -1;
109
+ if (low === index) {
110
+ m.at.set(value, Infinity);
111
+ if (m.stack[m.stack.length - 1] === value) {
112
+ m.stack.pop();
113
+ if (changed) m.changed.add(value);
114
+ return Infinity;
115
+ }
116
+ const members = m.stack.splice(m.stack.lastIndexOf(value));
117
+ if (!changed) for (const n of members) if (m.changed.has(n)) {
118
+ changed = true;
119
+ break;
120
+ }
121
+ for (const n of members) {
122
+ m.at.set(n, Infinity);
123
+ if (changed) m.changed.add(n);
124
+ }
125
+ return Infinity;
126
+ }
127
+ if (changed) m.changed.add(value);
128
+ return low;
129
+ }
130
+ function clone(value, memo, changed) {
131
+ if (memo.has(value)) return memo.get(value);
132
+ if (!changed.has(value)) return value;
133
+ const out = Array.isArray(value) ? value.slice() : {
81
134
  ...value
82
135
  };
83
136
  memo.set(value, out);
84
- if (s === 1) {
137
+ if (Array.isArray(value)) {
85
138
  for (let i = 0; i < value.length; i++) {
86
139
  const c = value[i];
87
- if (c !== null && typeof c === "object") out[i] = clone(c, visit, path === undefined ? undefined : `${path}[${i}]`, memo);
140
+ if (c !== null && typeof c === "object") out[i] = clone(c, memo, changed);
88
141
  }
89
142
  } else {
90
143
  for (const k of Object.keys(value)) {
91
144
  const c = value[k];
92
- if (c !== null && typeof c === "object") out[k] = clone(c, visit, path === undefined ? undefined : `${path}.${k}`, memo);
145
+ if (c !== null && typeof c === "object") out[k] = clone(c, memo, changed);
93
146
  }
94
147
  }
95
148
  return out;
@@ -242,7 +295,6 @@ function createKeyedSerializer(serialize, onError, onDone) {
242
295
  pendingWrites++;
243
296
  let settled = false;
244
297
  let failed = false;
245
- let started = false;
246
298
  let cancel = null;
247
299
  const settle = () => {
248
300
  if (settled) return;
@@ -256,17 +308,14 @@ function createKeyedSerializer(serialize, onError, onDone) {
256
308
  stream = serialize(key, value, {
257
309
  onError: onError && (err => {
258
310
  failed = true;
259
- onError(err);
311
+ onError(err, key);
260
312
  if (cancel) {
261
313
  cancel();
262
314
  settle();
263
315
  }
264
316
  }),
265
317
  onDone: settle
266
- }, initial => {
267
- if (initial) started = true;
268
- return !closed;
269
- });
318
+ }, () => !closed);
270
319
  } catch (err) {
271
320
  settle();
272
321
  throw err;
@@ -316,7 +365,7 @@ function createJSONSerializer({
316
365
  plugins: resolved.plugins,
317
366
  disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
318
367
  onParse(node, initial) {
319
- if (live(initial)) onData({
368
+ if (live()) onData({
320
369
  key,
321
370
  node,
322
371
  initial
@@ -1021,10 +1070,9 @@ function frameStream(makeCode, options) {
1021
1070
  };
1022
1071
  }
1023
1072
  function slotRange(occurrence) {
1024
- return {
1025
- t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
1073
+ return Object.assign(markup(`<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`), {
1026
1074
  $slot: true
1027
- };
1075
+ });
1028
1076
  }
1029
1077
  function argBorderForm(value, needs) {
1030
1078
  return toBorderForm(noteTraces(value, needs));
@@ -1161,6 +1209,16 @@ function suppressedFill(render) {
1161
1209
  live.suppressed--;
1162
1210
  }
1163
1211
  }
1212
+ const SSR_NODE = Symbol.for("solid.ssrNode");
1213
+ const markup = (t, h, p) => h ? {
1214
+ t,
1215
+ h,
1216
+ p,
1217
+ $: SSR_NODE
1218
+ } : {
1219
+ t,
1220
+ $: SSR_NODE
1221
+ };
1164
1222
  let parked = null;
1165
1223
  let parkedIds = 0;
1166
1224
  const PARKED = /<!--sc-n:(\d+)-->/;
@@ -1171,9 +1229,7 @@ function park(render) {
1171
1229
  render,
1172
1230
  out: undefined
1173
1231
  });
1174
- return {
1175
- t: `<!--sc-n:${id}-->`
1176
- };
1232
+ return markup(`<!--sc-n:${id}-->`);
1177
1233
  }
1178
1234
  const runParked = (entry, owner) => entry.out || (entry.out = entry.render(owner));
1179
1235
  function placeParked(node, nested, owner) {
@@ -1191,22 +1247,14 @@ function expandParked(node, nested, owner) {
1191
1247
  if (!node.h) return splitParked(node.t, nested, owner) || node;
1192
1248
  const out = [];
1193
1249
  node.t.forEach((t, i) => {
1194
- out.push(splitParked(t, nested, owner) || {
1195
- t
1196
- });
1197
- if (i < node.h.length) out.push({
1198
- t: ["", ""],
1199
- h: [node.h[i]],
1200
- p: [node.p[i]]
1201
- });
1250
+ out.push(splitParked(t, nested, owner) || markup(t));
1251
+ if (i < node.h.length) out.push(markup(["", ""], [node.h[i]], [node.p[i]]));
1202
1252
  });
1203
1253
  return out;
1204
1254
  }
1205
1255
  function splitParked(t, nested, owner) {
1206
1256
  const parts = typeof t === "string" ? t.split(PARKED) : [t];
1207
- return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : {
1208
- t: part
1209
- }) : undefined;
1257
+ return parts.length > 1 ? parts.map((part, i) => i & 1 ? runParked(nested.get(+part), owner) : markup(part)) : undefined;
1210
1258
  }
1211
1259
  function createDocumentSlotProps(clientProps, frameId) {
1212
1260
  const counts = Object.create(null);
@@ -1239,11 +1287,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1239
1287
  const getters = new Map();
1240
1288
  const repeats = new Map();
1241
1289
  const range = (occurrence, content, tail) => {
1242
- const r = [{
1243
- t: `<!--slot:${occurrence}:start-->`
1244
- }, content, tail, {
1245
- t: `<!--slot:${occurrence}:end-->`
1246
- }];
1290
+ const r = [markup(`<!--slot:${occurrence}:start-->`), content, tail, markup(`<!--slot:${occurrence}:end-->`)];
1247
1291
  r.$slot = true;
1248
1292
  return r;
1249
1293
  };
@@ -1364,11 +1408,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1364
1408
  resolved[key] = () => {
1365
1409
  if (region.locked) return [];
1366
1410
  region.used = true;
1367
- return [{
1368
- t: frameElementOpen(childId)
1369
- }, region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, {
1370
- t: FRAME_ELEMENT_CLOSE
1371
- }];
1411
+ return [markup(frameElementOpen(childId)), region.nested && region.nested.size ? placeParked(value, region.nested, getOwner()) : value, markup(FRAME_ELEMENT_CLOSE)];
1372
1412
  };
1373
1413
  } else if (ssrAsyncValue && isAsyncValue(value)) {
1374
1414
  let readable = value;
@@ -1663,9 +1703,7 @@ function frameTransformDirectResult(value, {
1663
1703
  const address = frameAddress(id, args);
1664
1704
  const wrapped = props => {
1665
1705
  const siteId = documentSiteId(id);
1666
- return [{
1667
- t: frameElementOpen(siteId, address.slice(id.length + 1))
1668
- },
1706
+ return [markup(frameElementOpen(siteId, address.slice(id.length + 1))),
1669
1707
  serverOwned(() => {
1670
1708
  const page = sharedConfig.context;
1671
1709
  armDocumentLiveHoles(page);
@@ -1681,9 +1719,7 @@ function frameTransformDirectResult(value, {
1681
1719
  } finally {
1682
1720
  sharedConfig.context = page;
1683
1721
  }
1684
- }), {
1685
- t: FRAME_ELEMENT_CLOSE
1686
- }];
1722
+ }), markup(FRAME_ELEMENT_CLOSE)];
1687
1723
  };
1688
1724
  wrapped[SERVER_COMPONENT] = id;
1689
1725
  wrapped[SERVER_COMPONENT_SOURCE] = component;
@@ -1826,10 +1862,9 @@ function createSlotProps(sink, frame) {
1826
1862
  if (repeat) return repeat;
1827
1863
  if (sweeping && !live.scope) {
1828
1864
  live.gateHit = true;
1829
- return {
1830
- t: "",
1865
+ return Object.assign(markup(""), {
1831
1866
  $slot: true
1832
- };
1867
+ });
1833
1868
  }
1834
1869
  const raw = callArgs[0];
1835
1870
  let occurrence = keyedId(prop, raw);
@@ -2230,25 +2265,23 @@ function snapshot(shared, have) {
2230
2265
  });
2231
2266
  open.r[k] = record;
2232
2267
  };
2233
- if (!conditional) {
2234
- for (const {
2268
+ const containers = [];
2269
+ const spliced = new Set();
2270
+ for (const entry of shared.records.values()) {
2271
+ const {
2235
2272
  id,
2236
- version,
2237
2273
  k,
2238
2274
  record
2239
- } of shared.records.values()) put(id, version, k, record);
2240
- return out;
2241
- }
2242
- const containers = [];
2243
- for (const e of shared.records.values()) if (e.id === shared.id && (e.k === "" || /^seg:[^:]+$/.test(e.k)) && e.record) containers.push({
2244
- e,
2245
- value: e.record.value
2246
- });
2247
- for (const {
2248
- k,
2249
- record
2250
- } of shared.records.values()) {
2251
- if (!k.startsWith("hole:lh:") || k.endsWith(":error") || !record || record.value == null) continue;
2275
+ } = entry;
2276
+ if (id !== shared.id || !record) continue;
2277
+ if (k === "" || /^seg:[^:]+$/.test(k)) {
2278
+ if (typeof record.value === "string") containers.push({
2279
+ e: entry,
2280
+ value: record.value
2281
+ });
2282
+ continue;
2283
+ }
2284
+ if (!k.startsWith("hole:lh:") || k.endsWith(":error") || record.value == null) continue;
2252
2285
  const n = k.slice(8);
2253
2286
  const startMark = `<!--lh:${n}-->`;
2254
2287
  const endMark = `<!--lh:/${n}-->`;
@@ -2258,9 +2291,32 @@ function snapshot(shared, have) {
2258
2291
  const end = c.value.indexOf(endMark, start);
2259
2292
  if (end < 0) continue;
2260
2293
  c.value = c.value.slice(0, start + startMark.length) + record.value + c.value.slice(end);
2294
+ spliced.add(entry);
2261
2295
  break;
2262
2296
  }
2263
2297
  }
2298
+ if (!conditional) {
2299
+ for (const e of shared.records.values()) {
2300
+ const {
2301
+ id,
2302
+ version,
2303
+ k,
2304
+ record
2305
+ } = e;
2306
+ if (spliced.has(e)) continue;
2307
+ const c = containers.find(c => c.e === e);
2308
+ if (c && c.value !== record.value) {
2309
+ const holes = {};
2310
+ if (record.holes) for (const key in record.holes) if (key.startsWith("lha:")) holes[key] = record.holes[key];
2311
+ put(id, version, k, withHoles({
2312
+ ...record,
2313
+ value: c.value,
2314
+ digest: k ? textDigest(c.value) : record.digest
2315
+ }, holeDigests(c.value, null, holes)));
2316
+ } else put(id, version, k, record);
2317
+ }
2318
+ return out;
2319
+ }
2264
2320
  for (const e of shared.records.values()) {
2265
2321
  const {
2266
2322
  id,
@@ -364,7 +364,7 @@ function connect(response, wire, address, binding, host, bump, begin) {
364
364
  const dead = error || cancelled || new Error("Frame stream ended before the frame completed.");
365
365
  connection.done = true;
366
366
  resolveEnd({
367
- open: open.size,
367
+ open: cancelled !== undefined ? Math.max(open.size, 1) : open.size,
368
368
  error: dead,
369
369
  sweep: () => {
370
370
  for (const [id, version] of open) host.apply({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/web",
3
3
  "description": "Solid's web runtime: client rendering, hydration, SSR, and DOM-specific control flow (Portal, Dynamic).",
4
- "version": "2.0.0-rc.20",
4
+ "version": "2.0.0-rc.22",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -379,7 +379,7 @@
379
379
  "seroval-plugins": "1.7.0"
380
380
  },
381
381
  "peerDependencies": {
382
- "solid-js": "^2.0.0-rc.20"
382
+ "solid-js": "^2.0.0-rc.22"
383
383
  },
384
384
  "devDependencies": {
385
385
  "@codspeed/vitest-plugin": "^5.4.0",
@@ -256,7 +256,6 @@ function createKeyedSerializer(serialize, onError, onDone) {
256
256
  pendingWrites++;
257
257
  let settled = false;
258
258
  let failed = false;
259
- let started = false;
260
259
  let cancel = null;
261
260
  const settle = () => {
262
261
  if (settled) return;
@@ -270,17 +269,14 @@ function createKeyedSerializer(serialize, onError, onDone) {
270
269
  stream = serialize(key, value, {
271
270
  onError: onError && (err => {
272
271
  failed = true;
273
- onError(err);
272
+ onError(err, key);
274
273
  if (cancel) {
275
274
  cancel();
276
275
  settle();
277
276
  }
278
277
  }),
279
278
  onDone: settle
280
- }, initial => {
281
- if (initial) started = true;
282
- return !closed;
283
- });
279
+ }, () => !closed);
284
280
  } catch (err) {
285
281
  settle();
286
282
  throw err;
@@ -327,22 +323,67 @@ function createHydrationSerializer({
327
323
  onDone,
328
324
  scopeId,
329
325
  onError,
330
- plugins
326
+ plugins,
327
+ late
331
328
  }) {
332
329
  const resolvedPlugins = resolveSerializerPlugins(plugins);
333
330
  const disabledFeatures = defaultDisabledFeatures() | serializeOnlyDisabledFeatures();
334
331
  const refs = new Map();
335
- return createKeyedSerializer((key, value, callbacks, live) => crossSerializeStream(value, {
332
+ const serialize = (key, value, callbacks, live) => crossSerializeStream(value, {
336
333
  scopeId,
337
334
  refs,
338
335
  plugins: resolvedPlugins,
339
336
  disabledFeatures,
340
337
  onSerialize(data, initial) {
341
- if (!live(initial)) return;
338
+ if (!live()) return;
342
339
  onData(initial ? HYDRATION_GLOBAL + '["' + serializeKey(key) + '"]=' + data : data);
343
340
  },
344
341
  ...callbacks
345
- }), onError, onDone);
342
+ });
343
+ return createKeyedSerializer(late ? late(serialize, refs, onData, scopeId) : serialize, onError, onDone);
344
+ }
345
+ function rejectUnserializedKey(serialize, refs, onData, scopeId, plain) {
346
+ let taken = 0;
347
+ let fresh = [];
348
+ const set = refs.set;
349
+ refs.set = (value, id) => {
350
+ taken++;
351
+ fresh.push(value);
352
+ return set.call(refs, value, id);
353
+ };
354
+ Object.defineProperty(refs, "size", {
355
+ get: () => taken
356
+ });
357
+ return (key, value, callbacks, live) => {
358
+ const sent = [];
359
+ const failed = () => {
360
+ for (const ref of fresh) refs.delete(ref);
361
+ fresh = [];
362
+ const ids = new Set();
363
+ for (const ref of sent) {
364
+ const id = refs.get(ref);
365
+ if (ref instanceof Promise) ids.add(id + 1);else if (isStream(ref) || Object.getPrototypeOf(ref) === Object.prototype && !Object.keys(ref).length) ids.add(id);
366
+ }
367
+ if (!ids.size) return;
368
+ const text = plain && plain(key);
369
+ const body = "for(const i of[" + [...ids] + "]){const v=$R[i];v&&(v.f?" + (text === undefined ? "v.f(e)" : "(v.f(e),v.p.s||(v.p.s=2,v.p.v=e))") + ":v.throw&&v.throw(e))}";
370
+ const message = JSON.stringify(text === undefined ? "Serialization failed: the hydration value for key " + JSON.stringify(key) + " could not be serialized on the server" : text).replace(/[<\u2028\u2029]/g, c => KEY_ESCAPES[c]);
371
+ onData("($R=>{const e=new Error(" + message + ");" + body + "})(" + (scopeId == null ? "$R" : '$R["' + serializeKey(scopeId) + '"]') + ")");
372
+ };
373
+ return serialize(key, value, {
374
+ ...callbacks,
375
+ onError: callbacks.onError && (err => {
376
+ if (live()) failed();
377
+ callbacks.onError(err);
378
+ })
379
+ },
380
+ () => {
381
+ if (!live()) return false;
382
+ sent.push(...fresh);
383
+ fresh = [];
384
+ return true;
385
+ });
386
+ };
346
387
  }
347
388
  function getLocalHeaderScript(id) {
348
389
  return getCrossReferenceHeader(id) + ";";
@@ -385,7 +426,7 @@ function createJSONSerializer({
385
426
  plugins: resolved.plugins,
386
427
  disabledFeatures: resolved.disabledFeatures | serializeOnlyDisabledFeatures(resolved.serializeErrorStacks),
387
428
  onParse(node, initial) {
388
- if (live(initial)) onData({
429
+ if (live()) onData({
389
430
  key,
390
431
  node,
391
432
  initial
@@ -395,4 +436,4 @@ function createJSONSerializer({
395
436
  }), onError, onDone);
396
437
  }
397
438
 
398
- export { DEFAULT_WEB_PLUGINS, OpaqueReference, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createPlugin, createSerializer, getLocalHeaderScript, resolveSerializerPlugins, serializeJSON };
439
+ export { DEFAULT_WEB_PLUGINS, OpaqueReference, createHydrationSerializer, createJSONDataTable, createJSONDeserializer, createJSONSerializer, createPlugin, createSerializer, getLocalHeaderScript, rejectUnserializedKey, resolveSerializerPlugins, serializeJSON };
@@ -100,6 +100,48 @@ export declare function createHydrationSerializer(options: HydrationSerializerOp
100
100
  flush(): void;
101
101
  close(): void;
102
102
  };
103
+ /**
104
+ * `createHydrationSerializer`'s `late`, which wraps its seroval session
105
+ * per write: rejects, on the client, what a write that failed to serialize
106
+ * midstream left pending (#4647; maintainer ruling,
107
+ * 2026-11-03). seroval 1.7 ends a write at its first failure without
108
+ * settling anything it already declared: the key's promise, a promise or
109
+ * async iterable nested in a value it already sent, each would stay pending
110
+ * forever. Every promise the write sent is rejected (its resolver is indexed
111
+ * right after it, `parsePromise`) and every stream it sent is thrown into,
112
+ * with one error naming the key; one that already settled ignores it. The
113
+ * failure's own text went to the error hook and is not sent. The promise is
114
+ * left unmarked (no `s`/`v`, which seroval's own failure call sets for
115
+ * synchronous adoption): the hydrating read sees it pending and takes the
116
+ * rejection after the claim pass, so the reading computation throws into
117
+ * the nearest `<Errored>`, whose fallback then replaces the server's
118
+ * content. Read synchronously, the fallback would be built in the claim pass
119
+ * against markup that is the content's.
120
+ *
121
+ * Which write a reference belongs to: seroval indexes a value into the
122
+ * shared `refs` as it parses it and hands the chunk that declares it to that
123
+ * write's `onSerialize` in the same synchronous step, so the indexes taken
124
+ * since the last chunk are the next chunk's, or the failed parse's when the
125
+ * write fails instead. Those never went out: they leave `refs`, or a later
126
+ * write reaching the same value (a second key on the same promise) would
127
+ * reference a slot the client never filled and resolve `undefined`; it
128
+ * parses the value again and fails on its own. seroval takes the next index
129
+ * from `refs.size`, so the size counts every index ever taken.
130
+ *
131
+ * `plain(key)` answers with a message when the failure is the key's own
132
+ * rejection and the renderer sends a plain `Error` in its place (#4709): an
133
+ * `<Errored>` drew its fallback from that error, so the promise is rejected
134
+ * with the message and marked the way seroval marks a rejection. The
135
+ * hydrating read then throws it in the claim pass, against the fallback's
136
+ * markup.
137
+ * @internal
138
+ */
139
+ export declare function rejectUnserializedKey(serialize: any, refs: any, onData: any, scopeId: any, plain: any): (key: any, value: any, callbacks: any, live: any) => any; /**
140
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
141
+ * emits ahead of hydration data for a render scope. Not meant for
142
+ * hand-written code.
143
+ * @internal
144
+ */
103
145
  export declare function getLocalHeaderScript(id?: string): string;
104
146
  export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
105
147
  export declare function createJSONSerializer(options: JSONSerializerOptions): {
@@ -100,6 +100,48 @@ export declare function createHydrationSerializer(options: HydrationSerializerOp
100
100
  flush(): void;
101
101
  close(): void;
102
102
  };
103
+ /**
104
+ * `createHydrationSerializer`'s `late`, which wraps its seroval session
105
+ * per write: rejects, on the client, what a write that failed to serialize
106
+ * midstream left pending (#4647; maintainer ruling,
107
+ * 2026-11-03). seroval 1.7 ends a write at its first failure without
108
+ * settling anything it already declared: the key's promise, a promise or
109
+ * async iterable nested in a value it already sent, each would stay pending
110
+ * forever. Every promise the write sent is rejected (its resolver is indexed
111
+ * right after it, `parsePromise`) and every stream it sent is thrown into,
112
+ * with one error naming the key; one that already settled ignores it. The
113
+ * failure's own text went to the error hook and is not sent. The promise is
114
+ * left unmarked (no `s`/`v`, which seroval's own failure call sets for
115
+ * synchronous adoption): the hydrating read sees it pending and takes the
116
+ * rejection after the claim pass, so the reading computation throws into
117
+ * the nearest `<Errored>`, whose fallback then replaces the server's
118
+ * content. Read synchronously, the fallback would be built in the claim pass
119
+ * against markup that is the content's.
120
+ *
121
+ * Which write a reference belongs to: seroval indexes a value into the
122
+ * shared `refs` as it parses it and hands the chunk that declares it to that
123
+ * write's `onSerialize` in the same synchronous step, so the indexes taken
124
+ * since the last chunk are the next chunk's, or the failed parse's when the
125
+ * write fails instead. Those never went out: they leave `refs`, or a later
126
+ * write reaching the same value (a second key on the same promise) would
127
+ * reference a slot the client never filled and resolve `undefined`; it
128
+ * parses the value again and fails on its own. seroval takes the next index
129
+ * from `refs.size`, so the size counts every index ever taken.
130
+ *
131
+ * `plain(key)` answers with a message when the failure is the key's own
132
+ * rejection and the renderer sends a plain `Error` in its place (#4709): an
133
+ * `<Errored>` drew its fallback from that error, so the promise is rejected
134
+ * with the message and marked the way seroval marks a rejection. The
135
+ * hydrating read then throws it in the claim pass, against the fallback's
136
+ * markup.
137
+ * @internal
138
+ */
139
+ export declare function rejectUnserializedKey(serialize: any, refs: any, onData: any, scopeId: any, plain: any): (key: any, value: any, callbacks: any, live: any) => any; /**
140
+ * Renderer primitive — returns the cross-reference bootstrap script SSR
141
+ * emits ahead of hydration data for a render scope. Not meant for
142
+ * hand-written code.
143
+ * @internal
144
+ */
103
145
  export declare function getLocalHeaderScript(id?: string): string;
104
146
  export declare function serializeJSON(value: unknown, options: JSONSerializeOptions): () => void;
105
147
  export declare function createJSONSerializer(options: JSONSerializerOptions): {
@@ -205,8 +205,8 @@ function hasFlightMetadata(response) {
205
205
  }
206
206
  async function deliverFlightData(response, data) {
207
207
  if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
208
- const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
209
- const metadata = hasFlightMetadata(response);
208
+ const folded = response.headers.get(SINGLE_FLIGHT_HEADER)?.split(",");
209
+ const metadata = !folded || hasFlightMetadata(response);
210
210
  for (const source of getFlightDataSourceIds()) {
211
211
  if (!metadata && !folded.includes(source)) continue;
212
212
  const consumer = getFlightDataConsumer(source);
@@ -1074,7 +1074,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1074
1074
  throw serverFunctionFailure(response, undefined);
1075
1075
  }
1076
1076
  const failed = response.headers.has(ERROR_HEADER);
1077
- if (!isReadCall(options) && getFlightDataSourceIds().length > 0) {
1077
+ const mutation = !isReadCall(options) && getFlightDataSourceIds().length > 0;
1078
+ if (mutation) {
1078
1079
  const folded = response.headers.has(SINGLE_FLIGHT_HEADER);
1079
1080
  const metadata = hasFlightMetadata(response);
1080
1081
  if (metadata || folded) {
@@ -1098,6 +1099,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1098
1099
  if (failed) {
1099
1100
  throw serverFunctionFailure(response, result);
1100
1101
  }
1102
+ if (mutation) await deliverFlightData(response);
1101
1103
  if (controller && result?.[Symbol.asyncIterator]) {
1102
1104
  return {
1103
1105
  [Symbol.asyncIterator]() {
@@ -98,8 +98,8 @@ function hasFlightMetadata(response) {
98
98
  }
99
99
  async function deliverFlightData(response, data) {
100
100
  if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
101
- const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
102
- const metadata = hasFlightMetadata(response);
101
+ const folded = response.headers.get(SINGLE_FLIGHT_HEADER)?.split(",");
102
+ const metadata = !folded || hasFlightMetadata(response);
103
103
  for (const source of getFlightDataSourceIds()) {
104
104
  if (!metadata && !folded.includes(source)) continue;
105
105
  const consumer = getFlightDataConsumer(source);
@@ -938,7 +938,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
938
938
  throw serverFunctionFailure(response, undefined);
939
939
  }
940
940
  const failed = response.headers.has(ERROR_HEADER);
941
- if (!isReadCall(options) && getFlightDataSourceIds().length > 0) {
941
+ const mutation = !isReadCall(options) && getFlightDataSourceIds().length > 0;
942
+ if (mutation) {
942
943
  const folded = response.headers.has(SINGLE_FLIGHT_HEADER);
943
944
  const metadata = hasFlightMetadata(response);
944
945
  if (metadata || folded) {
@@ -962,6 +963,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
962
963
  if (failed) {
963
964
  throw serverFunctionFailure(response, result);
964
965
  }
966
+ if (mutation) await deliverFlightData(response);
965
967
  if (controller && result?.[Symbol.asyncIterator]) {
966
968
  return {
967
969
  [Symbol.asyncIterator]() {
@@ -205,8 +205,8 @@ function hasFlightMetadata(response) {
205
205
  }
206
206
  async function deliverFlightData(response, data) {
207
207
  if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
208
- const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
209
- const metadata = hasFlightMetadata(response);
208
+ const folded = response.headers.get(SINGLE_FLIGHT_HEADER)?.split(",");
209
+ const metadata = !folded || hasFlightMetadata(response);
210
210
  for (const source of getFlightDataSourceIds()) {
211
211
  if (!metadata && !folded.includes(source)) continue;
212
212
  const consumer = getFlightDataConsumer(source);
@@ -1074,7 +1074,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1074
1074
  throw serverFunctionFailure(response, undefined);
1075
1075
  }
1076
1076
  const failed = response.headers.has(ERROR_HEADER);
1077
- if (!isReadCall(options) && getFlightDataSourceIds().length > 0) {
1077
+ const mutation = !isReadCall(options) && getFlightDataSourceIds().length > 0;
1078
+ if (mutation) {
1078
1079
  const folded = response.headers.has(SINGLE_FLIGHT_HEADER);
1079
1080
  const metadata = hasFlightMetadata(response);
1080
1081
  if (metadata || folded) {
@@ -1098,6 +1099,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1098
1099
  if (failed) {
1099
1100
  throw serverFunctionFailure(response, result);
1100
1101
  }
1102
+ if (mutation) await deliverFlightData(response);
1101
1103
  if (controller && result?.[Symbol.asyncIterator]) {
1102
1104
  return {
1103
1105
  [Symbol.asyncIterator]() {