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

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