@solidjs/web 2.0.0-rc.13 → 2.0.0-rc.14

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 (57) hide show
  1. package/dist/server.dev.js +200 -73
  2. package/dist/server.js +182 -59
  3. package/dist/server.observe.js +183 -60
  4. package/dist/web.dev.js +70 -35
  5. package/dist/web.js +43 -31
  6. package/dist/web.observe.js +43 -33
  7. package/frames/dist/assets.js +92 -0
  8. package/frames/dist/bind.dev.js +326 -0
  9. package/frames/dist/bind.js +295 -0
  10. package/frames/dist/client.dev.js +605 -1086
  11. package/frames/dist/client.js +572 -1066
  12. package/frames/dist/client.observe.js +571 -1066
  13. package/frames/dist/regions.js +130 -0
  14. package/frames/dist/server.dev.js +339 -177
  15. package/frames/dist/server.js +335 -173
  16. package/frames/dist/server.observe.js +335 -173
  17. package/frames/dist/trace.js +42 -0
  18. package/frames/dist/wire.js +133 -0
  19. package/package.json +28 -2
  20. package/performance-tracks/dist/performance-tracks.dev.js +2 -1
  21. package/performance-tracks/dist/performance-tracks.observe.js +2 -1
  22. package/performance-tracks/types/index.d.ts +8 -6
  23. package/serialization/dist/decode.js +37 -8
  24. package/serialization/dist/serialization.js +39 -10
  25. package/serialization/types/serializer-decode.d.ts +24 -2
  26. package/server-functions/dist/client.dev.js +99 -61
  27. package/server-functions/dist/client.js +99 -61
  28. package/server-functions/dist/client.observe.js +99 -61
  29. package/server-functions/dist/server.dev.js +87 -50
  30. package/server-functions/dist/server.js +87 -50
  31. package/server-functions/dist/server.observe.js +87 -50
  32. package/skills/server-components/SKILL.md +65 -43
  33. package/types/client.d.ts +20 -0
  34. package/types/constants.d.ts +2 -1
  35. package/types/diagnostics.d.ts +8 -0
  36. package/types/frames/assets-tier.d.ts +78 -0
  37. package/types/frames/bind-tier.d.ts +60 -0
  38. package/types/frames/client.d.ts +37 -3
  39. package/types/frames/frame-client.d.ts +249 -78
  40. package/types/frames/frame-container-plugin.d.ts +2 -2
  41. package/types/frames/frame-sink.d.ts +33 -0
  42. package/types/frames/frame-transport.d.ts +66 -18
  43. package/types/frames/regions-tier.d.ts +45 -0
  44. package/types/frames/serializer-decode.d.ts +24 -2
  45. package/types/frames/server.d.ts +32 -8
  46. package/types/frames/trace-tier.d.ts +2 -0
  47. package/types/frames/wire-tier.d.ts +116 -0
  48. package/types/index.d.ts +38 -0
  49. package/types/index.server.d.ts +9 -0
  50. package/types/jsx.d.ts +1 -1
  51. package/types/observe.d.ts +4 -2
  52. package/types/serializer-decode.d.ts +24 -2
  53. package/types/server-functions/client.d.ts +26 -0
  54. package/types/server-functions/registry.d.ts +4 -1
  55. package/types/server-functions/shared.d.ts +12 -8
  56. package/types/server-mock.d.ts +13 -1
  57. package/types/server.d.ts +34 -8
@@ -158,7 +158,7 @@ function provideServerFunctionRPC(rpc) {
158
158
  }
159
159
 
160
160
  const FLASH_COOKIE = "flash";
161
- const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
161
+ const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
162
162
  function hasFlashCookie(cookieHeader) {
163
163
  return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
164
164
  }
@@ -204,6 +204,7 @@ function hasFlightMetadata(response) {
204
204
  return response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
205
205
  }
