@getlimelight/sdk 0.1.4 → 0.2.0
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.
- package/dist/index.d.mts +84 -3
- package/dist/index.d.ts +84 -3
- package/dist/index.js +616 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +616 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -6
package/dist/index.mjs
CHANGED
|
@@ -221,7 +221,20 @@ var SENSITIVE_HEADERS = [
|
|
|
221
221
|
];
|
|
222
222
|
var DEFAULT_PORT = 9090;
|
|
223
223
|
var WS_PATH = "/limelight";
|
|
224
|
-
var SDK_VERSION = true ? "0.
|
|
224
|
+
var SDK_VERSION = true ? "0.2.0" : "test-version";
|
|
225
|
+
var RENDER_THRESHOLDS = {
|
|
226
|
+
HOT_VELOCITY: 5,
|
|
227
|
+
HIGH_RENDER_COUNT: 50,
|
|
228
|
+
VELOCITY_WINDOW_MS: 2e3,
|
|
229
|
+
SNAPSHOT_INTERVAL_MS: 1e3,
|
|
230
|
+
MIN_DELTA_TO_EMIT: 1,
|
|
231
|
+
MAX_PROP_KEYS_TO_TRACK: 20,
|
|
232
|
+
// Don't track more than this many unique props
|
|
233
|
+
MAX_PROP_CHANGES_PER_SNAPSHOT: 10,
|
|
234
|
+
// Limit delta array size
|
|
235
|
+
TOP_PROPS_TO_REPORT: 5
|
|
236
|
+
// Only report top N changed props
|
|
237
|
+
};
|
|
225
238
|
|
|
226
239
|
// src/helpers/safety/redactSensitiveHeaders.ts
|
|
227
240
|
var redactSensitiveHeaders = (headers) => {
|
|
@@ -401,6 +414,42 @@ var formatRequestName = (url) => {
|
|
|
401
414
|
}
|
|
402
415
|
};
|
|
403
416
|
|
|
417
|
+
// src/helpers/render/generateRenderId.ts
|
|
418
|
+
var counter = 0;
|
|
419
|
+
var generateRenderId = () => {
|
|
420
|
+
const timestamp = Date.now().toString(36);
|
|
421
|
+
const count = (counter++).toString(36);
|
|
422
|
+
const random = Math.random().toString(36).substring(2, 6);
|
|
423
|
+
if (counter > 1e3) counter = 0;
|
|
424
|
+
return `${timestamp}${count}-${random}`;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// src/helpers/render/createEmptyCauseBreakdown.ts
|
|
428
|
+
var createEmptyCauseBreakdown = () => {
|
|
429
|
+
return {
|
|
430
|
+
["state_change" /* STATE_CHANGE */]: 0,
|
|
431
|
+
["props_change" /* PROPS_CHANGE */]: 0,
|
|
432
|
+
["context_change" /* CONTEXT_CHANGE */]: 0,
|
|
433
|
+
["parent_render" /* PARENT_RENDER */]: 0,
|
|
434
|
+
["force_update" /* FORCE_UPDATE */]: 0,
|
|
435
|
+
["unknown" /* UNKNOWN */]: 0
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// src/helpers/render/createEmptyPropChangeStats.ts
|
|
440
|
+
var createEmptyPropChangeStats = () => {
|
|
441
|
+
return {
|
|
442
|
+
changeCount: /* @__PURE__ */ new Map(),
|
|
443
|
+
referenceOnlyCount: /* @__PURE__ */ new Map()
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/helpers/render/getCurrentTransactionId.ts
|
|
448
|
+
var globalGetTransactionId = null;
|
|
449
|
+
var getCurrentTransactionId = () => {
|
|
450
|
+
return globalGetTransactionId?.() ?? null;
|
|
451
|
+
};
|
|
452
|
+
|
|
404
453
|
// src/limelight/interceptors/ConsoleInterceptor.ts
|
|
405
454
|
var ConsoleInterceptor = class {
|
|
406
455
|
constructor(sendMessage, getSessionId) {
|
|
@@ -953,6 +1002,561 @@ var XHRInterceptor = class {
|
|
|
953
1002
|
}
|
|
954
1003
|
};
|
|
955
1004
|
|
|
1005
|
+
// src/limelight/interceptors/RenderInterceptor.ts
|
|
1006
|
+
var RenderInterceptor = class {
|
|
1007
|
+
sendMessage;
|
|
1008
|
+
getSessionId;
|
|
1009
|
+
config = null;
|
|
1010
|
+
isSetup = false;
|
|
1011
|
+
profiles = /* @__PURE__ */ new Map();
|
|
1012
|
+
fiberToComponentId = /* @__PURE__ */ new WeakMap();
|
|
1013
|
+
componentIdCounter = 0;
|
|
1014
|
+
snapshotTimer = null;
|
|
1015
|
+
currentCommitComponents = /* @__PURE__ */ new Set();
|
|
1016
|
+
componentsInCurrentCommit = 0;
|
|
1017
|
+
originalHook = null;
|
|
1018
|
+
originalOnCommitFiberRoot = null;
|
|
1019
|
+
originalOnCommitFiberUnmount = null;
|
|
1020
|
+
pendingUnmounts = [];
|
|
1021
|
+
constructor(sendMessage, getSessionId) {
|
|
1022
|
+
this.sendMessage = sendMessage;
|
|
1023
|
+
this.getSessionId = getSessionId;
|
|
1024
|
+
}
|
|
1025
|
+
setup(config) {
|
|
1026
|
+
if (this.isSetup) {
|
|
1027
|
+
console.warn("[Limelight] Render interceptor already set up");
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
this.config = config;
|
|
1031
|
+
if (!this.installHook()) {
|
|
1032
|
+
console.warn("[Limelight] Failed to install render hook");
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
this.snapshotTimer = setInterval(() => {
|
|
1036
|
+
this.emitSnapshot();
|
|
1037
|
+
}, RENDER_THRESHOLDS.SNAPSHOT_INTERVAL_MS);
|
|
1038
|
+
this.isSetup = true;
|
|
1039
|
+
}
|
|
1040
|
+
installHook() {
|
|
1041
|
+
const globalObj = typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : null;
|
|
1042
|
+
if (!globalObj) return false;
|
|
1043
|
+
const hookKey = "__REACT_DEVTOOLS_GLOBAL_HOOK__";
|
|
1044
|
+
const existingHook = globalObj[hookKey];
|
|
1045
|
+
if (existingHook) {
|
|
1046
|
+
this.wrapExistingHook(existingHook);
|
|
1047
|
+
} else {
|
|
1048
|
+
this.createHook(globalObj, hookKey);
|
|
1049
|
+
}
|
|
1050
|
+
return true;
|
|
1051
|
+
}
|
|
1052
|
+
wrapExistingHook(hook) {
|
|
1053
|
+
this.originalHook = hook;
|
|
1054
|
+
this.originalOnCommitFiberRoot = hook.onCommitFiberRoot?.bind(hook);
|
|
1055
|
+
this.originalOnCommitFiberUnmount = hook.onCommitFiberUnmount?.bind(hook);
|
|
1056
|
+
hook.onCommitFiberRoot = (rendererID, root, priorityLevel) => {
|
|
1057
|
+
this.originalOnCommitFiberRoot?.(rendererID, root, priorityLevel);
|
|
1058
|
+
this.handleCommitFiberRoot(rendererID, root);
|
|
1059
|
+
};
|
|
1060
|
+
hook.onCommitFiberUnmount = (rendererID, fiber) => {
|
|
1061
|
+
this.originalOnCommitFiberUnmount?.(rendererID, fiber);
|
|
1062
|
+
this.handleCommitFiberUnmount(rendererID, fiber);
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
createHook(globalObj, hookKey) {
|
|
1066
|
+
const renderers = /* @__PURE__ */ new Map();
|
|
1067
|
+
let rendererIdCounter = 0;
|
|
1068
|
+
const hook = {
|
|
1069
|
+
supportsFiber: true,
|
|
1070
|
+
inject: (renderer) => {
|
|
1071
|
+
const id = ++rendererIdCounter;
|
|
1072
|
+
renderers.set(id, renderer);
|
|
1073
|
+
return id;
|
|
1074
|
+
},
|
|
1075
|
+
onCommitFiberRoot: (rendererID, root, priorityLevel) => {
|
|
1076
|
+
this.handleCommitFiberRoot(rendererID, root);
|
|
1077
|
+
},
|
|
1078
|
+
onCommitFiberUnmount: (rendererID, fiber) => {
|
|
1079
|
+
this.handleCommitFiberUnmount(rendererID, fiber);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
globalObj[hookKey] = hook;
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Handles a fiber root commit - walks tree and ACCUMULATES into profiles.
|
|
1086
|
+
* Two-pass: first count components, then accumulate with distributed cost.
|
|
1087
|
+
*/
|
|
1088
|
+
handleCommitFiberRoot(_rendererID, root) {
|
|
1089
|
+
this.currentCommitComponents.clear();
|
|
1090
|
+
this.componentsInCurrentCommit = 0;
|
|
1091
|
+
try {
|
|
1092
|
+
this.countRenderedComponents(root.current);
|
|
1093
|
+
this.walkFiberTree(root.current, null, 0);
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
if (isDevelopment()) {
|
|
1096
|
+
console.warn("[Limelight] Error processing fiber tree:", error);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* First pass: count rendered components for cost distribution.
|
|
1102
|
+
*/
|
|
1103
|
+
countRenderedComponents(fiber) {
|
|
1104
|
+
if (!fiber) return;
|
|
1105
|
+
if (this.isUserComponent(fiber) && this.didFiberRender(fiber)) {
|
|
1106
|
+
this.componentsInCurrentCommit++;
|
|
1107
|
+
}
|
|
1108
|
+
this.countRenderedComponents(fiber.child);
|
|
1109
|
+
this.countRenderedComponents(fiber.sibling);
|
|
1110
|
+
}
|
|
1111
|
+
handleCommitFiberUnmount(_rendererID, fiber) {
|
|
1112
|
+
if (!this.isUserComponent(fiber)) return;
|
|
1113
|
+
const componentId = this.fiberToComponentId.get(fiber);
|
|
1114
|
+
if (!componentId) return;
|
|
1115
|
+
const profile = this.profiles.get(componentId);
|
|
1116
|
+
if (profile) {
|
|
1117
|
+
profile.unmountedAt = Date.now();
|
|
1118
|
+
this.pendingUnmounts.push(profile);
|
|
1119
|
+
this.profiles.delete(componentId);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* Walks fiber tree and accumulates render stats into profiles.
|
|
1124
|
+
*/
|
|
1125
|
+
walkFiberTree(fiber, parentComponentId, depth) {
|
|
1126
|
+
if (!fiber) return;
|
|
1127
|
+
if (this.isUserComponent(fiber) && this.didFiberRender(fiber)) {
|
|
1128
|
+
const componentId = this.getOrCreateComponentId(fiber);
|
|
1129
|
+
this.accumulateRender(fiber, componentId, parentComponentId, depth);
|
|
1130
|
+
this.currentCommitComponents.add(componentId);
|
|
1131
|
+
parentComponentId = componentId;
|
|
1132
|
+
}
|
|
1133
|
+
this.walkFiberTree(fiber.child, parentComponentId, depth + 1);
|
|
1134
|
+
this.walkFiberTree(fiber.sibling, parentComponentId, depth);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Core accumulation logic - this is where we build up the profile.
|
|
1138
|
+
*/
|
|
1139
|
+
accumulateRender(fiber, componentId, parentComponentId, depth) {
|
|
1140
|
+
const now = Date.now();
|
|
1141
|
+
const cause = this.inferRenderCause(fiber, parentComponentId);
|
|
1142
|
+
const renderCost = this.componentsInCurrentCommit > 0 ? 1 / this.componentsInCurrentCommit : 1;
|
|
1143
|
+
let profile = this.profiles.get(componentId);
|
|
1144
|
+
if (!profile) {
|
|
1145
|
+
profile = {
|
|
1146
|
+
id: generateRenderId(),
|
|
1147
|
+
componentId,
|
|
1148
|
+
componentName: this.getComponentName(fiber),
|
|
1149
|
+
componentType: this.getComponentType(fiber),
|
|
1150
|
+
mountedAt: now,
|
|
1151
|
+
totalRenders: 0,
|
|
1152
|
+
totalRenderCost: 0,
|
|
1153
|
+
velocityWindowStart: now,
|
|
1154
|
+
velocityWindowCount: 0,
|
|
1155
|
+
causeBreakdown: createEmptyCauseBreakdown(),
|
|
1156
|
+
causeDeltaBreakdown: createEmptyCauseBreakdown(),
|
|
1157
|
+
lastEmittedRenderCount: 0,
|
|
1158
|
+
lastEmittedRenderCost: 0,
|
|
1159
|
+
lastEmitTime: now,
|
|
1160
|
+
parentCounts: /* @__PURE__ */ new Map(),
|
|
1161
|
+
depth,
|
|
1162
|
+
isSuspicious: false,
|
|
1163
|
+
// NEW
|
|
1164
|
+
propChangeStats: createEmptyPropChangeStats(),
|
|
1165
|
+
propChangeDelta: []
|
|
1166
|
+
};
|
|
1167
|
+
this.profiles.set(componentId, profile);
|
|
1168
|
+
}
|
|
1169
|
+
profile.totalRenders++;
|
|
1170
|
+
profile.totalRenderCost += renderCost;
|
|
1171
|
+
profile.causeBreakdown[cause.type]++;
|
|
1172
|
+
profile.causeDeltaBreakdown[cause.type]++;
|
|
1173
|
+
if (cause.type === "props_change" /* PROPS_CHANGE */ && cause.propChanges) {
|
|
1174
|
+
this.accumulatePropChanges(profile, cause.propChanges);
|
|
1175
|
+
}
|
|
1176
|
+
const transactionId = getCurrentTransactionId();
|
|
1177
|
+
if (transactionId) {
|
|
1178
|
+
profile.lastTransactionId = transactionId;
|
|
1179
|
+
}
|
|
1180
|
+
if (parentComponentId) {
|
|
1181
|
+
const count = (profile.parentCounts.get(parentComponentId) ?? 0) + 1;
|
|
1182
|
+
profile.parentCounts.set(parentComponentId, count);
|
|
1183
|
+
if (!profile.primaryParentId || count > (profile.parentCounts.get(profile.primaryParentId) ?? 0)) {
|
|
1184
|
+
profile.primaryParentId = parentComponentId;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
profile.depth = depth;
|
|
1188
|
+
const windowStart = now - RENDER_THRESHOLDS.VELOCITY_WINDOW_MS;
|
|
1189
|
+
if (profile.velocityWindowStart < windowStart) {
|
|
1190
|
+
profile.velocityWindowStart = now;
|
|
1191
|
+
profile.velocityWindowCount = 1;
|
|
1192
|
+
} else {
|
|
1193
|
+
profile.velocityWindowCount++;
|
|
1194
|
+
}
|
|
1195
|
+
this.updateSuspiciousFlag(profile);
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* NEW: Accumulate prop change details into the profile.
|
|
1199
|
+
*/
|
|
1200
|
+
accumulatePropChanges(profile, changes) {
|
|
1201
|
+
const stats = profile.propChangeStats;
|
|
1202
|
+
for (const change of changes) {
|
|
1203
|
+
if (stats.changeCount.size >= RENDER_THRESHOLDS.MAX_PROP_KEYS_TO_TRACK && !stats.changeCount.has(change.key)) {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
stats.changeCount.set(
|
|
1207
|
+
change.key,
|
|
1208
|
+
(stats.changeCount.get(change.key) ?? 0) + 1
|
|
1209
|
+
);
|
|
1210
|
+
if (change.referenceOnly) {
|
|
1211
|
+
stats.referenceOnlyCount.set(
|
|
1212
|
+
change.key,
|
|
1213
|
+
(stats.referenceOnlyCount.get(change.key) ?? 0) + 1
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
if (profile.propChangeDelta.length < RENDER_THRESHOLDS.MAX_PROP_CHANGES_PER_SNAPSHOT) {
|
|
1218
|
+
profile.propChangeDelta.push(
|
|
1219
|
+
...changes.slice(
|
|
1220
|
+
0,
|
|
1221
|
+
RENDER_THRESHOLDS.MAX_PROP_CHANGES_PER_SNAPSHOT - profile.propChangeDelta.length
|
|
1222
|
+
)
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Build prop change snapshot for emission.
|
|
1228
|
+
*/
|
|
1229
|
+
buildPropChangeSnapshot(profile) {
|
|
1230
|
+
const stats = profile.propChangeStats;
|
|
1231
|
+
if (stats.changeCount.size === 0) {
|
|
1232
|
+
return void 0;
|
|
1233
|
+
}
|
|
1234
|
+
const sorted = Array.from(stats.changeCount.entries()).sort((a, b) => b[1] - a[1]).slice(0, RENDER_THRESHOLDS.TOP_PROPS_TO_REPORT);
|
|
1235
|
+
const topChangedProps = sorted.map(([key, count]) => {
|
|
1236
|
+
const refOnlyCount = stats.referenceOnlyCount.get(key) ?? 0;
|
|
1237
|
+
return {
|
|
1238
|
+
key,
|
|
1239
|
+
count,
|
|
1240
|
+
referenceOnlyPercent: count > 0 ? Math.round(refOnlyCount / count * 100) : 0
|
|
1241
|
+
};
|
|
1242
|
+
});
|
|
1243
|
+
return { topChangedProps };
|
|
1244
|
+
}
|
|
1245
|
+
updateSuspiciousFlag(profile) {
|
|
1246
|
+
const velocity = this.calculateVelocity(profile);
|
|
1247
|
+
if (velocity > RENDER_THRESHOLDS.HOT_VELOCITY) {
|
|
1248
|
+
profile.isSuspicious = true;
|
|
1249
|
+
profile.suspiciousReason = `High render velocity: ${velocity.toFixed(
|
|
1250
|
+
1
|
|
1251
|
+
)}/sec`;
|
|
1252
|
+
} else if (profile.totalRenders > RENDER_THRESHOLDS.HIGH_RENDER_COUNT) {
|
|
1253
|
+
profile.isSuspicious = true;
|
|
1254
|
+
profile.suspiciousReason = `High total renders: ${profile.totalRenders}`;
|
|
1255
|
+
} else {
|
|
1256
|
+
profile.isSuspicious = false;
|
|
1257
|
+
profile.suspiciousReason = void 0;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Calculates renders per second from velocity window.
|
|
1262
|
+
* Cheap: just count / window duration, no array operations.
|
|
1263
|
+
*/
|
|
1264
|
+
calculateVelocity(profile) {
|
|
1265
|
+
const now = Date.now();
|
|
1266
|
+
const windowAge = now - profile.velocityWindowStart;
|
|
1267
|
+
if (windowAge > RENDER_THRESHOLDS.VELOCITY_WINDOW_MS) {
|
|
1268
|
+
return 0;
|
|
1269
|
+
}
|
|
1270
|
+
const effectiveWindowMs = Math.max(windowAge, 100);
|
|
1271
|
+
return profile.velocityWindowCount / effectiveWindowMs * 1e3;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Emits a snapshot of all profiles with deltas.
|
|
1275
|
+
*/
|
|
1276
|
+
emitSnapshot() {
|
|
1277
|
+
const now = Date.now();
|
|
1278
|
+
const snapshots = [];
|
|
1279
|
+
for (const profile of this.profiles.values()) {
|
|
1280
|
+
const rendersDelta = profile.totalRenders - profile.lastEmittedRenderCount;
|
|
1281
|
+
if (rendersDelta < RENDER_THRESHOLDS.MIN_DELTA_TO_EMIT && !profile.isSuspicious) {
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
const velocity = this.calculateVelocity(profile);
|
|
1285
|
+
const isMount = profile.lastEmittedRenderCount === 0;
|
|
1286
|
+
const renderCostDelta = profile.totalRenderCost - profile.lastEmittedRenderCost;
|
|
1287
|
+
const propChanges = this.buildPropChangeSnapshot(profile);
|
|
1288
|
+
snapshots.push({
|
|
1289
|
+
id: profile.id,
|
|
1290
|
+
componentId: profile.componentId,
|
|
1291
|
+
componentName: profile.componentName,
|
|
1292
|
+
componentType: profile.componentType,
|
|
1293
|
+
totalRenders: profile.totalRenders,
|
|
1294
|
+
totalRenderCost: profile.totalRenderCost,
|
|
1295
|
+
avgRenderCost: profile.totalRenderCost / profile.totalRenders,
|
|
1296
|
+
rendersDelta,
|
|
1297
|
+
renderCostDelta,
|
|
1298
|
+
renderVelocity: velocity,
|
|
1299
|
+
causeBreakdown: { ...profile.causeBreakdown },
|
|
1300
|
+
causeDeltaBreakdown: { ...profile.causeDeltaBreakdown },
|
|
1301
|
+
parentComponentId: profile.primaryParentId,
|
|
1302
|
+
depth: profile.depth,
|
|
1303
|
+
lastTransactionId: profile.lastTransactionId,
|
|
1304
|
+
isSuspicious: profile.isSuspicious,
|
|
1305
|
+
suspiciousReason: profile.suspiciousReason,
|
|
1306
|
+
renderPhase: isMount ? "mount" /* MOUNT */ : "update" /* UPDATE */,
|
|
1307
|
+
mountedAt: profile.mountedAt,
|
|
1308
|
+
propChanges
|
|
1309
|
+
});
|
|
1310
|
+
profile.lastEmittedRenderCount = profile.totalRenders;
|
|
1311
|
+
profile.lastEmittedRenderCost = profile.totalRenderCost;
|
|
1312
|
+
profile.lastEmitTime = now;
|
|
1313
|
+
profile.causeDeltaBreakdown = createEmptyCauseBreakdown();
|
|
1314
|
+
profile.propChangeDelta = [];
|
|
1315
|
+
}
|
|
1316
|
+
for (const profile of this.pendingUnmounts) {
|
|
1317
|
+
const propChanges = this.buildPropChangeSnapshot(profile);
|
|
1318
|
+
snapshots.push({
|
|
1319
|
+
id: profile.id,
|
|
1320
|
+
componentId: profile.componentId,
|
|
1321
|
+
componentName: profile.componentName,
|
|
1322
|
+
componentType: profile.componentType,
|
|
1323
|
+
totalRenders: profile.totalRenders,
|
|
1324
|
+
totalRenderCost: profile.totalRenderCost,
|
|
1325
|
+
avgRenderCost: profile.totalRenderCost / Math.max(profile.totalRenders, 1),
|
|
1326
|
+
rendersDelta: 0,
|
|
1327
|
+
renderCostDelta: 0,
|
|
1328
|
+
renderVelocity: 0,
|
|
1329
|
+
causeBreakdown: { ...profile.causeBreakdown },
|
|
1330
|
+
causeDeltaBreakdown: createEmptyCauseBreakdown(),
|
|
1331
|
+
parentComponentId: profile.primaryParentId,
|
|
1332
|
+
depth: profile.depth,
|
|
1333
|
+
lastTransactionId: profile.lastTransactionId,
|
|
1334
|
+
isSuspicious: profile.isSuspicious,
|
|
1335
|
+
suspiciousReason: profile.suspiciousReason,
|
|
1336
|
+
renderPhase: "unmount" /* UNMOUNT */,
|
|
1337
|
+
mountedAt: profile.mountedAt,
|
|
1338
|
+
unmountedAt: profile.unmountedAt,
|
|
1339
|
+
propChanges
|
|
1340
|
+
});
|
|
1341
|
+
}
|
|
1342
|
+
this.pendingUnmounts = [];
|
|
1343
|
+
if (snapshots.length === 0) return;
|
|
1344
|
+
let message = {
|
|
1345
|
+
phase: "RENDER_SNAPSHOT",
|
|
1346
|
+
sessionId: this.getSessionId(),
|
|
1347
|
+
timestamp: now,
|
|
1348
|
+
profiles: snapshots
|
|
1349
|
+
};
|
|
1350
|
+
if (this.config?.beforeSend) {
|
|
1351
|
+
const modified = this.config.beforeSend(message);
|
|
1352
|
+
if (!modified) return;
|
|
1353
|
+
message = modified;
|
|
1354
|
+
}
|
|
1355
|
+
this.sendMessage(message);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Now returns prop change details when applicable.
|
|
1359
|
+
*/
|
|
1360
|
+
inferRenderCause(fiber, parentComponentId) {
|
|
1361
|
+
const alternate = fiber.alternate;
|
|
1362
|
+
if (!alternate) {
|
|
1363
|
+
return {
|
|
1364
|
+
type: "unknown" /* UNKNOWN */,
|
|
1365
|
+
confidence: "high" /* HIGH */
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
if (parentComponentId && this.currentCommitComponents.has(parentComponentId)) {
|
|
1369
|
+
const prevProps = alternate.memoizedProps;
|
|
1370
|
+
const nextProps = fiber.memoizedProps;
|
|
1371
|
+
const propsChanged = prevProps !== nextProps;
|
|
1372
|
+
if (propsChanged) {
|
|
1373
|
+
const propChanges = this.diffProps(prevProps, nextProps);
|
|
1374
|
+
return {
|
|
1375
|
+
type: "props_change" /* PROPS_CHANGE */,
|
|
1376
|
+
confidence: "medium" /* MEDIUM */,
|
|
1377
|
+
triggerId: parentComponentId,
|
|
1378
|
+
propChanges
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
return {
|
|
1382
|
+
type: "parent_render" /* PARENT_RENDER */,
|
|
1383
|
+
confidence: "medium" /* MEDIUM */,
|
|
1384
|
+
triggerId: parentComponentId
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
if (fiber.memoizedState !== alternate.memoizedState) {
|
|
1388
|
+
return {
|
|
1389
|
+
type: "state_change" /* STATE_CHANGE */,
|
|
1390
|
+
confidence: "medium" /* MEDIUM */
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
if (fiber.memoizedProps !== alternate.memoizedProps) {
|
|
1394
|
+
return {
|
|
1395
|
+
type: "context_change" /* CONTEXT_CHANGE */,
|
|
1396
|
+
confidence: "low" /* LOW */
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
return {
|
|
1400
|
+
type: "unknown" /* UNKNOWN */,
|
|
1401
|
+
confidence: "unknown" /* UNKNOWN */
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Diff props to find which keys changed and whether it's reference-only.
|
|
1406
|
+
* This is the key insight generator.
|
|
1407
|
+
*/
|
|
1408
|
+
diffProps(prevProps, nextProps) {
|
|
1409
|
+
if (!prevProps || !nextProps) {
|
|
1410
|
+
return [];
|
|
1411
|
+
}
|
|
1412
|
+
const changes = [];
|
|
1413
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
1414
|
+
...Object.keys(prevProps),
|
|
1415
|
+
...Object.keys(nextProps)
|
|
1416
|
+
]);
|
|
1417
|
+
const skipKeys = /* @__PURE__ */ new Set(["children", "key", "ref"]);
|
|
1418
|
+
for (const key of allKeys) {
|
|
1419
|
+
if (skipKeys.has(key)) continue;
|
|
1420
|
+
const prevValue = prevProps[key];
|
|
1421
|
+
const nextValue = nextProps[key];
|
|
1422
|
+
if (prevValue === nextValue) {
|
|
1423
|
+
continue;
|
|
1424
|
+
}
|
|
1425
|
+
const referenceOnly = this.isShallowEqual(prevValue, nextValue);
|
|
1426
|
+
changes.push({ key, referenceOnly });
|
|
1427
|
+
if (changes.length >= 10) {
|
|
1428
|
+
break;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
return changes;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Shallow equality check to determine if a prop is reference-only change.
|
|
1435
|
+
* We only go one level deep to keep it fast.
|
|
1436
|
+
*/
|
|
1437
|
+
isShallowEqual(a, b) {
|
|
1438
|
+
if (a === b) return true;
|
|
1439
|
+
if (typeof a !== typeof b) return false;
|
|
1440
|
+
if (a === null || b === null) return false;
|
|
1441
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
1442
|
+
return true;
|
|
1443
|
+
}
|
|
1444
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1445
|
+
if (a.length !== b.length) return false;
|
|
1446
|
+
for (let i = 0; i < a.length; i++) {
|
|
1447
|
+
if (a[i] !== b[i]) return false;
|
|
1448
|
+
}
|
|
1449
|
+
return true;
|
|
1450
|
+
}
|
|
1451
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
1452
|
+
const keysA = Object.keys(a);
|
|
1453
|
+
const keysB = Object.keys(b);
|
|
1454
|
+
if (keysA.length !== keysB.length) return false;
|
|
1455
|
+
for (const key of keysA) {
|
|
1456
|
+
if (a[key] !== b[key]) return false;
|
|
1457
|
+
}
|
|
1458
|
+
return true;
|
|
1459
|
+
}
|
|
1460
|
+
return a === b;
|
|
1461
|
+
}
|
|
1462
|
+
isUserComponent(fiber) {
|
|
1463
|
+
const tag = fiber.tag;
|
|
1464
|
+
return tag === 0 /* FunctionComponent */ || tag === 1 /* ClassComponent */ || tag === 11 /* ForwardRef */ || tag === 14 /* MemoComponent */ || tag === 15 /* SimpleMemoComponent */;
|
|
1465
|
+
}
|
|
1466
|
+
didFiberRender(fiber) {
|
|
1467
|
+
return (fiber.flags & 1 /* PerformedWork */) !== 0;
|
|
1468
|
+
}
|
|
1469
|
+
getOrCreateComponentId(fiber) {
|
|
1470
|
+
let id = this.fiberToComponentId.get(fiber);
|
|
1471
|
+
if (id) return id;
|
|
1472
|
+
if (fiber.alternate) {
|
|
1473
|
+
id = this.fiberToComponentId.get(fiber.alternate);
|
|
1474
|
+
if (id) {
|
|
1475
|
+
this.fiberToComponentId.set(fiber, id);
|
|
1476
|
+
return id;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
id = `c_${++this.componentIdCounter}`;
|
|
1480
|
+
this.fiberToComponentId.set(fiber, id);
|
|
1481
|
+
return id;
|
|
1482
|
+
}
|
|
1483
|
+
getComponentName(fiber) {
|
|
1484
|
+
const type = fiber.type;
|
|
1485
|
+
if (!type) return "Unknown";
|
|
1486
|
+
if (typeof type === "function") {
|
|
1487
|
+
return type.displayName || type.name || "Anonymous";
|
|
1488
|
+
}
|
|
1489
|
+
if (typeof type === "object" && type !== null) {
|
|
1490
|
+
if (type.displayName) return type.displayName;
|
|
1491
|
+
if (type.render)
|
|
1492
|
+
return type.render.displayName || type.render.name || "ForwardRef";
|
|
1493
|
+
if (type.type) {
|
|
1494
|
+
const inner = type.type;
|
|
1495
|
+
return inner.displayName || inner.name || "Memo";
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
return "Unknown";
|
|
1499
|
+
}
|
|
1500
|
+
getComponentType(fiber) {
|
|
1501
|
+
switch (fiber.tag) {
|
|
1502
|
+
case 0 /* FunctionComponent */:
|
|
1503
|
+
return "function";
|
|
1504
|
+
case 1 /* ClassComponent */:
|
|
1505
|
+
return "class";
|
|
1506
|
+
case 11 /* ForwardRef */:
|
|
1507
|
+
return "forwardRef";
|
|
1508
|
+
case 14 /* MemoComponent */:
|
|
1509
|
+
case 15 /* SimpleMemoComponent */:
|
|
1510
|
+
return "memo";
|
|
1511
|
+
default:
|
|
1512
|
+
return "unknown";
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Force emit current state (useful for debugging or on-demand refresh).
|
|
1517
|
+
*/
|
|
1518
|
+
forceEmit() {
|
|
1519
|
+
this.emitSnapshot();
|
|
1520
|
+
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Get current profile for a component (useful for debugging).
|
|
1523
|
+
*/
|
|
1524
|
+
getProfile(componentId) {
|
|
1525
|
+
return this.profiles.get(componentId);
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Get all suspicious components.
|
|
1529
|
+
*/
|
|
1530
|
+
getSuspiciousComponents() {
|
|
1531
|
+
return Array.from(this.profiles.values()).filter((p) => p.isSuspicious);
|
|
1532
|
+
}
|
|
1533
|
+
cleanup() {
|
|
1534
|
+
if (!this.isSetup) return;
|
|
1535
|
+
this.emitSnapshot();
|
|
1536
|
+
if (this.snapshotTimer) {
|
|
1537
|
+
clearInterval(this.snapshotTimer);
|
|
1538
|
+
this.snapshotTimer = null;
|
|
1539
|
+
}
|
|
1540
|
+
if (this.originalHook) {
|
|
1541
|
+
if (this.originalOnCommitFiberRoot) {
|
|
1542
|
+
this.originalHook.onCommitFiberRoot = this.originalOnCommitFiberRoot;
|
|
1543
|
+
}
|
|
1544
|
+
if (this.originalOnCommitFiberUnmount) {
|
|
1545
|
+
this.originalHook.onCommitFiberUnmount = this.originalOnCommitFiberUnmount;
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
this.originalHook = null;
|
|
1549
|
+
this.originalOnCommitFiberRoot = null;
|
|
1550
|
+
this.originalOnCommitFiberUnmount = null;
|
|
1551
|
+
this.profiles.clear();
|
|
1552
|
+
this.pendingUnmounts = [];
|
|
1553
|
+
this.currentCommitComponents.clear();
|
|
1554
|
+
this.componentIdCounter = 0;
|
|
1555
|
+
this.config = null;
|
|
1556
|
+
this.isSetup = false;
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
|
|
956
1560
|
// src/limelight/LimelightClient.ts
|
|
957
1561
|
var LimelightClient = class {
|
|
958
1562
|
ws = null;
|
|
@@ -967,6 +1571,7 @@ var LimelightClient = class {
|
|
|
967
1571
|
networkInterceptor;
|
|
968
1572
|
xhrInterceptor;
|
|
969
1573
|
consoleInterceptor;
|
|
1574
|
+
renderInterceptor;
|
|
970
1575
|
constructor() {
|
|
971
1576
|
this.networkInterceptor = new NetworkInterceptor(
|
|
972
1577
|
this.sendMessage.bind(this),
|
|
@@ -980,10 +1585,14 @@ var LimelightClient = class {
|
|
|
980
1585
|
this.sendMessage.bind(this),
|
|
981
1586
|
() => this.sessionId
|
|
982
1587
|
);
|
|
1588
|
+
this.renderInterceptor = new RenderInterceptor(
|
|
1589
|
+
this.sendMessage.bind(this),
|
|
1590
|
+
() => this.sessionId
|
|
1591
|
+
);
|
|
983
1592
|
}
|
|
984
1593
|
/**
|
|
985
1594
|
* Configures the Limelight client with the provided settings.
|
|
986
|
-
* Sets up network, XHR, and
|
|
1595
|
+
* Sets up network, XHR, console, and render interceptors based on the configuration.
|
|
987
1596
|
* @internal
|
|
988
1597
|
* @private
|
|
989
1598
|
* @param {LimelightConfig} config - Configuration object for Limelight
|
|
@@ -998,6 +1607,7 @@ var LimelightClient = class {
|
|
|
998
1607
|
enableNetworkInspector: true,
|
|
999
1608
|
enableConsole: true,
|
|
1000
1609
|
enableGraphQL: true,
|
|
1610
|
+
enableRenderInspector: true,
|
|
1001
1611
|
...config
|
|
1002
1612
|
};
|
|
1003
1613
|
if (!this.config.enabled) {
|
|
@@ -1012,6 +1622,9 @@ var LimelightClient = class {
|
|
|
1012
1622
|
if (this.config.enableConsole) {
|
|
1013
1623
|
this.consoleInterceptor.setup(this.config);
|
|
1014
1624
|
}
|
|
1625
|
+
if (this.config.enableRenderInspector) {
|
|
1626
|
+
this.renderInterceptor.setup(this.config);
|
|
1627
|
+
}
|
|
1015
1628
|
} catch (error) {
|
|
1016
1629
|
console.error("[Limelight] Failed to setup interceptors:", error);
|
|
1017
1630
|
}
|
|
@@ -1197,6 +1810,7 @@ var LimelightClient = class {
|
|
|
1197
1810
|
this.networkInterceptor.cleanup();
|
|
1198
1811
|
this.xhrInterceptor.cleanup();
|
|
1199
1812
|
this.consoleInterceptor.cleanup();
|
|
1813
|
+
this.renderInterceptor.cleanup();
|
|
1200
1814
|
this.reconnectAttempts = 0;
|
|
1201
1815
|
this.messageQueue = [];
|
|
1202
1816
|
}
|