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

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.
@@ -1,10 +1,100 @@
1
- import { ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
- import { sharedConfig, NoHydration, getOwner, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
- import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, CLAIM_PROP } from '@solidjs/web';
1
+ import { sharedConfig, ssrSanitizeError, creationStamp, ssrHandleError, runInServerComponentScope, shareAsyncIterable, getProjectionTrace } from 'solid-js/internal';
2
+ import { NoHydration, getOwner, runWithOwner, createMemo, Hydration, createOwner } from 'solid-js';
3
+ import { isResponseEnvelope, renderToStream, createLiveHoles, CLAIMS_STREAM, CLAIMS_DOCUMENT, SLOT_FACE_DATA, slotValue, SLOT_FACE_STREAM, SLOT_FACE_MARKUP, isSlotValue } from '@solidjs/web';
4
4
  import { Feature, createStream, toCrossJSONStream } from 'seroval';
5
5
  import { AbortSignalPlugin, CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web';
6
6
  import { textDigest, frameAddress, getEventServerFunctionInvocation, armLiveBody, createEventChunk, createChunk, ChunkReader, serializeStream, guardFailures } from '@solidjs/web/server-functions/server';
7
7
 
8
+ const DESCEND = Symbol("descend");
9
+ const CYCLE = {};
10
+ const TRACK = 16;
11
+ function rewriteTree(value, visit, withPath) {
12
+ if (value === null || typeof value !== "object") return value;
13
+ const path = withPath ? "" : undefined;
14
+ const state = {
15
+ memo: undefined,
16
+ ancestors: undefined
17
+ };
18
+ try {
19
+ return cow(value, visit, path, 0, state);
20
+ } catch (err) {
21
+ if (err !== CYCLE) throw err;
22
+ }
23
+ return clone(value, visit, path, state.memo || (state.memo = new Map()));
24
+ }
25
+ function shape(value) {
26
+ return Array.isArray(value) ? 1 : Object.getPrototypeOf(value) === Object.prototype ? 2 : 0;
27
+ }
28
+ function cow(value, visit, path, depth, state) {
29
+ const memo = state.memo;
30
+ if (memo !== undefined && memo.has(value)) return memo.get(value);
31
+ const r = visit(value, path);
32
+ if (r !== DESCEND) {
33
+ if (r !== value) (memo || (state.memo = new Map())).set(value, r);
34
+ return r;
35
+ }
36
+ const s = shape(value);
37
+ if (s === 0) return value;
38
+ let ancestors;
39
+ if (depth >= TRACK) {
40
+ ancestors = state.ancestors || (state.ancestors = new Set());
41
+ if (ancestors.has(value)) throw CYCLE;
42
+ ancestors.add(value);
43
+ }
44
+ let out = value;
45
+ if (s === 1) {
46
+ for (let i = 0; i < value.length; i++) {
47
+ const c = value[i];
48
+ if (c === null || typeof c !== "object") continue;
49
+ const next = cow(c, visit, path === undefined ? undefined : `${path}[${i}]`, depth + 1, state);
50
+ if (next !== c) {
51
+ if (out === value) out = value.slice();
52
+ out[i] = next;
53
+ }
54
+ }
55
+ } else {
56
+ for (const k of Object.keys(value)) {
57
+ const c = value[k];
58
+ if (c === null || typeof c !== "object") continue;
59
+ const next = cow(c, visit, path === undefined ? undefined : `${path}.${k}`, depth + 1, state);
60
+ if (next !== c) {
61
+ if (out === value) out = {
62
+ ...value
63
+ };
64
+ out[k] = next;
65
+ }
66
+ }
67
+ }
68
+ if (ancestors !== undefined) ancestors.delete(value);
69
+ return out;
70
+ }
71
+ function clone(value, visit, path, memo) {
72
+ if (memo.has(value)) return memo.get(value);
73
+ const r = visit(value, path);
74
+ if (r !== DESCEND) {
75
+ memo.set(value, r);
76
+ return r;
77
+ }
78
+ const s = shape(value);
79
+ if (s === 0) return value;
80
+ const out = s === 1 ? value.slice() : {
81
+ ...value
82
+ };
83
+ memo.set(value, out);
84
+ if (s === 1) {
85
+ for (let i = 0; i < value.length; i++) {
86
+ const c = value[i];
87
+ if (c !== null && typeof c === "object") out[i] = clone(c, visit, path === undefined ? undefined : `${path}[${i}]`, memo);
88
+ }
89
+ } else {
90
+ for (const k of Object.keys(value)) {
91
+ const c = value[k];
92
+ if (c !== null && typeof c === "object") out[k] = clone(c, visit, path === undefined ? undefined : `${path}.${k}`, memo);
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+
8
98
  const STATE = Symbol.for("solid.container-trace-state");
9
99
  const state = globalThis[STATE] || (globalThis[STATE] = {
10
100
  materialized: new WeakMap(),
@@ -29,38 +119,16 @@ function toBorderForm(value, envelopeContainers) {
29
119
  const resolve = state.resolveTrace ;
30
120
  const share = state.shareIterable;
31
121
  if (!resolve && !share) return value;
32
- if (resolve) {
33
- const trace = resolve(value);
34
- if (trace) return {
35
- [TRACE]: trace
36
- };
37
- }
38
- if (share && isShareableIterable(value)) return share(value);
39
- if (Array.isArray(value)) {
40
- let out = value;
41
- for (let i = 0; i < value.length; i++) {
42
- const next = toBorderForm(value[i]);
43
- if (next !== value[i]) {
44
- if (out === value) out = value.slice();
45
- out[i] = next;
46
- }
47
- }
48
- return out;
49
- }
50
- if (Object.getPrototypeOf(value) === Object.prototype) {
51
- let out = value;
52
- for (const key of Object.keys(value)) {
53
- const next = toBorderForm(value[key]);
54
- if (next !== value[key]) {
55
- if (out === value) out = {
56
- ...value
57
- };
58
- out[key] = next;
59
- }
122
+ return rewriteTree(value, v => {
123
+ if (resolve) {
124
+ const trace = resolve(v);
125
+ if (trace) return {
126
+ [TRACE]: trace
127
+ };
60
128
  }
61
- return out;
62
- }
63
- return value;
129
+ if (share && isShareableIterable(v)) return share(v);
130
+ return DESCEND;
131
+ }, false);
64
132
  }
65
133
  function isShareableIterable(value) {
66
134
  try {
@@ -818,9 +886,52 @@ function frameStream(makeCode, options) {
818
886
  function slotRange(occurrence) {
819
887
  return {
820
888
  t: `<!--slot:${occurrence}:start--><!--slot:${occurrence}:end-->`,
821
- $slot: true
889
+ $slot: true,
890
+ $occurrence: occurrence
822
891
  };
823
892
  }
893
+ const RANGE_KEYS = new Set(["t", "h", "p", "then", "length", "slice", "constructor", "toString", "valueOf", "toJSON"]);
894
+ const NODE_KEYS = new Set(["t", "h", "p"]);
895
+ function isRangeKey(key) {
896
+ const c = key.charCodeAt(0);
897
+ return c === 36 || c >= 48 && c <= 57 || RANGE_KEYS.has(key);
898
+ }
899
+ function slotProxy(range, occurrence, face, content, onData) {
900
+ return new Proxy(range, {
901
+ get(target, key, receiver) {
902
+ if (typeof key !== "string" || isRangeKey(key)) return Reflect.get(target, key, receiver);
903
+ if (onData) onData = void onData();
904
+ return slotValue(occurrence, key, content ? content[key] : undefined, face);
905
+ }
906
+ });
907
+ }
908
+ function argBorderForm(value, key, occurrence) {
909
+ return toBorderForm(withoutStandIns(value));
910
+ }
911
+ function withoutStandIns(value, key, occurrence) {
912
+ return rewriteTree(value, (v, path) => {
913
+ if (isContainerTraced(v)) return v;
914
+ if (Object.getPrototypeOf(v) === Object.prototype && isSlotValue(v)) {
915
+ return undefined;
916
+ }
917
+ return DESCEND;
918
+ }, true);
919
+ }
920
+ function slotFace(range, content) {
921
+ if (content == null) return SLOT_FACE_DATA;
922
+ if (typeof content !== "object" || Array.isArray(content)) return SLOT_FACE_MARKUP;
923
+ if (isServerContent(content)) {
924
+ let data = false;
925
+ for (const key in content) {
926
+ if (!NODE_KEYS.has(key)) {
927
+ data = true;
928
+ break;
929
+ }
930
+ }
931
+ if (!data) return SLOT_FACE_MARKUP;
932
+ }
933
+ return SLOT_FACE_DATA;
934
+ }
824
935
  const OCCURRENCE_UNSAFE = /[^A-Za-z0-9_.-]/g;
825
936
  function encodeOccurrenceKey(key) {
826
937
  return String(key).replace(OCCURRENCE_UNSAFE, c => {
@@ -829,14 +940,58 @@ function encodeOccurrenceKey(key) {
829
940
  });
830
941
  }
831
942
  function occurrenceId(prop, raw, counts) {
832
- const k = raw.$key;
833
- if (typeof k === "string" || typeof k === "number") {
834
- return `${prop}#${encodeOccurrenceKey(k)}`;
835
- }
943
+ const keyed = keyedId(prop, raw);
944
+ if (keyed !== undefined) return keyed;
836
945
  const n = counts[prop] || 0;
837
946
  counts[prop] = n + 1;
838
947
  return `${prop}#${n}`;
839
948
  }
949
+ function keyedId(prop, raw) {
950
+ const k = raw.$key;
951
+ return typeof k === "string" || typeof k === "number" ? `${prop}#${encodeOccurrenceKey(k)}` : undefined;
952
+ }
953
+ function structuralArgsKey(raw) {
954
+ let out = "";
955
+ let ancestors;
956
+ const walk = (v, top) => {
957
+ if (v === null) out += "N";else if (typeof v === "string") out += "s" + v.length + ":" + v;else if (typeof v === "boolean") out += v ? "T" : "F";else if (typeof v === "undefined") out += "U";else if (typeof v === "number") out += "n" + v + ";";else if (typeof v === "bigint") out += "b" + v + ";";else if (typeof v !== "object") return false;else {
958
+ const isArray = Array.isArray(v);
959
+ if (!isArray) {
960
+ const proto = Object.getPrototypeOf(v);
961
+ if (proto !== Object.prototype && proto !== null) return false;
962
+ }
963
+ if (ancestors === undefined) ancestors = new Set();else if (ancestors.has(v)) return false;
964
+ ancestors.add(v);
965
+ try {
966
+ if (isArray) {
967
+ out += "[";
968
+ for (const item of v) if (!walk(item)) return false;
969
+ out += "]";
970
+ } else {
971
+ out += "{";
972
+ for (const k of Object.keys(v).sort()) {
973
+ if (top && k === "$key") continue;
974
+ const desc = Object.getOwnPropertyDescriptor(v, k);
975
+ if (desc.get || desc.set) return false;
976
+ out += "k" + k.length + ":" + k;
977
+ if (!walk(desc.value)) return false;
978
+ }
979
+ out += "}";
980
+ }
981
+ } finally {
982
+ ancestors.delete(v);
983
+ }
984
+ }
985
+ return true;
986
+ };
987
+ return walk(raw, true) ? out : undefined;
988
+ }
989
+ function repeatKey(prop, raw) {
990
+ const keyed = keyedId(prop, raw);
991
+ if (keyed !== undefined) return keyed;
992
+ const structural = structuralArgsKey(raw);
993
+ return structural === undefined ? undefined : prop + "\0" + structural;
994
+ }
840
995
  function isAsyncValue(v) {
841
996
  return !!v && typeof v === "object" && (typeof v.then === "function" || typeof v[Symbol.asyncIterator] === "function");
842
997
  }
@@ -865,6 +1020,7 @@ function suppressedFill(render) {
865
1020
  function createDocumentSlotProps(clientProps, frameId) {
866
1021
  const counts = Object.create(null);
867
1022
  const getters = new Map();
1023
+ const repeats = new Map();
868
1024
  const range = (occurrence, content) => {
869
1025
  const r = [{
870
1026
  t: `<!--slot:${occurrence}:start-->`
@@ -872,7 +1028,10 @@ function createDocumentSlotProps(clientProps, frameId) {
872
1028
  t: `<!--slot:${occurrence}:end-->`
873
1029
  }];
874
1030
  r.$slot = true;
875
- return r;
1031
+ r.$occurrence = occurrence;
1032
+ const face = slotFace(r, content);
1033
+ r.$face = face;
1034
+ return slotProxy(r, occurrence, face, face === SLOT_FACE_DATA ? content : undefined);
876
1035
  };
877
1036
  const zoneOwner = getOwner ? getOwner() : null;
878
1037
  const scoped = (occurrence, render) => {
@@ -896,12 +1055,20 @@ function createDocumentSlotProps(clientProps, frameId) {
896
1055
  if (!fn) {
897
1056
  fn = (...callArgs) => {
898
1057
  if (callArgs.length === 0 || callArgs[0] === undefined) {
899
- return suppressedFill(() => scoped(prop, () => {
1058
+ const rk = prop + "\0";
1059
+ const repeat = repeats.get(rk);
1060
+ if (repeat) return repeat;
1061
+ const out = suppressedFill(() => scoped(prop, () => {
900
1062
  const value = clientProps[prop];
901
1063
  return range(prop, typeof value === "function" ? value() : value);
902
1064
  }));
1065
+ if (out.$face === SLOT_FACE_DATA) repeats.set(rk, out);
1066
+ return out;
903
1067
  }
904
1068
  const raw = callArgs[0];
1069
+ const rk = repeatKey(prop, raw);
1070
+ const repeat = rk !== undefined && repeats.get(rk);
1071
+ if (repeat) return repeat;
905
1072
  const occurrence = occurrenceId(prop, raw, counts);
906
1073
  const slot = clientProps[prop];
907
1074
  if (typeof slot !== "function") return range(occurrence, undefined);
@@ -993,7 +1160,7 @@ function createDocumentSlotProps(clientProps, frameId) {
993
1160
  configurable: true
994
1161
  });
995
1162
  } else {
996
- resolved[key] = value;
1163
+ resolved[key] = vals[key] = withoutStandIns(value);
997
1164
  }
998
1165
  }
999
1166
  const out = suppressedFill(() => scoped(occurrence, () => range(occurrence, slot(resolved))));
@@ -1010,7 +1177,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1010
1177
  continue;
1011
1178
  }
1012
1179
  if (!isContainerTraced(value) && isServerContent(value)) continue;
1013
- args[key] = toBorderForm(value);
1180
+ args[key] = argBorderForm(value);
1014
1181
  }
1015
1182
  sharedConfig.context.serialize(`sc:slot:${frameId}:${occurrence}`, {
1016
1183
  ...args
@@ -1025,7 +1192,7 @@ function createDocumentSlotProps(clientProps, frameId) {
1025
1192
  if (minted[key]) continue;
1026
1193
  const ledgerKey = `${frameId}:${occurrence}:${key}`;
1027
1194
  openArgBinding(liveArgs, ledgerKey, occurrence, key, evals[key], states[key], value => {
1028
- args[key] = toBorderForm(value);
1195
+ args[key] = argBorderForm(value);
1029
1196
  liveArgs.slot(frameId, occurrence, {
1030
1197
  ...args
1031
1198
  });
@@ -1033,10 +1200,10 @@ function createDocumentSlotProps(clientProps, frameId) {
1033
1200
  }
1034
1201
  }
1035
1202
  }
1203
+ if (rk !== undefined && (rk === occurrence || out.$face === SLOT_FACE_DATA)) repeats.has(rk) || repeats.set(rk, out);
1036
1204
  return out;
1037
1205
  };
1038
1206
  fn.$lhSkip = true;
1039
- fn[CLAIM_PROP] = prop;
1040
1207
  getters.set(prop, fn);
1041
1208
  }
1042
1209
  return fn;
@@ -1061,7 +1228,7 @@ function armDocumentLiveHoles(ctx) {
1061
1228
  }
1062
1229
  return;
1063
1230
  }
1064
- if (!live || !ctx.async || ctx.noHydrate || !ctx.serialize || typeof ReadableStream !== "function") {
1231
+ if (!live || !ctx.async || !ctx.serialize || typeof ReadableStream !== "function") {
1065
1232
  ctx.liveHoles = null;
1066
1233
  if (live) live.holes = null;
1067
1234
  return;
@@ -1169,10 +1336,17 @@ function frameTransformDirectResult(value, {
1169
1336
  t: frameElementOpen(id)
1170
1337
  },
1171
1338
  serverOwned(() => {
1172
- armDocumentLiveHoles(sharedConfig.context);
1173
- sharedConfig.context.claims = CLAIMS_DOCUMENT;
1174
- const slotProps = createDocumentSlotProps(props, id);
1175
- return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
1339
+ const page = sharedConfig.context;
1340
+ armDocumentLiveHoles(page);
1341
+ const ctx = Object.create(page);
1342
+ ctx.claims = CLAIMS_DOCUMENT;
1343
+ sharedConfig.context = ctx;
1344
+ try {
1345
+ const slotProps = createDocumentSlotProps(props, id);
1346
+ return serverComponentScope(() => component(slotProps), !!wrapped[LIVE_SOURCE]);
1347
+ } finally {
1348
+ sharedConfig.context = page;
1349
+ }
1176
1350
  }), {
1177
1351
  t: FRAME_ELEMENT_CLOSE
1178
1352
  }];
@@ -1280,6 +1454,7 @@ function openArgBinding(sink, ledgerKey, occurrence, key, evaluate, state, emit)
1280
1454
  function createSlotProps(sink, frame) {
1281
1455
  const counts = Object.create(null);
1282
1456
  const getters = new Map();
1457
+ const repeats = new Map();
1283
1458
  return new Proxy(Object.create(null), {
1284
1459
  has() {
1285
1460
  return true;
@@ -1291,8 +1466,11 @@ function createSlotProps(sink, frame) {
1291
1466
  if (!fn) {
1292
1467
  fn = (...callArgs) => {
1293
1468
  if (callArgs.length === 0 || callArgs[0] === undefined) {
1294
- return slotRange(prop);
1469
+ return slotProxy(slotRange(prop), prop, SLOT_FACE_STREAM, undefined);
1295
1470
  }
1471
+ const rk = repeatKey(prop, callArgs[0]);
1472
+ const repeat = rk !== undefined && repeats.get(rk);
1473
+ if (repeat) return repeat;
1296
1474
  const live = sharedConfig.context && sharedConfig.context.liveHoles;
1297
1475
  if (live) {
1298
1476
  if (live.sweeping) {
@@ -1369,7 +1547,7 @@ function createSlotProps(sink, frame) {
1369
1547
  };
1370
1548
  } else {
1371
1549
  const ref = `arg:${occurrence}:${key}`;
1372
- ctx.serialize(ref, toBorderForm(value, true));
1550
+ ctx.serialize(ref, argBorderForm(value, key, occurrence));
1373
1551
  args[key] = {
1374
1552
  $ref: ref
1375
1553
  };
@@ -1401,7 +1579,7 @@ function createSlotProps(sink, frame) {
1401
1579
  } else {
1402
1580
  const ref = `arg:${occurrence}:${key}@${sink.nextArgRef(ledgerKey)}`;
1403
1581
  sink.mintRef(ref);
1404
- ctx.serialize(ref, toBorderForm(value));
1582
+ ctx.serialize(ref, argBorderForm(value));
1405
1583
  args[key] = {
1406
1584
  $ref: ref
1407
1585
  };
@@ -1411,10 +1589,12 @@ function createSlotProps(sink, frame) {
1411
1589
  });
1412
1590
  });
1413
1591
  }
1414
- return slotRange(occurrence);
1592
+ const keyed = rk === occurrence;
1593
+ const out = slotProxy(slotRange(occurrence), occurrence, SLOT_FACE_STREAM, undefined, rk === undefined || keyed ? undefined : () => repeats.has(rk) || repeats.set(rk, out));
1594
+ if (keyed) repeats.set(rk, out);
1595
+ return out;
1415
1596
  };
1416
1597
  fn.$lhSkip = true;
1417
- fn[CLAIM_PROP] = prop;
1418
1598
  getters.set(prop, fn);
1419
1599
  }
1420
1600
  return fn;
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.11",
4
+ "version": "2.0.0-rc.13",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -41,7 +41,8 @@
41
41
  "frames/package.json",
42
42
  "performance-tracks/dist",
43
43
  "performance-tracks/types",
44
- "performance-tracks/package.json"
44
+ "performance-tracks/package.json",
45
+ "skills"
45
46
  ],
46
47
  "exports": {
47
48
  ".": {
@@ -359,7 +360,7 @@
359
360
  "seroval-plugins": "~1.6.7"
360
361
  },
361
362
  "peerDependencies": {
362
- "solid-js": "^2.0.0-rc.11"
363
+ "solid-js": "^2.0.0-rc.13"
363
364
  },
364
365
  "devDependencies": {
365
366
  "@codspeed/vitest-plugin": "^5.4.0",
@@ -16,20 +16,60 @@ function isDeferredBody(value) {
16
16
  if (typeof v[Symbol.asyncIterator] === "function") return true;
17
17
  return typeof v[Symbol.iterator] === "function" && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set) && !ArrayBuffer.isView(value);
18
18
  }
19
- function observeCall(id, method, args) {
19
+ function observeCall(id, method, args, name) {
20
20
  const channel = records();
21
- if (channel === undefined || !channel.observed("call")) return undefined;
21
+ if (channel === undefined) return undefined;
22
+ const observedCall = channel.observed("call");
23
+ const observedRequest = channel.observed("request");
24
+ if (!observedCall && !observedRequest) return undefined;
22
25
  const at = performance.now();
26
+ const bodies = channel.observed("call", "bodies");
27
+ const requestBodies = bodies || channel.observed("request", "bodies");
23
28
  const origin = currentOrigin();
29
+ const live = {
30
+ args
31
+ };
24
32
  let response;
33
+ let clone;
25
34
  let settled = false;
26
35
  return {
36
+ request(url, init) {
37
+ const at = observedRequest ? performance.now() : 0;
38
+ if (requestBodies) {
39
+ const request = reconstructRequest(url, init);
40
+ if (request !== undefined) live.request = request;
41
+ }
42
+ if (!observedRequest) return;
43
+ const event = {
44
+ side: "client",
45
+ id,
46
+ at,
47
+ method
48
+ };
49
+ if (name !== undefined) event.name = name;
50
+ if (origin !== undefined) event.origin = origin;
51
+ channel.emit("request", event, live);
52
+ },
27
53
  response(r) {
28
54
  response = r;
55
+ if (!bodies) return;
56
+ const type = r.headers.get("content-type");
57
+ if (type !== null && type.startsWith("text/event-stream")) return;
58
+ try {
59
+ clone = r.clone();
60
+ } catch {}
29
61
  },
30
62
  settle(outcome, value) {
31
63
  if (settled) return;
32
64
  settled = true;
65
+ const deferred = outcome === "ok" && isDeferredBody(value);
66
+ if (outcome === "ok") live.result = value;else live.error = value;
67
+ if (deferred && clone !== undefined) {
68
+ cancelBody(clone);
69
+ clone = undefined;
70
+ }
71
+ if (clone !== undefined) live.response = clone;else if (response !== undefined) live.response = response;
72
+ if (!observedCall) return;
33
73
  const event = {
34
74
  id,
35
75
  at,
@@ -37,20 +77,35 @@ function observeCall(id, method, args) {
37
77
  method,
38
78
  outcome
39
79
  };
80
+ if (name !== undefined) event.name = name;
40
81
  if (response !== undefined) event.status = response.status;
41
82
  if (origin !== undefined) event.origin = origin;
42
- const live = {
43
- args
44
- };
45
- if (response !== undefined) live.response = response;
46
- if (outcome === "ok") {
47
- live.result = value;
48
- if (isDeferredBody(value)) event.deferred = true;
49
- } else live.error = value;
83
+ if (deferred) event.deferred = true;
50
84
  channel.emit("call", event, live);
51
85
  }
52
86
  };
53
87
  }
88
+ function reconstructRequest(url, init) {
89
+ try {
90
+ return new Request(new URL(url, globalThis.location?.href), {
91
+ ...init,
92
+ body: reconstructableBody(init.body)
93
+ });
94
+ } catch {
95
+ return undefined;
96
+ }
97
+ }
98
+ function reconstructableBody(body) {
99
+ if (body == null || typeof body === "string") return body;
100
+ if (body instanceof URLSearchParams || typeof FormData !== "undefined" && body instanceof FormData || typeof Blob !== "undefined" && body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return body;
101
+ return undefined;
102
+ }
103
+ function cancelBody(response) {
104
+ try {
105
+ const body = response.body;
106
+ if (body !== null) body.cancel().catch(() => {});
107
+ } catch {}
108
+ }
54
109
 
55
110
  const SERVER_FUNCTION_METADATA = Symbol.for("solid.ServerFunctionMetadata");
56
111
  function getServerFunctionMetadata(fn) {
@@ -751,6 +806,7 @@ async function decodeResponsePayload(response, codecOptions) {
751
806
  };
752
807
  }
753
808
 
809
+ const CALL_OBSERVATION = Symbol("solid.CallObservation");
754
810
  const config = {
755
811
  endpoint: "/_server",
756
812
  fetch: undefined,
@@ -843,6 +899,13 @@ async function createRequest(base, id, options, meta) {
843
899
  if (wire.position !== undefined) headers[LAST_EVENT_ID_HEADER] = wire.position;
844
900
  if (wire.headers) Object.assign(headers, wire.headers);
845
901
  }
902
+ const observation = options[CALL_OBSERVATION] ;
903
+ if (observation) {
904
+ options = {
905
+ ...options
906
+ };
907
+ delete options[CALL_OBSERVATION];
908
+ }
846
909
  const flightSources = getFlightDataSourceIds();
847
910
  if (flightSources.length > 0 && !isReadCall(options)) {
848
911
  headers[SINGLE_FLIGHT_HEADER] = flightSources.join(",");
@@ -867,6 +930,7 @@ async function createRequest(base, id, options, meta) {
867
930
  }
868
931
  init = prepared || init;
869
932
  }
933
+ if (observation) observation.request(base, init);
870
934
  const send = config.fetch || fetch;
871
935
  return send(base, init);
872
936
  }
@@ -931,7 +995,7 @@ async function initializeResponse(base, id, options, args, meta) {
931
995
  }, meta);
932
996
  }
933
997
  async function observedFetch(base, id, options, args, meta, callArgs = args) {
934
- const observation = observeCall(id, options.method && options.method.toUpperCase() === "GET" ? "GET" : "POST", callArgs);
998
+ const observation = observeCall(id, options.method && options.method.toUpperCase() === "GET" ? "GET" : "POST", callArgs, meta && meta.name);
935
999
  if (!observation) return dispatchServerFunction(base, id, options, args, meta, callArgs);
936
1000
  let result;
937
1001
  try {
@@ -955,6 +1019,10 @@ async function dispatchServerFunction(base, id, options, args, meta, callArgs =
955
1019
  ...options,
956
1020
  signal: controller.signal
957
1021
  };
1022
+ if (observation) options = {
1023
+ ...options,
1024
+ [CALL_OBSERVATION]: observation
1025
+ };
958
1026
  const response = await initializeResponse(base, id, options, args, meta);
959
1027
  if (observation) observation.response(response);
960
1028
  if (handler) {