206
206
  async function deliverFlightData(response, data) {
207
+ if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
207
208
  const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
208
209
  const metadata = hasFlightMetadata(response);
209
210
  for (const source of getFlightDataSourceIds()) {
@@ -523,26 +524,42 @@ async function extractBody(source, codecOptions, wire) {
523
524
  return undefined;
524
525
  }
525
526
  function createChunk(data) {
526
- const encoder = new TextEncoder();
527
- const encodeData = encoder.encode(data);
527
+ const encodeData = CHUNK_ENCODER.encode(data);
528
528
  const bytes = encodeData.length;
529
+ if (bytes > MAX_CHUNK_BYTES) {
530
+ throw new RangeError("Server function chunk is too large to frame.");
531
+ }
529
532
  const chunk = new Uint8Array(12 + bytes);
530
- chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
533
+ chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
531
534
  chunk.set(encodeData, 12);
532
535
  return chunk;
533
536
  }
537
+ const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
538
+ const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
539
+ fatal: true
540
+ });
541
+ const MAX_CHUNK_BYTES = 0xffffffff;
542
+ const RETAINED_STORE_BYTES = 64 * 1024;
543
+ const DONE = {
544
+ done: true,
545
+ value: undefined
546
+ };
547
+ function malformedStream() {
548
+ return new Error("Malformed server function stream.");
549
+ }
534
550
  class ChunkReader {
535
551
  constructor(stream) {
536
552
  this.reader = stream.getReader();
537
553
  this.store = new Uint8Array(0);
538
554
  this.buffer = this.store;
539
555
  this.done = false;
556
+ this.cancelled = false;
540
557
  }
541
558
  async readChunk() {
542
559
  const chunk = await this.reader.read();
543
560
  if (chunk.done) {
544
561
  this.done = true;
545
- return;
562
+ return this.cancelled;
546
563
  }
547
564
  const incoming = chunk.value;
548
565
  const store = this.store;
@@ -563,55 +580,66 @@ class ChunkReader {
563
580
  this.store = grown;
564
581
  this.buffer = grown.subarray(0, needed);
565
582
  }
583
+ return this.cancelled;
566
584
  }
567
585
  async next() {
586
+ if (this.cancelled) return DONE;
568
587
  while (this.buffer.length < 12) {
569
588
  if (this.done) {
570
- if (this.buffer.length === 0) return {
571
- done: true,
572
- value: undefined
573
- };
574
- throw new Error("Malformed server function stream.");
589
+ if (this.buffer.length === 0) return DONE;
590
+ throw malformedStream();
575
591
  }
576
- await this.readChunk();
577
- }
578
- const decoder = new TextDecoder();
579
- const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
580
- if (Number.isNaN(bytes)) {
581
- throw new Error("Malformed server function stream.");
592
+ if (await this.readChunk()) return DONE;
582
593
  }
594
+ const header = String.fromCharCode(...this.buffer.subarray(0, 12));
595
+ if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
596
+ const bytes = parseInt(header.slice(3, 11), 16);
583
597
  while (bytes > this.buffer.length - 12) {
584
598
  if (this.done) {
585
- throw new Error("Malformed server function stream.");
599
+ throw malformedStream();
586
600
  }
587
- await this.readChunk();
601
+ if (await this.readChunk()) return DONE;
602
+ }
603
+ let partial;
604
+ try {
605
+ partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
606
+ } catch {
607
+ throw malformedStream();
588
608
  }
589
- const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
590
609
  this.buffer = this.buffer.subarray(12 + bytes);
610
+ if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
611
+ this.store = this.buffer = this.buffer.slice();
612
+ }
591
613
  return {
592
614
  done: false,
593
615
  value: partial
594
616
  };
595
617
  }
