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

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 (107) hide show
  1. package/dist/server.dev.js +4472 -0
  2. package/dist/server.js +1301 -251
  3. package/dist/{server.cjs → server.observe.js} +1501 -452
  4. package/dist/{dev.cjs → web.dev.js} +699 -360
  5. package/dist/web.js +454 -139
  6. package/dist/{dev.js → web.observe.js} +505 -211
  7. package/frames/dist/client.dev.js +463 -71
  8. package/frames/dist/client.js +363 -70
  9. package/frames/dist/{client.dev.cjs → client.observe.js} +486 -133
  10. package/frames/dist/server.dev.js +1713 -0
  11. package/frames/dist/server.js +552 -2583
  12. package/frames/dist/server.observe.js +1713 -0
  13. package/frames/package.json +2 -25
  14. package/package.json +214 -255
  15. package/performance-tracks/dist/performance-tracks.dev.js +678 -0
  16. package/performance-tracks/dist/performance-tracks.js +6 -0
  17. package/performance-tracks/dist/performance-tracks.observe.js +666 -0
  18. package/performance-tracks/package.json +7 -0
  19. package/performance-tracks/types/index.d.ts +67 -0
  20. package/serialization/decode/package.json +2 -15
  21. package/serialization/dist/decode.js +92 -15
  22. package/serialization/dist/serialization.js +103 -23
  23. package/serialization/package.json +2 -15
  24. package/serialization/types/index.d.ts +76 -157
  25. package/serialization/types/serializer-decode.d.ts +149 -112
  26. package/serialization/types/serializer.d.ts +101 -0
  27. package/server-functions/dist/client.dev.js +1364 -0
  28. package/server-functions/dist/client.js +611 -97
  29. package/server-functions/dist/client.observe.js +1343 -0
  30. package/server-functions/dist/server.dev.js +2138 -202
  31. package/server-functions/dist/server.js +2042 -199
  32. package/server-functions/dist/server.observe.js +3043 -0
  33. package/server-functions/package.json +2 -35
  34. package/server-functions/rich-args/package.json +2 -15
  35. package/storage/package.json +2 -15
  36. package/types/client.d.ts +193 -288
  37. package/types/constants.d.ts +20 -0
  38. package/types/cookies.d.ts +32 -84
  39. package/types/diagnostics.d.ts +56 -0
  40. package/types/frames/client.d.ts +1 -1
  41. package/types/frames/frame-client.d.ts +323 -259
  42. package/types/frames/frame-container-plugin.d.ts +72 -0
  43. package/types/frames/frame-sink.d.ts +101 -158
  44. package/types/frames/frame-transport.d.ts +192 -190
  45. package/types/frames/serializer-decode.d.ts +219 -0
  46. package/types/frames/serializer.d.ts +76 -157
  47. package/types/frames/server.d.ts +1 -1
  48. package/types/head.d.ts +19 -0
  49. package/types/index.d.ts +52 -80
  50. package/types/index.server.d.ts +174 -0
  51. package/types/jsx.d.ts +33 -35
  52. package/types/observe.d.ts +358 -0
  53. package/types/reconcile.d.ts +1 -0
  54. package/types/render.d.ts +9 -0
  55. package/types/response.d.ts +75 -150
  56. package/types/serializer-decode.d.ts +149 -112
  57. package/types/serializer.d.ts +76 -157
  58. package/types/server-functions/client.d.ts +192 -194
  59. package/types/server-functions/flash.d.ts +28 -30
  60. package/types/server-functions/registry.d.ts +102 -0
  61. package/types/server-functions/rich-args.d.ts +1 -10
  62. package/types/server-functions/server.d.ts +511 -475
  63. package/types/server-functions/shared.d.ts +366 -425
  64. package/types/server-mock.d.ts +110 -13
  65. package/types/server-observe.d.ts +77 -0
  66. package/types/server.d.ts +425 -425
  67. package/types/trace.d.ts +127 -0
  68. package/LICENSE +0 -21
  69. package/dist/web.cjs +0 -2008
  70. package/frames/dist/client.cjs +0 -1916
  71. package/frames/dist/server.cjs +0 -3756
  72. package/serialization/dist/decode.cjs +0 -122
  73. package/serialization/dist/serialization.cjs +0 -244
  74. package/serialization/types-cjs/index.d.cts +0 -182
  75. package/serialization/types-cjs/package.json +0 -3
  76. package/serialization/types-cjs/serializer-decode.d.cts +0 -182
  77. package/server-functions/dist/client.cjs +0 -793
  78. package/server-functions/dist/rich-args.cjs +0 -11
  79. package/server-functions/dist/server.cjs +0 -1171
  80. package/server-functions/dist/server.dev.cjs +0 -1171
  81. package/storage/dist/storage.cjs +0 -12
  82. package/storage/types-cjs/index.d.cts +0 -28
  83. package/storage/types-cjs/package.json +0 -3
  84. package/types/core.d.ts +0 -6
  85. package/types-cjs/client.d.cts +0 -337
  86. package/types-cjs/cookies.d.cts +0 -93
  87. package/types-cjs/core.d.cts +0 -6
  88. package/types-cjs/frames/client.d.cts +0 -36
  89. package/types-cjs/frames/frame-client.d.cts +0 -338
  90. package/types-cjs/frames/frame-sink.d.cts +0 -194
  91. package/types-cjs/frames/frame-transport.d.cts +0 -222
  92. package/types-cjs/frames/serializer.d.cts +0 -182
  93. package/types-cjs/frames/server.d.cts +0 -52
  94. package/types-cjs/index.d.cts +0 -244
  95. package/types-cjs/jsx-properties.d.cts +0 -93
  96. package/types-cjs/jsx.d.cts +0 -4159
  97. package/types-cjs/package.json +0 -3
  98. package/types-cjs/response.d.cts +0 -174
  99. package/types-cjs/serializer-decode.d.cts +0 -182
  100. package/types-cjs/serializer.d.cts +0 -182
  101. package/types-cjs/server-functions/client.d.cts +0 -231
  102. package/types-cjs/server-functions/flash.d.cts +0 -38
  103. package/types-cjs/server-functions/rich-args.d.cts +0 -10
  104. package/types-cjs/server-functions/server.d.cts +0 -616
  105. package/types-cjs/server-functions/shared.d.cts +0 -523
  106. package/types-cjs/server-mock.d.cts +0 -277
  107. package/types-cjs/server.d.cts +0 -523