596
618
  async drain(interpret) {
597
- while (true) {
598
- const result = await this.next();
599
- if (result.done) {
600
- break;
619
+ try {
620
+ while (true) {
621
+ const result = await this.next();
622
+ if (result.done) {
623
+ break;
624
+ }
625
+ interpret(result.value);
601
626
  }
602
- interpret(result.value);
627
+ } catch (error) {
628
+ this.cancel(error).catch(() => {});
629
+ throw error;
603
630
  }
604
631
  }
605
632
  cancel(reason) {
633
+ this.cancelled = true;
606
634
  return this.reader.cancel(reason);
607
635
  }
608
636
  }
609
637
  function createEventChunk(data, id) {
610
638
  let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
611
639
  for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
612
- return new TextEncoder().encode(event + "\n");
640
+ return CHUNK_ENCODER.encode(event + "\n");
613
641
  }
614
- const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
642
+ const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
615
643
  function isEventStream(source) {
616
644
  const contentType = source.headers.get("content-type");
617
645
  return !!contentType && contentType.startsWith("text/event-stream");
@@ -754,40 +782,44 @@ async function deserializeStream(source, codecOptions, wire) {
754
782
  throw new Error("missing body");
755
783
  }
756
784
  const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
757
- const result = await reader.next();
758
- if (!result.done) {
759
- if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
760
- throw errorFromTrailer(result.value);
761
- }
762
- const {
763
- createJSONDeserializer
764
- } = await import('@solidjs/web/serialization/decode');
765
- const deserializeChunk = createJSONDeserializer(codecOptions);
766
- function interpretChunk(chunk) {
767
- if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
768
- throw errorFromTrailer(chunk);
785
+ try {
786
+ const result = await reader.next();
787
+ if (!result.done) {
788
+ if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
789
+ throw errorFromTrailer(result.value);
790
+ }
791
+ const {
792
+ createJSONDeserializer
793
+ } = await import('@solidjs/web/serialization/decode');
794
+ const deserializeChunk = createJSONDeserializer(codecOptions);
795
+ function interpretChunk(chunk) {
796
+ if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
797
+ throw errorFromTrailer(chunk);
798
+ }
799
+ return deserializeChunk(JSON.parse(chunk));
769
800
  }
770
- return deserializeChunk(JSON.parse(chunk));
801
+ const connection = wire && wire.connection;
802
+ let endConnection;
803
+ if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
804
+ const end = error => {
805
+ const sweep = () => deserializeChunk.abort(error);
806
+ if (connection) {
807
+ const close = () => deserializeChunk.close();
808
+ endConnection({
809
+ open: deserializeChunk.open(),
810
+ error,
811
+ sweep,
812
+ close
813
+ });
814
+ } else sweep();
815
+ };
816
+ reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
817
+ return interpretChunk(result.value);
771
818
  }
772
- const connection = wire && wire.connection;
773
- let endConnection;
774
- if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
775
- const end = error => {
776
- const sweep = () => deserializeChunk.abort(error);
777
- if (connection) {
778
- const close = () => deserializeChunk.close();
779
- endConnection({
780
- open: deserializeChunk.open(),
781
- error,
782
- sweep,
783
- close
784
- });
785
- } else sweep();
786
- };
787
- reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
788
- return interpretChunk(result.value);
819
+ } catch (error) {
820
+ reader.cancel(error).catch(() => {});
821
+ throw error;
789
822
  }
790
- return undefined;
791
823
  }
792
824
  async function decodeResponse(response, codecOptions) {
793
825
  if (!response.body) return undefined;
@@ -1014,6 +1046,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1014
1046
  id,
1015
1047
  meta
1016
1048
  }) : undefined;
1049
+ const sent = options;
1017
1050
  const controller = options.signal ? undefined : new AbortController();
1018
1051
  if (controller) options = {
1019
1052
  ...options,
@@ -1030,7 +1063,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
1030
1063
  id,
1031
1064
  meta,
1032
1065
  args: callArgs,
1033
- context
1066
+ context,
1067
+ retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
1034
1068
  };
1035
1069
  if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
1036
1070
  const handled = handler.handle(response, ctx);
@@ -1094,7 +1128,8 @@ function createServerReference(id, name, base) {
1094
1128
  const hit = handler.intercept({
1095
1129
  id,
1096
1130
  meta: metadata,
1097
- args
1131
+ args,
1132
+ retry: send
1098
1133
  });
1099
1134
  if (hit !== undefined) return localOrSend(hit, send);
1100
1135
  }
@@ -1125,12 +1160,14 @@ function GET(fn) {
1125
1160
  const run = async (args, invokeOptions) => {
1126
1161
  const handler = config.responseHandler;
1127
1162
  if (handler && handler.intercept && !adoptedCall(invokeOptions)) {
1163
+ const retry = () => send(args, invokeOptions);
1128
1164
  const hit = handler.intercept({
1129
1165
  id,
1130
1166
  meta: metadata,
1131
- args
1167
+ args,
1168
+ retry
1132
1169
  });
1133
- if (hit !== undefined) return localOrSend(hit, () => send(args, invokeOptions));
1170
+ if (hit !== undefined) return localOrSend(hit, retry);
1134
1171
  }
1135
1172
  return send(args, invokeOptions);
1136
1173
  };
@@ -1204,6 +1241,7 @@ function live(fn) {
1204
1241
  };
1205
1242
  const makeIterable = (args, invokeOptions) => {
1206
1243
  const handler = config.responseHandler;
1244
+ handler && handler.onLive && handler.onLive();
1207
1245
  const local = handler && handler.intercept ? handler.intercept({
1208
1246
  id,
1209
1247
  meta: metadata,
@@ -51,7 +51,7 @@ function provideServerFunctionRPC(rpc) {
51
51
  }
52
52
 
53
53
  const FLASH_COOKIE = "flash";
54
- const FLASH_MATCHER = new RegExp(`(?:^|;\\s*)${FLASH_COOKIE}=([^;]+)`);
54
+ const FLASH_MATCHER = /(?:^|;\s*)flash=([^;]+)/;
55
55
  function hasFlashCookie(cookieHeader) {
56
56
  return !!cookieHeader && FLASH_MATCHER.test(cookieHeader);
57
57
  }
@@ -97,6 +97,7 @@ function hasFlightMetadata(response) {
97
97
  return response.headers.has(REDIRECT_HEADER) || response.headers.has(REVALIDATE_HEADER);
98
98
  }
99
99
  async function deliverFlightData(response, data) {
100
+ if (data) await Promise.allSettled(Object.values(data).flatMap(s => s && typeof s == "object" ? Object.values(s) : []));
100
101
  const folded = (response.headers.get(SINGLE_FLIGHT_HEADER) || "").split(",");
101
102
  const metadata = hasFlightMetadata(response);
102
103
  for (const source of getFlightDataSourceIds()) {
@@ -416,26 +417,42 @@ async function extractBody(source, codecOptions, wire) {
416
417
  return undefined;
417
418
  }
418
419
  function createChunk(data) {
419
- const encoder = new TextEncoder();
420
- const encodeData = encoder.encode(data);
420
+ const encodeData = CHUNK_ENCODER.encode(data);
421
421
  const bytes = encodeData.length;
422
+ if (bytes > MAX_CHUNK_BYTES) {
423
+ throw new RangeError("Server function chunk is too large to frame.");
424
+ }
422
425
  const chunk = new Uint8Array(12 + bytes);
423
- chunk.set(encoder.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
426
+ chunk.set(CHUNK_ENCODER.encode(`;0x${bytes.toString(16).padStart(8, "0")};`));
424
427
  chunk.set(encodeData, 12);
425
428
  return chunk;
426
429
  }
430
+ const CHUNK_ENCODER = /* @__PURE__ */new TextEncoder();
431
+ const CHUNK_DECODER = /* @__PURE__ */new TextDecoder("utf-8", {
432
+ fatal: true
433
+ });
434
+ const MAX_CHUNK_BYTES = 0xffffffff;
435
+ const RETAINED_STORE_BYTES = 64 * 1024;
436
+ const DONE = {
437
+ done: true,
438
+ value: undefined
439
+ };
440
+ function malformedStream() {
441
+ return new Error("Malformed server function stream.");
442
+ }
427
443
  class ChunkReader {
428
444
  constructor(stream) {
429
445
  this.reader = stream.getReader();
430
446
  this.store = new Uint8Array(0);
431
447
  this.buffer = this.store;
432
448
  this.done = false;
449
+ this.cancelled = false;
433
450
  }
434
451
  async readChunk() {
435
452
  const chunk = await this.reader.read();
436
453
  if (chunk.done) {
437
454
  this.done = true;
438
- return;
455
+ return this.cancelled;
439
456
  }
440
457
  const incoming = chunk.value;
441
458
  const store = this.store;
@@ -456,55 +473,66 @@ class ChunkReader {
456
473
  this.store = grown;
457
474
  this.buffer = grown.subarray(0, needed);
458
475
  }
476
+ return this.cancelled;
459
477
  }
460
478
  async next() {
479
+ if (this.cancelled) return DONE;
461
480
  while (this.buffer.length < 12) {
462
481
  if (this.done) {
463
- if (this.buffer.length === 0) return {
464
- done: true,
465
- value: undefined
466
- };
467
- throw new Error("Malformed server function stream.");
482
+ if (this.buffer.length === 0) return DONE;
483
+ throw malformedStream();
468
484
  }
469
- await this.readChunk();
470
- }
471
- const decoder = new TextDecoder();
472
- const bytes = Number.parseInt(decoder.decode(this.buffer.subarray(1, 11)), 16);
473
- if (Number.isNaN(bytes)) {
474
- throw new Error("Malformed server function stream.");
485
+ if (await this.readChunk()) return DONE;
475
486
  }
487
+ const header = String.fromCharCode(...this.buffer.subarray(0, 12));
488
+ if (!/^;0x[\dA-Fa-f]{8};$/.test(header)) throw malformedStream();
489
+ const bytes = parseInt(header.slice(3, 11), 16);
476
490
  while (bytes > this.buffer.length - 12) {
477
491
  if (this.done) {
478
- throw new Error("Malformed server function stream.");
492
+ throw malformedStream();
479
493
  }
480
- await this.readChunk();
494
+ if (await this.readChunk()) return DONE;
495
+ }
496
+ let partial;
497
+ try {
498
+ partial = CHUNK_DECODER.decode(this.buffer.subarray(12, 12 + bytes));
499
+ } catch {
500
+ throw malformedStream();
481
501
  }
482
- const partial = decoder.decode(this.buffer.subarray(12, 12 + bytes));
483
502
  this.buffer = this.buffer.subarray(12 + bytes);
503
+ if (this.store.length > RETAINED_STORE_BYTES && this.buffer.length <= RETAINED_STORE_BYTES) {
504
+ this.store = this.buffer = this.buffer.slice();
505
+ }
484
506
  return {
485
507
  done: false,
486
508
  value: partial
487
509
  };
488
510
  }
489
511
  async drain(interpret) {
490
- while (true) {
491
- const result = await this.next();
492
- if (result.done) {
493
- break;
512
+ try {
513
+ while (true) {
514
+ const result = await this.next();
515
+ if (result.done) {
516
+ break;
517
+ }
518
+ interpret(result.value);
494
519
  }
495
- interpret(result.value);
520
+ } catch (error) {
521
+ this.cancel(error).catch(() => {});
522
+ throw error;
496
523
  }
497
524
  }
498
525
  cancel(reason) {
526
+ this.cancelled = true;
499
527
  return this.reader.cancel(reason);
500
528
  }
501
529
  }
502
530
  function createEventChunk(data, id) {
503
531
  let event = id !== undefined && !id.includes("\0") ? `id: ${id}\n` : "";
504
532
  for (const line of data.split(/\r\n|\r|\n/)) event += `data: ${line}\n`;
505
- return new TextEncoder().encode(event + "\n");
533
+ return CHUNK_ENCODER.encode(event + "\n");
506
534
  }
507
- const EVENT_STREAM_HEARTBEAT = new TextEncoder().encode(":\n\n");
535
+ const EVENT_STREAM_HEARTBEAT = /* @__PURE__ */new TextEncoder().encode(":\n\n");
508
536
  function isEventStream(source) {
509
537
  const contentType = source.headers.get("content-type");
510
538
  return !!contentType && contentType.startsWith("text/event-stream");
@@ -647,40 +675,44 @@ async function deserializeStream(source, codecOptions, wire) {
647
675
  throw new Error("missing body");
648
676
  }
649
677
  const reader = wire && isEventStream(source) ? wire.open(source.body) : new ChunkReader(source.body);
650
- const result = await reader.next();
651
- if (!result.done) {
652
- if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
653
- throw errorFromTrailer(result.value);
654
- }
655
- const {
656
- createJSONDeserializer
657
- } = await import('@solidjs/web/serialization/decode');
658
- const deserializeChunk = createJSONDeserializer(codecOptions);
659
- function interpretChunk(chunk) {
660
- if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
661
- throw errorFromTrailer(chunk);
678
+ try {
679
+ const result = await reader.next();
680
+ if (!result.done) {
681
+ if (result.value.startsWith(ERROR_TRAILER_PREFIX)) {
682
+ throw errorFromTrailer(result.value);
662
683
  }
663
- return deserializeChunk(JSON.parse(chunk));
684
+ const {
685
+ createJSONDeserializer
686
+ } = await import('@solidjs/web/serialization/decode');
687
+ const deserializeChunk = createJSONDeserializer(codecOptions);
688
+ function interpretChunk(chunk) {
689
+ if (chunk.startsWith(ERROR_TRAILER_PREFIX)) {
690
+ throw errorFromTrailer(chunk);
691
+ }
692
+ return deserializeChunk(JSON.parse(chunk));
693
+ }
694
+ const connection = wire && wire.connection;
695
+ let endConnection;
696
+ if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
697
+ const end = error => {
698
+ const sweep = () => deserializeChunk.abort(error);
699
+ if (connection) {
700
+ const close = () => deserializeChunk.close();
701
+ endConnection({
702
+ open: deserializeChunk.open(),
703
+ error,
704
+ sweep,
705
+ close
706
+ });
707
+ } else sweep();
708
+ };
709
+ reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
710
+ return interpretChunk(result.value);
664
711
  }
665
- const connection = wire && wire.connection;
666
- let endConnection;
667
- if (connection) connection.ended = new Promise(resolve => endConnection = resolve);
668
- const end = error => {
669
- const sweep = () => deserializeChunk.abort(error);
670
- if (connection) {
671
- const close = () => deserializeChunk.close();
672
- endConnection({
673
- open: deserializeChunk.open(),
674
- error,
675
- sweep,
676
- close
677
- });
678
- } else sweep();
679
- };
680
- reader.drain(interpretChunk).then(() => end(new Error("Server function stream ended unexpectedly.")), error => end(error));
681
- return interpretChunk(result.value);
712
+ } catch (error) {
713
+ reader.cancel(error).catch(() => {});
714
+ throw error;
682
715
  }
683
- return undefined;
684
716
  }
685
717
  async function decodeResponse(response, codecOptions) {
686
718
  if (!response.body) return undefined;
@@ -885,6 +917,7 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
885
917
  id,
886
918
  meta
887
919
  }) : undefined;
920
+ const sent = options;
888
921
  const controller = options.signal ? undefined : new AbortController();
889
922
  if (controller) options = {
890
923
  ...options,
@@ -896,7 +929,8 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
896
929
  id,
897
930
  meta,
898
931
  args: callArgs,
899
- context
932
+ context,
933
+ retry: () => fetchServerFunction(base, id, sent, args, meta, callArgs)
900
934
  };
901
935
  if (options[LIVE_WIRE]) ctx[LIVE_WIRE] = options[LIVE_WIRE];
902
936
  const handled = handler.handle(response, ctx);
@@ -960,7 +994,8 @@ function createServerReference(id, name, base) {
960
994
  const hit = handler.intercept({
961
995
  id,
962
996
  meta: metadata,
963
- args
997
+ args,
998
+ retry: send
964
999
  });
965
1000
  if (hit !== undefined) return localOrSend(hit, send);
966
1001
  }
@@ -991,12 +1026,14 @@ function GET(fn) {
991
1026
  const run = async (args, invokeOptions) => {
992
1027
  const handler = config.responseHandler;
993
1028
  if (handler && handler.intercept && !adoptedCall(invokeOptions)) {
1029
+ const retry = () => send(args, invokeOptions);
994
1030
  const hit = handler.intercept({
995
1031
  id,
996
1032
  meta: metadata,
997
- args
1033
+ args,
1034
+ retry
998
1035
  });
999
- if (hit !== undefined) return localOrSend(hit, () => send(args, invokeOptions));
1036
+ if (hit !== undefined) return localOrSend(hit, retry);
1000
1037
  }
1001
1038
  return send(args, invokeOptions);
1002
1039
  };
@@ -1054,6 +1091,7 @@ function live(fn) {
1054
1091
  };
1055
1092
  const makeIterable = (args, invokeOptions) => {
1056
1093
  const handler = config.responseHandler;
1094
+ handler && handler.onLive && handler.onLive();
1057
1095
  const local = handler && handler.intercept ? handler.intercept({
1058
1096
  id,
1059
1097
  meta: metadata,