@@ -0,0 +1,678 @@
1
+ import { OBSERVE, DEV } from 'solid-js';
2
+ import { attribution, formatRerun, formatOrigin } from 'solid-js/attribution';
3
+
4
+ const IS_DEV = true;
5
+ const GROUP = "Solid";
6
+ const TRACKS = {
7
+ interactions: "Interactions",
8
+ propagation: "Propagation",
9
+ effects: "Effects",
10
+ memos: "Memos",
11
+ async: "Async",
12
+ holds: "Holds",
13
+ navigations: "Navigations",
14
+ server: "Server"
15
+ };
16
+ const noop = () => {};
17
+ function enablePerformanceTracks(options = {}) {
18
+ if (instance !== null) return instance.join();
19
+ const observe = OBSERVE;
20
+ if (observe === undefined) return noop;
21
+ if (typeof performance !== "object" || typeof performance.now !== "function") return noop;
22
+ const emitter = createEmitter(options.rich ?? IS_DEV);
23
+ if (emitter === undefined) return noop;
24
+ const minMs = options.minMs ?? (0 );
25
+ const painter = new Painter(emitter, minMs);
26
+ const server = new ServerSpans(emitter);
27
+ server.start();
28
+ const {
29
+ records
30
+ } = observe;
31
+ const releases = [() => server.dispose(), attribution.enable({
32
+ log: false,
33
+ ...options.attribution
34
+ }), records.subscribe("rerun", (e, node) => painter.rerun(e, node)), records.subscribe("create", (e, node) => painter.create(e, node)), records.subscribe("effect", (e, node) => painter.effect(e, node)), records.subscribe("flush", e => painter.flush(e)), records.subscribe("flight", (e, node) => painter.flight(e, node)), records.subscribe("fallback", (e, subtree) => painter.fallback(e, subtree)), records.subscribe("interaction", e => painter.interaction(e)), records.subscribe("hold", e => painter.hold(e)), records.subscribe("navigation", e => painter.navigation(e)), records.subscribe("call", (e, live) => {
35
+ painter.call(e);
36
+ server.call(e, live);
37
+ }), records.subscribe("frame", e => painter.frame(e)), observe.diagnostics.subscribe((e, subject) => painter.diagnostic(e, subject))];
38
+ const active = {
39
+ holders: 0,
40
+ join() {
41
+ active.holders++;
42
+ let held = true;
43
+ return () => {
44
+ if (!held) return;
45
+ held = false;
46
+ if (--active.holders > 0 || instance !== active) return;
47
+ instance = null;
48
+ for (const release of releases) release();
49
+ emitter.dispose();
50
+ };
51
+ }
52
+ };
53
+ instance = active;
54
+ return active.join();
55
+ }
56
+ let instance = null;
57
+ function createEmitter(rich) {
58
+ const hasMeasure = typeof performance.measure === "function";
59
+ const hasTimeStamp = typeof console !== "undefined" && typeof console.timeStamp === "function";
60
+ let emitter;
61
+ if (rich && hasMeasure || !hasTimeStamp && hasMeasure) {
62
+ const names = new Map();
63
+ const markNames = new Map();
64
+ let pending = 0;
65
+ const clear = () => {
66
+ pending = 0;
67
+ clearOwned(names, "measure", performance.clearMeasures);
68
+ clearOwned(markNames, "mark", performance.clearMarks);
69
+ };
70
+ const hasMark = typeof performance.mark === "function";
71
+ emitter = {
72
+ rich: true,
73
+ span(label, start, end, track, color, tooltip, properties, task) {
74
+ const devtools = {
75
+ dataType: "track-entry",
76
+ track,
77
+ trackGroup: GROUP,
78
+ color
79
+ };
80
+ if (tooltip !== undefined) devtools.tooltipText = tooltip;
81
+ if (properties !== undefined) devtools.properties = properties;
82
+ const measure = () => performance.measure(label, {
83
+ start,
84
+ end,
85
+ detail: {
86
+ devtools
87
+ }
88
+ });
89
+ if (!guarded(measure, task)) return;
90
+ names.set(label, (names.get(label) ?? 0) + 1);
91
+ if (++pending >= CLEAR_EVERY) clear();
92
+ },
93
+ mark(label, color, tooltip, properties, issue, task) {
94
+ if (!hasMark) return;
95
+ const devtools = {
96
+ dataType: "marker",
97
+ color
98
+ };
99
+ if (tooltip !== undefined) devtools.tooltipText = tooltip;
100
+ if (properties !== undefined) devtools.properties = properties;
101
+ if (issue !== undefined) devtools.performanceIssue = issue;
102
+ const mark = () => performance.mark(label, {
103
+ detail: {
104
+ devtools
105
+ }
106
+ });
107
+ if (!guarded(mark, task)) return;
108
+ markNames.set(label, (markNames.get(label) ?? 0) + 1);
109
+ if (++pending >= CLEAR_EVERY) clear();
110
+ },
111
+ dispose: clear
112
+ };
113
+ } else if (hasTimeStamp) {
114
+ const timeStamp = console.timeStamp;
115
+ emitter = {
116
+ rich: false,
117
+ span(label, start, end, track, color, _tooltip, _properties, task) {
118
+ guarded(() => timeStamp(label, start, end, track, GROUP, color), task);
119
+ },
120
+ mark(label, _color, _tooltip, _properties, _issue, task) {
121
+ guarded(() => timeStamp(label), task);
122
+ },
123
+ dispose: noop
124
+ };
125
+ } else return undefined;
126
+ for (const track of Object.values(TRACKS)) {
127
+ emitter.span(track, SEED_AT, SEED_AT, track, "primary-light");
128
+ }
129
+ return emitter;
130
+ }
131
+ const SEED_AT = 0.003;
132
+ const CLEAR_EVERY = 500;
133
+ let warnedThrow = false;
134
+ function guarded(fn, task) {
135
+ try {
136
+ task !== undefined ? task.run(fn) : fn();
137
+ return true;
138
+ } catch (error) {
139
+ if (!warnedThrow) {
140
+ warnedThrow = true;
141
+ console.warn("[performance-tracks] a timeline entry could not be emitted; dropped.", error);
142
+ }
143
+ return false;
144
+ }
145
+ }
146
+ function clearOwned(owned, type, clearFn) {
147
+ if (typeof clearFn !== "function" || typeof performance.getEntriesByName !== "function") {
148
+ owned.clear();
149
+ return;
150
+ }
151
+ for (const [name, count] of owned) {
152
+ if (performance.getEntriesByName(name, type).length <= count) {
153
+ clearFn.call(performance, name);
154
+ owned.delete(name);
155
+ }
156
+ }
157
+ }
158
+ class Painter {
159
+ roots = new Set();
160
+ unchanged = 0;
161
+ names = new Map();
162
+ constructor(emit, minMs) {
163
+ this.emit = emit;
164
+ this.minMs = minMs;
165
+ this.rich = emit.rich;
166
+ }
167
+ rerun(event, subject) {
168
+ collectRoots(event.causes, this.roots);
169
+ if (!event.changed) this.unchanged++;
170
+ const node = describe(event.nodeName, OBSERVE.ownerPath(subject));
171
+ this.names.set(event.nodeId, node.short);
172
+ if (event.totalMs < this.minMs) return;
173
+ const track = event.nodeKind === "effect" ? TRACKS.effects : TRACKS.memos;
174
+ const color = event.phase === "optimistic" ? "tertiary" : !event.changed ? "warning" : bySelfTime(event.selfMs);
175
+ let tooltip;
176
+ let properties;
177
+ if (this.rich) {
178
+ tooltip = formatRerun(event);
179
+ properties = [["Run", `${event.run} (run ${event.nodeRuns} of this node)`], ["Self time", ms(event.selfMs)], ["Total time", ms(event.totalMs)], ["Changed", event.changed ? "yes" : "no — unchanged (wasted)"], ["Phase", event.phase + (event.held ? ", held" : "")], ["Deps", String(event.depCount)]];
180
+ this.identity(properties, node, event.nodeId);
181
+ if (event.depsAdded.length > 0) properties.push(["Deps added", event.depsAdded.join(", ")]);
182
+ if (event.depsRemoved.length > 0) properties.push(["Deps removed", event.depsRemoved.join(", ")]);
183
+ if (event.causes.length > 0) properties.push(["Causes", event.causes.map(rootCause).join("; ")]);
184
+ const origin = rootOrigin(event.causes);
185
+ if (origin !== undefined && origin !== event.interaction) properties.push(["Origin", this.origin(origin)]);
186
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
187
+ }
188
+ const end = event.at + event.totalMs;
189
+ const task = taskOf(subject);
190
+ this.emit.span(node.label, event.at, end, track, color, tooltip, properties, task);
191
+ this.emit.span(`${node.label} ← ${this.causeLabels(event.causes)}`, event.at, end, TRACKS.propagation, color, tooltip, properties, task);
192
+ }
193
+ create(event, subject) {
194
+ const node = describe(event.nodeName, OBSERVE.ownerPath(subject));
195
+ this.names.set(event.nodeId, node.short);
196
+ if (event.totalMs < this.minMs) return;
197
+ let properties;
198
+ if (this.rich) {
199
+ properties = [["Self time", ms(event.selfMs)], ["Total time", ms(event.totalMs)], ["Phase", event.phase + (event.held ? ", held" : "")], ["Deps", String(event.depCount)]];
200
+ this.identity(properties, node, event.nodeId);
201
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
202
+ }
203
+ const label = `${node.label} · create`;
204
+ const end = event.at + event.totalMs;
205
+ const color = event.phase === "optimistic" ? "tertiary" : bySelfTime(event.selfMs);
206
+ const task = taskOf(subject);
207
+ this.emit.span(label, event.at, end, event.nodeKind === "effect" ? TRACKS.effects : TRACKS.memos, color, undefined, properties, task);
208
+ this.emit.span(label, event.at, end, TRACKS.propagation, color, undefined, properties, task);
209
+ }
210
+ effect(event, subject) {
211
+ if (event.durationMs < this.minMs) return;
212
+ const node = describe(event.nodeName, OBSERVE.ownerPath(subject));
213
+ let properties;
214
+ if (this.rich) {
215
+ properties = [["Duration", ms(event.durationMs)]];
216
+ this.identity(properties, node, event.nodeId);
217
+ if (event.run !== undefined) properties.push(["Run", String(event.run)]);
218
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
219
+ }
220
+ const label = `${node.label} · callback`;
221
+ const end = event.at + event.durationMs;
222
+ const color = event.durationMs < 10 ? "secondary-light" : event.durationMs < 100 ? "secondary" : "error";
223
+ const task = taskOf(subject);
224
+ this.emit.span(label, event.at, end, TRACKS.effects, color, undefined, properties, task);
225
+ this.emit.span(label, event.at, end, TRACKS.propagation, color, undefined, properties, task);
226
+ }
227
+ diagnostic(event, subject) {
228
+ const owner = event.ownerPath?.join(" › ");
229
+ const label = event.ownerPath !== undefined ? `${event.code} — ${nearest(event.ownerPath).join(" › ")}` : event.code;
230
+ const color = event.severity === "error" ? "error" : event.severity === "warn" ? "warning" : "primary-light";
231
+ let tooltip;
232
+ let properties;
233
+ let issue;
234
+ if (this.rich) {
235
+ tooltip = event.message;
236
+ properties = [["Code", event.code], ["Kind", event.kind], ["Severity", event.severity]];
237
+ if (owner !== undefined) properties.push(["Owner path", owner]);
238
+ if (event.nodeName !== undefined) properties.push(["Node", event.nodeName]);
239
+ properties.push(["Message", event.message]);
240
+ if (event.data !== undefined) {
241
+ for (const [key, value] of Object.entries(event.data)) {
242
+ if (typeof value === "number") properties.push([key, Number.isInteger(value) ? String(value) : value.toFixed(2)]);else if (typeof value === "string" || typeof value === "boolean") properties.push([key, String(value)]);
243
+ }
244
+ }
245
+ const guide = DEV.guideUrl(event.code) ;
246
+ if (guide) properties.push(["Guide", guide]);
247
+ if (event.severity !== "info") {
248
+ issue = {
249
+ name: `Solid: ${event.code}`,
250
+ severity: event.severity === "error" ? "error" : "warning",
251
+ description: tooltip,
252
+ learnMoreUrl: guide
253
+ };
254
+ }
255
+ }
256
+ this.emit.mark(label, color, tooltip, properties, issue, taskOf(subject));
257
+ }
258
+ identity(properties, node, nodeId) {
259
+ if (node.path !== undefined) properties.push(["Owner path", node.path]);
260
+ if (node.internal !== undefined) properties.push(["Node", node.internal]);
261
+ properties.push(["Node id", String(nodeId)]);
262
+ }
263
+ flush(event) {
264
+ const roots = [...this.roots];
265
+ const unchanged = this.unchanged;
266
+ this.roots.clear();
267
+ this.unchanged = 0;
268
+ this.names.clear();
269
+ let label = roots.length > 0 ? this.writes(roots, 3) : "flush";
270
+ const origin = event.interaction ?? roots.map(r => r.origin).find(o => o !== undefined && o.kind !== "external");
271
+ if (origin !== undefined) label += ` — ${this.origin(origin)}`;
272
+ label += ` · ${event.runs} ${event.runs === 1 ? "run" : "runs"}`;
273
+ if (unchanged > 0) label += `, ${unchanged} unchanged`;
274
+ if (event.created > 0) label += `, ${event.created} created`;
275
+ if (event.held) label += " · held";
276
+ let properties;
277
+ if (this.rich) {
278
+ properties = [["Duration", ms(event.durationMs)], ["Writes", roots.length > 0 ? this.writes(roots, Infinity) : "none"], ["Re-runs", String(event.runs)], ["Unchanged", `${unchanged} (wasted)`], ["Created", String(event.created)], ["Held", event.held ? "yes — a transition parked" : "no"]];
279
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
280
+ }
281
+ this.emit.span(label, event.at, event.at + event.durationMs, TRACKS.propagation, event.held ? "tertiary" : unchanged > 0 && unchanged * 2 >= event.runs ? "warning" : event.durationMs < 16 ? "primary" : "primary-dark", undefined, properties);
282
+ }
283
+ flight(event, subject) {
284
+ const node = describe(event.nodeName, event.ownerPath);
285
+ let properties;
286
+ if (this.rich) {
287
+ properties = [["In the air", ms(event.durationMs)], ["Outcome", event.outcome]];
288
+ if (node.path !== undefined) properties.push(["Owner path", node.path]);
289
+ if (node.internal !== undefined) properties.push(["Node", node.internal]);
290
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
291
+ }
292
+ this.emit.span(`${node.label}${event.outcome === "abandoned" ? " · abandoned" : ""}`, event.at, event.at + event.durationMs, TRACKS.async, event.outcome === "abandoned" ? "warning" : "secondary", undefined, properties, taskOf(subject));
293
+ }
294
+ fallback(event, subject) {
295
+ const path = event.ownerPath;
296
+ const label = `fallback${path !== undefined ? ` ${nearest(path).join(" › ")}` : ""}`;
297
+ let properties;
298
+ if (this.rich) {
299
+ properties = [["Shown", ms(event.shownMs)]];
300
+ if (path !== undefined && nearest(path).length !== path.length) properties.push(["Owner path", path.join(" › ")]);
301
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
302
+ }
303
+ this.emit.span(label, event.at, event.at + event.shownMs, TRACKS.async, "tertiary", undefined, properties, taskOf(subject));
304
+ }
305
+ interaction(event) {
306
+ const label = this.origin(event.origin);
307
+ const handlerStart = event.at + (event.inputDelayMs ?? 0);
308
+ const handlerEnd = handlerStart + event.handlerMs;
309
+ let properties;
310
+ if (this.rich) {
311
+ properties = [["Handler", ms(event.handlerMs)], ["Writes", String(event.writes)], ["Re-runs", `${event.runs} (${ms(event.runMs)} self time)`], ["Created", String(event.created)]];
312
+ if (event.inputDelayMs !== undefined) properties.unshift(["Input delay", ms(event.inputDelayMs)]);
313
+ if (event.settledMs !== undefined) properties.push(["Settled", ms(event.settledMs)]);
314
+ if (event.outcome !== undefined) properties.push(["Outcome", event.outcome]);
315
+ if (event.holds.length > 0) properties.push(["Holds", String(event.holds.length)]);
316
+ if (event.navigations.length > 0) properties.push(["Navigations", event.navigations.map(n => this.origin(n.origin)).join("; ")]);
317
+ }
318
+ if (event.inputDelayMs !== undefined && event.inputDelayMs > 0) {
319
+ this.emit.span("input delay", event.at, handlerStart, TRACKS.interactions, "primary-light");
320
+ }
321
+ this.emit.span(label, handlerStart, handlerEnd, TRACKS.interactions, "primary", undefined, properties);
322
+ const outcome = event.outcome;
323
+ if (event.settledMs === undefined || outcome === undefined || outcome === "idle") return;
324
+ const settleEnd = event.at + event.settledMs;
325
+ if (settleEnd <= handlerEnd) return;
326
+ const silent = outcome === "held" && event.holds.some(h => h.silent);
327
+ this.emit.span(outcome, handlerEnd, settleEnd, TRACKS.interactions, silent ? "warning" : outcome === "held" ? "tertiary" : "secondary-light", undefined, this.rich ? [["Settled", ms(event.settledMs)]] : undefined);
328
+ }
329
+ hold(event) {
330
+ const {
331
+ long,
332
+ silent
333
+ } = event;
334
+ const what = event.blockers.length > 0 ? event.blockers.join(", ") : "a transition";
335
+ const label = event.origin !== undefined ? `${this.origin(event.origin)} — waiting on ${what}` : `waiting on ${what}`;
336
+ let properties;
337
+ if (this.rich) {
338
+ properties = [["Held", ms(event.holdMs)], ["Tail", `${ms(event.tailMs)} (last write → commit)`], ["Flushes", String(event.flushes)], ["Held writes", event.heldWrites.map(heldWrite).join(", ") || "none"], ["Acknowledged by", event.acknowledgements.map(a => `${a.kind}(${a.source})`).join(", ") || "nothing"], ["Painted during hold", String(event.paintedDuringHold)]];
339
+ if (silent) properties.push(["Verdict", "silent hold — no feedback while waiting"]);
340
+ if (long) properties.push(["Verdict", "long hold"]);
341
+ if (event.action) properties.push(["Action", "yes"]);
342
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
343
+ }
344
+ this.emit.span(label, event.at, event.at + event.holdMs, TRACKS.holds, long ? "error" : silent ? "warning" : "tertiary", undefined, properties);
345
+ }
346
+ navigation(event) {
347
+ if (event.settledMs === undefined) return;
348
+ let properties;
349
+ if (this.rich) {
350
+ properties = [["Settled", ms(event.settledMs)], ["Writes", String(event.writes)]];
351
+ if (event.to !== undefined) properties.push(["To", event.to]);
352
+ if (event.from !== undefined) properties.push(["From", event.from]);
353
+ if (event.params !== undefined) {
354
+ const params = Object.entries(event.params).filter(([, v]) => v !== undefined).map(([k, v]) => `${k}=${v}`).join(", ");
355
+ if (params) properties.push(["Params", params]);
356
+ }
357
+ if (event.redirects !== undefined) properties.push(["Redirected from", event.redirects.map(hop => hop.to ?? hop.name ?? "?").join(" → ")]);
358
+ if (event.outcome !== undefined) properties.push(["Outcome", event.outcome]);
359
+ if (event.interaction !== undefined) properties.push(["Interaction", this.origin(event.interaction)]);
360
+ }
361
+ this.emit.span(formatOrigin(event.origin), event.at, event.at + event.settledMs, TRACKS.navigations, event.outcome === "superseded" ? "secondary-light" : event.outcome === "held" ? "tertiary" : "secondary", undefined, properties);
362
+ }
363
+ call(event) {
364
+ let label = `${event.method} ${event.id}`;
365
+ if (event.status !== undefined) label += ` · ${event.status}`;
366
+ let properties;
367
+ if (this.rich) {
368
+ properties = [["Duration", ms(event.durationMs)], ["Outcome", event.outcome]];
369
+ if (event.status !== undefined) properties.push(["Status", String(event.status)]);
370
+ if (event.deferred) properties.push(["Deferred", "the body is consumed by the caller"]);
371
+ if (event.origin !== undefined) properties.push(["Origin", this.origin(event.origin)]);
372
+ }
373
+ this.emit.span(label, event.at, event.at + event.durationMs, TRACKS.server, event.outcome === "error" ? "error" : "secondary", undefined, properties);
374
+ }
375
+ frame(event) {
376
+ if (event.side !== "client") return;
377
+ const label = `frame ${event.id || "(unnamed)"}`;
378
+ let properties;
379
+ if (this.rich) {
380
+ properties = [["Duration", ms(event.durationMs)], ["Outcome", event.outcome], ["Chunks", String(event.chunks)], ["Fragments", String(event.fragments)], ["Slots", String(event.slots)], ["Regions", String(event.regions)], ["Errors", String(event.errors)], ["Version", String(event.version)]];
381
+ if (event.shellMs !== undefined) properties.splice(1, 0, ["Shell", ms(event.shellMs)]);
382
+ if (event.address !== undefined) properties.push(["Applied as", event.address]);
383
+ }
384
+ if (event.shellMs !== undefined && event.shellMs > 0) {
385
+ this.emit.span(`${label} · shell`, event.at, event.at + event.shellMs, TRACKS.server, "secondary-light");
386
+ }
387
+ this.emit.span(label, event.at, event.at + event.durationMs, TRACKS.server, event.outcome === "complete" ? "secondary" : "error", undefined, properties);
388
+ }
389
+ causeLabels(causes) {
390
+ const labels = new Set();
391
+ for (const c of causes) {
392
+ const name = (c.kind === "derived" && c.nodeId !== undefined ? this.names.get(c.nodeId) : undefined) ?? c.name;
393
+ labels.add(c.kind === "async" ? `${name} landed` : c.kind === "refresh" ? `refresh ${name}` : name);
394
+ }
395
+ return [...labels].join(", ");
396
+ }
397
+ writes(roots, limit) {
398
+ const shown = roots.slice(0, limit).map(r => {
399
+ let out = r.kind === "async" ? `${r.name} landed` : r.kind === "refresh" ? `refresh ${r.name}` : r.name;
400
+ if (r.prev !== undefined) out += ` ${r.prev} → ${r.value}`;
401
+ return out;
402
+ });
403
+ if (roots.length > limit) shown.push(`+${roots.length - limit} more`);
404
+ return shown.join(", ");
405
+ }
406
+ origin(origin) {
407
+ return formatOrigin(origin);
408
+ }
409
+ }
410
+ const FLOW_INTERNALS = {
411
+ "<Show>": new Set(["condition value", "condition", "value"]),
412
+ "<Switch>": new Set(["children", "conditions", "condition value", "condition", "eval conditions"]),
413
+ "<Loading>": new Set(["children", "boundary", "value"]),
414
+ "<Errored>": new Set(["children", "boundary", "value"]),
415
+ "<Reveal>": new Set(["reveal order"])
416
+ };
417
+ const FLOW_TAGS = new Set(["<Show>", "<For>", "<Repeat>", "<Switch>", "<Match>", "<Errored>", "<Loading>", "<Reveal>", "<Portal>", "<Dynamic>"]);
418
+ function nearest(segments) {
419
+ for (let i = segments.length - 1; i > 0; i--) {
420
+ const s = segments[i];
421
+ if (s.charCodeAt(0) === 60 && !FLOW_TAGS.has(s)) return segments.slice(i);
422
+ }
423
+ return segments;
424
+ }
425
+ function describe(nodeName, path) {
426
+ const full = path === undefined ? [nodeName] : path[path.length - 1] === nodeName ? path : [...path, nodeName];
427
+ const segments = [];
428
+ let flow;
429
+ let internal;
430
+ for (let i = 0; i < full.length; i++) {
431
+ const name = full[i];
432
+ let shown;
433
+ if (flow !== undefined && flow.has(name)) {
434
+ internal = name;
435
+ } else {
436
+ flow = FLOW_INTERNALS[name];
437
+ const dot = name.indexOf(".");
438
+ if (dot > 0 && name.charCodeAt(0) !== 60 ) {
439
+ shown = name.slice(0, dot);
440
+ internal = name.slice(dot + 1);
441
+ } else {
442
+ shown = name;
443
+ internal = undefined;
444
+ }
445
+ }
446
+ if (shown !== undefined && shown !== segments[segments.length - 1]) segments.push(shown);
447
+ }
448
+ const short = segments[segments.length - 1];
449
+ const label = nearest(segments).join(" › ");
450
+ const described = {
451
+ label,
452
+ short
453
+ };
454
+ if (internal !== undefined) described.internal = internal;
455
+ const runtimePath = full.join(" › ");
456
+ if (runtimePath !== label) described.path = runtimePath;
457
+ return described;
458
+ }
459
+ function taskOf(subject) {
460
+ if (!subject) return undefined;
461
+ let owner = "_parent" in subject ? subject : subject._owner;
462
+ for (; owner != null; owner = owner._parent) {
463
+ const task = owner._component?.task;
464
+ if (task !== undefined) return task;
465
+ }
466
+ return undefined;
467
+ }
468
+ function rootOrigin(causes) {
469
+ for (const c of causes) {
470
+ let root = c;
471
+ while (root.causes !== undefined && root.causes.length > 0) root = root.causes[0];
472
+ if (root.origin !== undefined && root.origin.kind !== "external") return root.origin;
473
+ }
474
+ return undefined;
475
+ }
476
+ function collectRoots(causes, out) {
477
+ for (const c of causes) {
478
+ if (c.kind === "derived") {
479
+ if (c.causes !== undefined) collectRoots(c.causes, out);
480
+ } else out.add(c);
481
+ }
482
+ }
483
+ function bySelfTime(selfMs) {
484
+ return selfMs < 0.5 ? "primary-light" : selfMs < 10 ? "primary" : selfMs < 100 ? "primary-dark" : "error";
485
+ }
486
+ const SOLID_METRIC = /^solid-(invocation|shell|boundary)$/;
487
+ const PENDING_MS = 30_000;
488
+ class ServerSpans {
489
+ pending = [];
490
+ constructor(emit) {
491
+ this.emit = emit;
492
+ }
493
+ start() {
494
+ this.navigation();
495
+ if (typeof PerformanceObserver !== "function") return;
496
+ try {
497
+ const observer = new PerformanceObserver(list => this.resources(list.getEntries()));
498
+ observer.observe({
499
+ type: "resource",
500
+ buffered: true
501
+ });
502
+ this.observer = observer;
503
+ } catch {
504
+ this.observer = undefined;
505
+ }
506
+ }
507
+ dispose() {
508
+ if (this.observer !== undefined) this.observer.disconnect();
509
+ this.observer = undefined;
510
+ this.pending.length = 0;
511
+ }
512
+ call(event, live) {
513
+ const response = live.response;
514
+ if (response === undefined) return;
515
+ let header;
516
+ try {
517
+ header = response.headers.get("server-timing");
518
+ } catch {
519
+ return;
520
+ }
521
+ if (!header) return;
522
+ const metrics = parseServerTiming(header).filter(m => SOLID_METRIC.test(m.name));
523
+ if (metrics.length === 0) return;
524
+ if (this.observer === undefined) {
525
+ this.paint(metrics, event, undefined);
526
+ return;
527
+ }
528
+ if (typeof performance.getEntriesByName === "function") {
529
+ const entry = findResource(performance.getEntriesByName(response.url, "resource"), event);
530
+ if (entry !== undefined) {
531
+ this.paint(metrics, event, entry);
532
+ return;
533
+ }
534
+ }
535
+ this.pending.push({
536
+ event,
537
+ url: response.url,
538
+ metrics,
539
+ expires: performance.now() + PENDING_MS
540
+ });
541
+ }
542
+ resources(entries) {
543
+ const pending = this.pending;
544
+ if (pending.length === 0) return;
545
+ const now = performance.now();
546
+ for (let i = pending.length - 1; i >= 0; i--) {
547
+ const call = pending[i];
548
+ if (call.expires <= now) {
549
+ pending.splice(i, 1);
550
+ continue;
551
+ }
552
+ const entry = findResource(entries.filter(e => e.name === call.url), call.event);
553
+ if (entry === undefined) continue;
554
+ pending.splice(i, 1);
555
+ this.paint(call.metrics, call.event, entry);
556
+ }
557
+ }
558
+ navigation() {
559
+ if (typeof performance.getEntriesByType !== "function") return;
560
+ const [nav] = performance.getEntriesByType("navigation");
561
+ if (nav === undefined || !Array.isArray(nav.serverTiming) || !(nav.responseStart > 0)) return;
562
+ const end = nav.responseStart;
563
+ const rich = this.emit.rich;
564
+ for (const metric of nav.serverTiming) {
565
+ if (!SOLID_METRIC.test(metric.name)) continue;
566
+ const kind = metric.name.slice(6);
567
+ const path = kind === "boundary" ? metric.description.split(" > ") : undefined;
568
+ const label = kind === "shell" ? "shell · server" : path !== undefined ? `boundary ${nearest(path).join(" › ")} · server` : `${metric.description} · server`;
569
+ let properties;
570
+ if (rich) {
571
+ properties = [["Duration", ms(metric.duration)], ["Source", "Server-Timing on the document"], ["Placement", kind === "shell" ? "ends at responseStart — the head left when the shell was ready" : "ends with the shell — settled at or before the flush"]];
572
+ if (path !== undefined && nearest(path).length !== path.length) properties.push(["Owner path", path.join(" › ")]);
573
+ }
574
+ this.emit.span(label, end - metric.duration, end, TRACKS.server, kind === "shell" ? "tertiary" : "tertiary-light", undefined, properties);
575
+ }
576
+ }
577
+ paint(metrics, event, entry) {
578
+ const rich = this.emit.rich;
579
+ const end = entry !== undefined && entry.responseStart > 0 ? entry.responseStart : undefined;
580
+ const mid = event.at + event.durationMs / 2;
581
+ for (const metric of metrics) {
582
+ const start = end !== undefined ? end - metric.duration : mid - metric.duration / 2;
583
+ const stop = end !== undefined ? end : mid + metric.duration / 2;
584
+ const label = `${metric.description || event.id} · server`;
585
+ let properties;
586
+ if (rich) {
587
+ properties = [["Duration", ms(metric.duration)], ["Wire", ms(Math.max(0, event.durationMs - metric.duration))], ["Source", "Server-Timing"], ["Placement", end !== undefined ? "ends at the response's responseStart" : "centred in the call — no resource timing for this fetch"]];
588
+ }
589
+ this.emit.span(label, start, stop, TRACKS.server, "tertiary", undefined, properties);
590
+ }
591
+ }
592
+ }
593
+ function findResource(entries, event) {
594
+ const from = event.at - 1;
595
+ const to = event.at + event.durationMs + 1;
596
+ for (const entry of entries) {
597
+ if (entry.startTime >= from && entry.startTime <= to) {
598
+ return entry;
599
+ }
600
+ }
601
+ return undefined;
602
+ }
603
+ function parseServerTiming(value) {
604
+ const out = [];
605
+ let start = 0;
606
+ let quoted = false;
607
+ const take = end => {
608
+ const entry = value.slice(start, end).trim();
609
+ if (entry === "") return;
610
+ const parts = splitParams(entry);
611
+ const name = parts[0].trim().toLowerCase();
612
+ if (name === "") return;
613
+ let duration;
614
+ let description = "";
615
+ for (let i = 1; i < parts.length; i++) {
616
+ const eq = parts[i].indexOf("=");
617
+ if (eq === -1) continue;
618
+ const key = parts[i].slice(0, eq).trim().toLowerCase();
619
+ const raw = parts[i].slice(eq + 1).trim();
620
+ if (key === "dur") duration = Number(raw);else if (key === "desc") description = unquote(raw);
621
+ }
622
+ if (duration === undefined || !(duration >= 0)) return;
623
+ out.push({
624
+ name,
625
+ duration,
626
+ description
627
+ });
628
+ };
629
+ for (let i = 0; i < value.length; i++) {
630
+ const c = value[i];
631
+ if (quoted) {
632
+ if (c === "\\") i++;else if (c === '"') quoted = false;
633
+ } else if (c === '"') quoted = true;else if (c === ",") {
634
+ take(i);
635
+ start = i + 1;
636
+ }
637
+ }
638
+ take(value.length);
639
+ return out;
640
+ }
641
+ function splitParams(entry) {
642
+ const parts = [];
643
+ let start = 0;
644
+ let quoted = false;
645
+ for (let i = 0; i < entry.length; i++) {
646
+ const c = entry[i];
647
+ if (quoted) {
648
+ if (c === "\\") i++;else if (c === '"') quoted = false;
649
+ } else if (c === '"') quoted = true;else if (c === ";") {
650
+ parts.push(entry.slice(start, i));
651
+ start = i + 1;
652
+ }
653
+ }
654
+ parts.push(entry.slice(start));
655
+ return parts;
656
+ }
657
+ function unquote(raw) {
658
+ if (raw.length >= 2 && raw[0] === '"' && raw[raw.length - 1] === '"') {
659
+ return raw.slice(1, -1).replace(/\\(.)/g, "$1");
660
+ }
661
+ return raw;
662
+ }
663
+ function ms(value) {
664
+ return `${value.toFixed(2)}ms`;
665
+ }
666
+ function rootCause(cause) {
667
+ let root = cause;
668
+ while (root.causes !== undefined && root.causes.length > 0) root = root.causes[0];
669
+ let out = `${root.kind === "derived" ? "memo" : "signal"} "${root.name}" ${root.kind}`;
670
+ if (root.prev !== undefined) out += ` ${root.prev} → ${root.value}`;
671
+ if (root.origin !== undefined && root.origin.kind !== "external") out += ` — ${formatOrigin(root.origin)}`;
672
+ return out;
673
+ }
674
+ function heldWrite(write) {
675
+ return write.prev === undefined ? write.name : `${write.name} ${write.prev} → ${write.value}`;
676
+ }
677
+
678
+ export { enablePerformanceTracks };
@@ -0,0 +1,6 @@
1
+ const noop = () => {};
2
+ function enablePerformanceTracks(options = {}) {
3
+ return noop;
4
+ }
5
+
6
+ export { enablePerformanceTracks };