rerender-lens 0.1.0 → 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.js CHANGED
@@ -1,7 +1,832 @@
1
- import { diffRecords, dispatch, buildReport, getState, isReactElement, getDisplayName } from './chunk-3YHI7BCU.js';
2
- export { MARKER, buildReport, classify, configure, deepEqual, diffRecords, disable, getDisplayName, init, isEnabled, printReport, resolveType, summarize, track } from './chunk-3YHI7BCU.js';
3
1
  import { useRef, useEffect } from 'react';
4
2
 
3
+ // src/types.ts
4
+ var MARKER = "rerenderLens";
5
+
6
+ // src/diff.ts
7
+ var REACT_ELEMENT = /* @__PURE__ */ Symbol.for("react.element");
8
+ var REACT_TRANSITIONAL_ELEMENT = /* @__PURE__ */ Symbol.for("react.transitional.element");
9
+ function isReactElement(v) {
10
+ if (typeof v !== "object" || v === null) return false;
11
+ const t = v.$$typeof;
12
+ return t === REACT_ELEMENT || t === REACT_TRANSITIONAL_ELEMENT;
13
+ }
14
+ function isPlainObject(v) {
15
+ if (typeof v !== "object" || v === null) return false;
16
+ const proto = Object.getPrototypeOf(v);
17
+ return proto === Object.prototype || proto === null;
18
+ }
19
+ function remember(seen, a, b) {
20
+ let set = seen.get(a);
21
+ if (!set) {
22
+ set = /* @__PURE__ */ new Set();
23
+ seen.set(a, set);
24
+ }
25
+ if (set.has(b)) return true;
26
+ set.add(b);
27
+ return false;
28
+ }
29
+ function deepEqual(a, b, seen = /* @__PURE__ */ new Map()) {
30
+ if (Object.is(a, b)) return true;
31
+ if (typeof a !== typeof b) return false;
32
+ if (typeof a !== "object" || a === null || b === null) return false;
33
+ const objA = a;
34
+ const objB = b;
35
+ if (remember(seen, objA, objB)) return true;
36
+ if (a instanceof Date) return b instanceof Date && a.getTime() === b.getTime();
37
+ if (a instanceof RegExp) return b instanceof RegExp && a.source === b.source && a.flags === b.flags;
38
+ if (Array.isArray(a)) {
39
+ if (!Array.isArray(b) || a.length !== b.length) return false;
40
+ for (let i = 0; i < a.length; i++) if (!deepEqual(a[i], b[i], seen)) return false;
41
+ return true;
42
+ }
43
+ if (Array.isArray(b)) return false;
44
+ if (ArrayBuffer.isView(a)) {
45
+ if (!ArrayBuffer.isView(b) || a.constructor !== b.constructor) return false;
46
+ const ta = a;
47
+ const tb = b;
48
+ if (ta.length !== tb.length) return false;
49
+ for (let i = 0; i < ta.length; i++) if (ta[i] !== tb[i]) return false;
50
+ return true;
51
+ }
52
+ if (a instanceof Map) {
53
+ if (!(b instanceof Map) || a.size !== b.size) return false;
54
+ for (const [k, v] of a) {
55
+ if (!b.has(k) || !deepEqual(v, b.get(k), seen)) return false;
56
+ }
57
+ return true;
58
+ }
59
+ if (a instanceof Set) {
60
+ if (!(b instanceof Set) || a.size !== b.size) return false;
61
+ outer: for (const v of a) {
62
+ if (b.has(v)) continue;
63
+ for (const w of b) if (deepEqual(v, w, seen)) continue outer;
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ if (isReactElement(a)) {
69
+ if (!isReactElement(b)) return false;
70
+ return a.type === b.type && a.key === b.key && deepEqual(a.props, b.props, seen);
71
+ }
72
+ if (isPlainObject(a) && isPlainObject(b)) {
73
+ const ka = Object.keys(a);
74
+ const kb = Object.keys(b);
75
+ if (ka.length !== kb.length) return false;
76
+ for (const k of ka) {
77
+ if (!Object.prototype.hasOwnProperty.call(b, k)) return false;
78
+ if (!deepEqual(a[k], b[k], seen)) return false;
79
+ }
80
+ return true;
81
+ }
82
+ return false;
83
+ }
84
+ function classify(prev, next) {
85
+ if (typeof prev === "function" && typeof next === "function") {
86
+ return prev.name === next.name && prev.toString() === next.toString() ? "function" : "different";
87
+ }
88
+ if (isReactElement(prev) && isReactElement(next)) {
89
+ return deepEqual(prev, next) ? "element" : "different";
90
+ }
91
+ return deepEqual(prev, next) ? "deep-equal" : "different";
92
+ }
93
+ function joinPath(base, key) {
94
+ if (typeof key === "number") return `${base}[${key}]`;
95
+ if (base === "") return key;
96
+ return /^[A-Za-z_$][\w$]*$/.test(key) ? `${base}.${key}` : `${base}[${JSON.stringify(key)}]`;
97
+ }
98
+ function diffRecords(prev, next, basePath = "") {
99
+ const p = prev ?? {};
100
+ const n = next ?? {};
101
+ const changes = [];
102
+ const keys = /* @__PURE__ */ new Set([...Object.keys(p), ...Object.keys(n)]);
103
+ for (const key of keys) {
104
+ const inPrev = Object.prototype.hasOwnProperty.call(p, key);
105
+ const inNext = Object.prototype.hasOwnProperty.call(n, key);
106
+ const path = joinPath(basePath, key);
107
+ if (inPrev && !inNext) {
108
+ changes.push({ path, kind: "removed", prev: p[key], next: void 0 });
109
+ continue;
110
+ }
111
+ if (!inPrev && inNext) {
112
+ changes.push({ path, kind: "added", prev: void 0, next: n[key] });
113
+ continue;
114
+ }
115
+ const a = p[key];
116
+ const b = n[key];
117
+ if (Object.is(a, b)) continue;
118
+ const kind = classify(a, b);
119
+ if (kind === "different") {
120
+ changes.push({ path: firstDifferentPath(a, b, path), kind, prev: a, next: b });
121
+ } else {
122
+ changes.push({ path, kind, prev: a, next: b });
123
+ }
124
+ }
125
+ return changes;
126
+ }
127
+ function firstDifferentPath(a, b, path, depth = 0) {
128
+ if (depth > 8) return path;
129
+ if (Array.isArray(a) && Array.isArray(b)) {
130
+ if (a.length !== b.length) return `${path}.length`;
131
+ for (let i = 0; i < a.length; i++) {
132
+ if (!deepEqual(a[i], b[i])) return firstDifferentPath(a[i], b[i], joinPath(path, i), depth + 1);
133
+ }
134
+ return path;
135
+ }
136
+ if (isPlainObject(a) && isPlainObject(b)) {
137
+ const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
138
+ for (const k of keys) {
139
+ if (!deepEqual(a[k], b[k])) return firstDifferentPath(a[k], b[k], joinPath(path, k), depth + 1);
140
+ }
141
+ return path;
142
+ }
143
+ return path;
144
+ }
145
+
146
+ // src/report.ts
147
+ var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
148
+ var isGenuine = (c) => c.kind === "different" || c.kind === "added" || c.kind === "removed";
149
+ var isChildren = (change) => change.path === "children";
150
+ function fixFor(change) {
151
+ if (isChildren(change) && (change.kind === "element" || change.kind === "deep-equal")) {
152
+ return `lift the children out of the parent's render: memoize them with useMemo, hoist static elements to module scope, or render them from a component that does not re-render`;
153
+ }
154
+ switch (change.kind) {
155
+ case "function":
156
+ return `wrap it in useCallback (or hoist it out of the parent's render)`;
157
+ case "element":
158
+ return `memoize the element with useMemo, or pass it as children from a stable parent`;
159
+ case "deep-equal":
160
+ return Array.isArray(change.next) ? `memoize the array with useMemo (same items, new reference)` : `memoize the object with useMemo, or hoist it to module scope if it is constant`;
161
+ default:
162
+ return "";
163
+ }
164
+ }
165
+ function describe(change) {
166
+ if (isChildren(change) && (change.kind === "element" || change.kind === "deep-equal")) {
167
+ return `children are new React elements with the same types and props on every render of the parent`;
168
+ }
169
+ switch (change.kind) {
170
+ case "deep-equal":
171
+ return `prop "${change.path}" is a new reference but deep-equal to the previous value`;
172
+ case "function":
173
+ return `prop "${change.path}" is a new function instance on every render`;
174
+ case "element":
175
+ return `prop "${change.path}" is a new React element with the same type and props`;
176
+ case "different":
177
+ return `prop "${change.path}" changed`;
178
+ case "added":
179
+ return `prop "${change.path}" was added`;
180
+ case "removed":
181
+ return `prop "${change.path}" was removed`;
182
+ }
183
+ }
184
+ function buildReport(input) {
185
+ const stateChanges = input.stateChanges ?? [];
186
+ const hookChanges = input.hookChanges ?? [];
187
+ const isStateHook = (h) => h.hook === "useState" || h.hook === "useReducer";
188
+ const genuineProps = input.propChanges.some(isGenuine);
189
+ const genuineState = stateChanges.some(isGenuine) || hookChanges.some((h) => isStateHook(h) && isGenuine(h));
190
+ const genuineHooks = hookChanges.some((h) => !isStateHook(h) && isGenuine(h));
191
+ const causes = [genuineProps && "props", genuineState && "state", genuineHooks && "hooks"].filter(Boolean);
192
+ let trigger;
193
+ if (causes.length === 0) trigger = "parent";
194
+ else if (causes.length === 1) trigger = causes[0];
195
+ else trigger = "mixed";
196
+ const avoidable = trigger === "parent";
197
+ const reasons = [];
198
+ if (avoidable && input.propChanges.length === 0 && stateChanges.length === 0 && hookChanges.length === 0) {
199
+ const who = input.parent ? `<${input.parent.name}> re-rendered (${describeTrigger(input.parent.trigger)})` : "its parent re-rendered";
200
+ reasons.push(`re-rendered with identical props because ${who}. Wrap "${input.component}" in React.memo (or extend PureComponent).`);
201
+ } else if (avoidable && input.parent) {
202
+ reasons.push(`caused by <${input.parent.name}> re-rendering (${describeTrigger(input.parent.trigger)}).`);
203
+ }
204
+ for (const c of input.propChanges) {
205
+ const fix = fixFor(c);
206
+ reasons.push(fix ? `${describe(c)}: ${fix}.` : `${describe(c)}.`);
207
+ }
208
+ const memoized = input.memoized !== false;
209
+ if (avoidable && !memoized && input.propChanges.length > 0) {
210
+ reasons.push(
211
+ `"${input.component}" is not memoized, so fixing the props alone will not stop this re-render: also wrap it in React.memo (or extend PureComponent).`
212
+ );
213
+ }
214
+ for (const c of stateChanges) {
215
+ if (isGenuine(c)) reasons.push(`state "${c.path}" changed.`);
216
+ else reasons.push(`setState was called with a value deep-equal to the current "${c.path}" (new reference, same contents).`);
217
+ }
218
+ for (const c of hookChanges) {
219
+ if (c.hook === "useContext" && isGenuine(c)) {
220
+ const where = c.provider && c.provider.component ? ` (provided by <${c.provider.component}>)` : "";
221
+ const keys = c.changedKeys && typeof c.totalKeys === "number" && c.changedKeys.length > 0 && c.changedKeys.length < c.totalKeys ? `: only ${c.changedKeys.map((k) => `"${k}"`).join(", ")} of ${c.totalKeys} keys changed, yet every consumer re-renders. Split the context or memoize the slices consumers read` : "";
222
+ reasons.push(`${c.path} changed${where}${keys}.`);
223
+ } else if (isGenuine(c)) reasons.push(`${c.hook} #${c.index} changed.`);
224
+ else if (isStateHook(c))
225
+ reasons.push(`${c.hook} #${c.index} was set to a value deep-equal to the current one (new reference, same contents): reuse the existing object or bail out before calling the setter.`);
226
+ else reasons.push(`${c.hook} #${c.index} returned a new reference that is deep-equal to the previous value: memoize the context/store value where it is produced.`);
227
+ }
228
+ const report = {
229
+ component: input.component,
230
+ instanceId: input.instanceId ?? 0,
231
+ commitId: input.commitId ?? 0,
232
+ renderCount: input.renderCount,
233
+ trigger,
234
+ avoidable,
235
+ memoized,
236
+ props: { prev: input.prevProps, next: input.nextProps },
237
+ propChanges: input.propChanges,
238
+ stateChanges,
239
+ hookChanges,
240
+ parent: input.parent ?? null,
241
+ owner: input.owner ?? null,
242
+ path: input.path ?? [],
243
+ reasons,
244
+ time: now()
245
+ };
246
+ if (input.selfDuration !== void 0) report.selfDuration = input.selfDuration;
247
+ if (input.treeDuration !== void 0) report.treeDuration = input.treeDuration;
248
+ if (input.commitPriority) report.commitPriority = input.commitPriority;
249
+ if (input.source) report.source = input.source;
250
+ return report;
251
+ }
252
+ function describeTrigger(t) {
253
+ switch (t) {
254
+ case "props":
255
+ return "its props changed";
256
+ case "state":
257
+ return "its state changed";
258
+ case "hooks":
259
+ return "a context or store it reads changed";
260
+ case "mixed":
261
+ return "its props and state changed";
262
+ default:
263
+ return "its own parent re-rendered";
264
+ }
265
+ }
266
+ var KIND_LABEL = {
267
+ "deep-equal": "equal by value",
268
+ function: "new function",
269
+ element: "equal element",
270
+ different: "changed",
271
+ added: "added",
272
+ removed: "removed"
273
+ };
274
+ function summarize(report) {
275
+ const counts2 = /* @__PURE__ */ new Map();
276
+ for (const c of [...report.propChanges, ...report.stateChanges, ...report.hookChanges]) {
277
+ counts2.set(c.kind, (counts2.get(c.kind) ?? 0) + 1);
278
+ }
279
+ const parts = [...counts2].map(([kind, n]) => `${n} ${KIND_LABEL[kind]}`);
280
+ if (parts.length === 0) parts.push("no changes");
281
+ return parts.join(", ");
282
+ }
283
+ function printReport(report, options) {
284
+ const c = options.console ?? console;
285
+ const open = options.collapse === false ? c.group : c.groupCollapsed;
286
+ const verdict = report.avoidable ? "avoidable re-render" : `re-render (${report.trigger})`;
287
+ open.call(c, `[rerender-lens] <${report.component}> ${verdict}: ${summarize(report)}`);
288
+ for (const r of report.reasons) c.log(`- ${r}`);
289
+ if (report.path.length) c.log(`at ${[...report.path, report.component].join(" > ")}`);
290
+ for (const ch of [...report.propChanges, ...report.stateChanges, ...report.hookChanges]) {
291
+ c.log(`${ch.path} (${KIND_LABEL[ch.kind]})`, { prev: ch.prev, next: ch.next });
292
+ }
293
+ c.log("props", report.props);
294
+ c.groupEnd();
295
+ }
296
+
297
+ // src/state.ts
298
+ var KEY = /* @__PURE__ */ Symbol.for("rerender-lens.state");
299
+ function getState() {
300
+ const g = globalThis;
301
+ let s = g[KEY];
302
+ if (!s) {
303
+ s = { options: {}, enabled: false, printed: /* @__PURE__ */ new Map(), detach: null, nextInstanceId: 1, nextCommitId: 1, warnedOnce: /* @__PURE__ */ new Set(), scheduled: 0, commits: 0 };
304
+ g[KEY] = s;
305
+ }
306
+ return s;
307
+ }
308
+ function warnOnce(key, message) {
309
+ const s = getState();
310
+ if (s.warnedOnce.has(key)) return;
311
+ s.warnedOnce.add(key);
312
+ (s.options.console ?? console).warn(`[rerender-lens] ${message}`);
313
+ }
314
+ function dispatch(report, override) {
315
+ const s = getState();
316
+ const options = override ? { ...s.options, ...override } : s.options;
317
+ if (!options.silent && (report.avoidable || options.logAll)) {
318
+ const max = options.maxReportsPerComponent ?? 0;
319
+ const n = (s.printed.get(report.component) ?? 0) + 1;
320
+ s.printed.set(report.component, n);
321
+ if (max <= 0 || n <= max) {
322
+ printReport(report, options);
323
+ } else if (n === max + 1) {
324
+ (options.console ?? console).log(
325
+ `[rerender-lens] <${report.component}> reached maxReportsPerComponent (${max}); further reports are not printed.`
326
+ );
327
+ }
328
+ }
329
+ if (options.notifier) {
330
+ try {
331
+ options.notifier(report);
332
+ } catch (err) {
333
+ (options.console ?? console).warn("[rerender-lens] notifier threw", err);
334
+ }
335
+ }
336
+ }
337
+
338
+ // src/fiber.ts
339
+ var FunctionComponent = 0;
340
+ var ClassComponent = 1;
341
+ var HostRoot = 3;
342
+ var HostComponent = 5;
343
+ var ContextProvider = 10;
344
+ var ForwardRef = 11;
345
+ var MemoComponent = 14;
346
+ var SimpleMemoComponent = 15;
347
+ var PerformedWork = 1;
348
+ var HOOK = "__REACT_DEVTOOLS_GLOBAL_HOOK__";
349
+ function ensureDevtoolsHook() {
350
+ const g = globalThis;
351
+ let hook = g[HOOK];
352
+ if (!hook) {
353
+ let nextId = 0;
354
+ const renderers = /* @__PURE__ */ new Map();
355
+ hook = {
356
+ renderers,
357
+ supportsFiber: true,
358
+ inject(renderer) {
359
+ const id = ++nextId;
360
+ renderers.set(id, renderer);
361
+ return id;
362
+ },
363
+ onCommitFiberRoot() {
364
+ },
365
+ onCommitFiberUnmount() {
366
+ },
367
+ onScheduleFiberRoot() {
368
+ },
369
+ onPostCommitFiberRoot() {
370
+ }
371
+ };
372
+ g[HOOK] = hook;
373
+ }
374
+ return hook;
375
+ }
376
+ var capturedRenderers = /* @__PURE__ */ new Map();
377
+ var INJECT_WRAPPED = /* @__PURE__ */ Symbol.for("rerender-lens.injectWrapped");
378
+ function pickRenderer(r) {
379
+ const info = r ?? {};
380
+ return { version: info.version, bundleType: info.bundleType, rendererPackageName: info.rendererPackageName };
381
+ }
382
+ function wrapInject(hook) {
383
+ const h = hook;
384
+ if (h[INJECT_WRAPPED] || typeof hook.inject !== "function") return;
385
+ const original = hook.inject;
386
+ hook.inject = function(renderer) {
387
+ const id = original.call(this, renderer);
388
+ capturedRenderers.set(typeof id === "number" ? id : capturedRenderers.size + 1, pickRenderer(renderer));
389
+ return id;
390
+ };
391
+ h[INJECT_WRAPPED] = true;
392
+ }
393
+ function attach() {
394
+ const hook = ensureDevtoolsHook();
395
+ wrapInject(hook);
396
+ const previous = hook.onCommitFiberRoot;
397
+ const patched = function(id, root, priority, didError) {
398
+ try {
399
+ onCommit(root, priorityLabel(priority));
400
+ } catch (err) {
401
+ warnOnce("commit", `failed to inspect a commit: ${String(err)}`);
402
+ }
403
+ if (typeof previous === "function") return previous.call(this, id, root, priority, didError);
404
+ };
405
+ hook.onCommitFiberRoot = patched;
406
+ const previousSchedule = hook.onScheduleFiberRoot;
407
+ const patchedSchedule = function(id, root, children) {
408
+ getState().scheduled++;
409
+ if (typeof previousSchedule === "function") return previousSchedule.call(this, id, root, children);
410
+ };
411
+ hook.onScheduleFiberRoot = patchedSchedule;
412
+ return () => {
413
+ if (hook.onCommitFiberRoot === patched) hook.onCommitFiberRoot = previous;
414
+ if (hook.onScheduleFiberRoot === patchedSchedule) hook.onScheduleFiberRoot = previousSchedule;
415
+ };
416
+ }
417
+ function priorityLabel(priority) {
418
+ switch (priority) {
419
+ case 1:
420
+ return "immediate";
421
+ case 2:
422
+ return "user-blocking";
423
+ case 3:
424
+ return "normal";
425
+ case 4:
426
+ return "low";
427
+ case 5:
428
+ return "idle";
429
+ default:
430
+ return void 0;
431
+ }
432
+ }
433
+ function getRenderers() {
434
+ const g = globalThis;
435
+ const hook = g[HOOK];
436
+ const byId = new Map(capturedRenderers);
437
+ if (hook && hook.renderers && typeof hook.renderers.forEach === "function") {
438
+ hook.renderers.forEach((r, id) => {
439
+ if (!byId.has(id)) byId.set(id, pickRenderer(r));
440
+ });
441
+ }
442
+ return [...byId.values()];
443
+ }
444
+ function isProductionReact() {
445
+ const renderers = getRenderers();
446
+ return renderers.length > 0 && renderers.every((r) => r.bundleType === 0);
447
+ }
448
+ var flagsOf = (f) => f.flags ?? f.effectTag ?? 0;
449
+ var isComponentTag = (tag) => tag === FunctionComponent || tag === ClassComponent || tag === ForwardRef || tag === MemoComponent || tag === SimpleMemoComponent;
450
+ function isMemoizedFiber(fiber) {
451
+ if (fiber.tag === MemoComponent || fiber.tag === SimpleMemoComponent) return true;
452
+ if (fiber.tag === ClassComponent) {
453
+ const inst = fiber.stateNode;
454
+ return !!(inst && inst.isPureReactComponent);
455
+ }
456
+ return false;
457
+ }
458
+ function durationsOf(fiber) {
459
+ if (typeof fiber.actualDuration !== "number") return null;
460
+ const tree = fiber.actualDuration;
461
+ let children = 0;
462
+ for (let c = fiber.child; c; c = c.sibling) if (typeof c.actualDuration === "number") children += c.actualDuration;
463
+ return { self: Math.max(0, tree - children), tree };
464
+ }
465
+ function fiberType(fiber) {
466
+ return fiber.elementType ?? fiber.type;
467
+ }
468
+ function fiberName(fiber) {
469
+ return getDisplayName(fiberType(fiber));
470
+ }
471
+ function didRender(fiber) {
472
+ return (flagsOf(fiber) & PerformedWork) !== 0;
473
+ }
474
+ function isHotSwapped(fiber, alt) {
475
+ return fiber.type !== alt.type;
476
+ }
477
+ var counts = /* @__PURE__ */ new WeakMap();
478
+ var ids = /* @__PURE__ */ new WeakMap();
479
+ var fibersById = /* @__PURE__ */ new Map();
480
+ var hasWeakRef = typeof WeakRef === "function";
481
+ function remember2(id, fiber) {
482
+ if (!hasWeakRef) return;
483
+ fibersById.set(id, new WeakRef(fiber));
484
+ if (fibersById.size > 5e3) {
485
+ for (const [k, ref] of fibersById) if (!ref.deref()) fibersById.delete(k);
486
+ }
487
+ }
488
+ function instanceIdOf(fiber) {
489
+ return ids.get(fiber) ?? (fiber.alternate ? ids.get(fiber.alternate) : void 0);
490
+ }
491
+ function fiberById(id) {
492
+ const f = fibersById.get(id)?.deref() ?? null;
493
+ if (!f) return null;
494
+ const alt = f.alternate;
495
+ if (alt && counts.get(alt) !== void 0 && (counts.get(alt) ?? 0) > (counts.get(f) ?? 0)) return alt;
496
+ return f;
497
+ }
498
+ function instanceId(fiber) {
499
+ const existing = instanceIdOf(fiber);
500
+ if (existing !== void 0) {
501
+ ids.set(fiber, existing);
502
+ remember2(existing, fiber);
503
+ return existing;
504
+ }
505
+ const s = getState();
506
+ const id = s.nextInstanceId++;
507
+ ids.set(fiber, id);
508
+ remember2(id, fiber);
509
+ return id;
510
+ }
511
+ function hostNodesOf(fiber, limit = 50) {
512
+ const out = [];
513
+ const stack = [];
514
+ for (let c = fiber.child; c; c = c.sibling) stack.push(c);
515
+ while (stack.length && out.length < limit) {
516
+ const f = stack.pop();
517
+ if (f.tag === HostComponent) {
518
+ if (typeof Element !== "undefined" && f.stateNode instanceof Element) out.push(f.stateNode);
519
+ continue;
520
+ }
521
+ for (let c = f.child; c; c = c.sibling) stack.push(c);
522
+ }
523
+ return out;
524
+ }
525
+ function fiberForNode(node) {
526
+ if (!node || typeof node !== "object") return null;
527
+ const key = Object.keys(node).find((k) => k.startsWith("__reactFiber$") || k.startsWith("__reactInternalInstance$"));
528
+ return key ? node[key] ?? null : null;
529
+ }
530
+ function nearestComponent(fiber) {
531
+ let f = fiber;
532
+ while (f && f.tag !== HostRoot) {
533
+ if (isComponentTag(f.tag)) return f;
534
+ f = f.return;
535
+ }
536
+ return null;
537
+ }
538
+ var INTERNAL_FRAME = /react-dom|react_jsx|jsx-(dev-)?runtime|\/react\/|node_modules\/react|react-stack-bottom-frame|react_stack_bottom_frame|scheduler/;
539
+ function parseStackLocation(stack) {
540
+ for (const line of stack.split("\n")) {
541
+ const m = /(?:at\s+(?:.*?\s+)?\(?|@)?((?:https?|file|webpack|vite|blob):[^\s()]+?):(\d+):(\d+)\)?\s*$/.exec(line.trim());
542
+ if (!m || !m[1] || INTERNAL_FRAME.test(m[1])) continue;
543
+ return { fileName: m[1], lineNumber: Number(m[2]), columnNumber: Number(m[3]) };
544
+ }
545
+ return void 0;
546
+ }
547
+ function sourceOf(fiber) {
548
+ const src = fiber._debugSource;
549
+ if (src && typeof src.fileName === "string") {
550
+ const out = { fileName: src.fileName };
551
+ if (typeof src.lineNumber === "number") out.lineNumber = src.lineNumber;
552
+ if (typeof src.columnNumber === "number") out.columnNumber = src.columnNumber;
553
+ return out;
554
+ }
555
+ const st = fiber._debugStack;
556
+ const text = typeof st === "string" ? st : st && typeof st.stack === "string" ? st.stack : null;
557
+ return text ? parseStackLocation(text) : void 0;
558
+ }
559
+ function bumpCount(fiber) {
560
+ const prev = counts.get(fiber) ?? (fiber.alternate ? counts.get(fiber.alternate) : void 0) ?? 0;
561
+ const n = prev + 1;
562
+ counts.set(fiber, n);
563
+ return n;
564
+ }
565
+ function componentPath(fiber) {
566
+ const path = [];
567
+ let f = fiber.return;
568
+ while (f && f.tag !== HostRoot) {
569
+ if (isComponentTag(f.tag)) path.unshift(fiberName(f));
570
+ f = f.return;
571
+ }
572
+ return path;
573
+ }
574
+ function ownerName(fiber) {
575
+ const owner = fiber._debugOwner;
576
+ if (!owner) return null;
577
+ if (owner.type !== void 0) return getDisplayName(owner.type);
578
+ return typeof owner.name === "string" ? owner.name : null;
579
+ }
580
+ var isStateNode = (n) => !!n.queue && typeof n.queue.lastRenderedReducer === "function";
581
+ var isStoreNode = (n) => !!n.queue && typeof n.queue.getSnapshot === "function";
582
+ function hookLabel(node) {
583
+ if (isStoreNode(node)) return "useSyncExternalStore";
584
+ if (isStateNode(node)) {
585
+ const r = node.queue.lastRenderedReducer;
586
+ return r.name === "basicStateReducer" ? "useState" : "useReducer";
587
+ }
588
+ return "state";
589
+ }
590
+ var NODELESS_HOOKS = /* @__PURE__ */ new Set(["useContext", "useDebugValue", "use"]);
591
+ function diffHooks(fiber, alt) {
592
+ const out = [];
593
+ if (fiber.tag === ClassComponent) return out;
594
+ let a = alt.memoizedState;
595
+ let b = fiber.memoizedState;
596
+ if (!a || !b || typeof b !== "object" || !("next" in b)) return out;
597
+ const types = fiber._debugHookTypes?.filter((t) => !NODELESS_HOOKS.has(t));
598
+ let nodeCount = 0;
599
+ for (let n = b; n; n = n.next) nodeCount++;
600
+ const labels = types && types.length === nodeCount ? types : null;
601
+ let i = 0;
602
+ while (a && b) {
603
+ if ((isStateNode(b) || isStoreNode(b)) && !Object.is(a.memoizedState, b.memoizedState)) {
604
+ const hook = labels?.[i] ?? hookLabel(b);
605
+ out.push({
606
+ path: `${hook}#${i}`,
607
+ hook,
608
+ index: i,
609
+ kind: classify(a.memoizedState, b.memoizedState),
610
+ prev: a.memoizedState,
611
+ next: b.memoizedState
612
+ });
613
+ }
614
+ a = a.next;
615
+ b = b.next;
616
+ i++;
617
+ }
618
+ return out;
619
+ }
620
+ function findProvider(fiber, context) {
621
+ let f = fiber.return;
622
+ while (f && f.tag !== HostRoot) {
623
+ if (f.tag === ContextProvider) {
624
+ const t = f.type;
625
+ if (t === context || t && typeof t === "object" && t._context === context) return f;
626
+ }
627
+ f = f.return;
628
+ }
629
+ return null;
630
+ }
631
+ var isPlainObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v) && Object.getPrototypeOf(v) === Object.prototype;
632
+ function diffContexts(fiber, alt) {
633
+ const out = [];
634
+ let a = alt.dependencies?.firstContext ?? null;
635
+ let b = fiber.dependencies?.firstContext ?? null;
636
+ let i = 0;
637
+ while (a && b) {
638
+ if (a.context === b.context && !Object.is(a.memoizedValue, b.memoizedValue)) {
639
+ const name = b.context.displayName ?? "Context";
640
+ const change = {
641
+ path: `useContext(${name})`,
642
+ hook: "useContext",
643
+ index: i,
644
+ kind: classify(a.memoizedValue, b.memoizedValue),
645
+ prev: a.memoizedValue,
646
+ next: b.memoizedValue
647
+ };
648
+ const provider = findProvider(fiber, b.context);
649
+ if (provider) {
650
+ const path = componentPath(provider);
651
+ change.provider = { component: path[path.length - 1] ?? null, path };
652
+ }
653
+ if (isPlainObject2(a.memoizedValue) && isPlainObject2(b.memoizedValue)) {
654
+ const prev = a.memoizedValue;
655
+ const next = b.memoizedValue;
656
+ const keys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)]);
657
+ change.changedKeys = [...keys].filter((k) => !Object.is(prev[k], next[k]));
658
+ change.totalKeys = keys.size;
659
+ }
660
+ out.push(change);
661
+ }
662
+ a = a.next;
663
+ b = b.next;
664
+ i++;
665
+ }
666
+ return out;
667
+ }
668
+ var isGenuine2 = (c) => c.kind === "different" || c.kind === "added" || c.kind === "removed";
669
+ function analyze(fiber, alt, trackHooks) {
670
+ const prevProps = alt.memoizedProps ?? {};
671
+ const nextProps = fiber.memoizedProps ?? {};
672
+ const propChanges = prevProps === nextProps ? [] : diffRecords(prevProps, nextProps);
673
+ let stateChanges = [];
674
+ let hookChanges = [];
675
+ if (fiber.tag === ClassComponent) {
676
+ if (alt.memoizedState !== fiber.memoizedState) {
677
+ stateChanges = diffRecords(
678
+ alt.memoizedState ?? {},
679
+ fiber.memoizedState ?? {}
680
+ );
681
+ }
682
+ } else if (trackHooks) {
683
+ hookChanges = [...diffHooks(fiber, alt), ...diffContexts(fiber, alt)];
684
+ }
685
+ const isStateHook = (h) => h.hook !== "useContext" && h.hook !== "useSyncExternalStore";
686
+ const causes = [];
687
+ if (propChanges.some(isGenuine2)) causes.push("props");
688
+ if (stateChanges.some(isGenuine2) || hookChanges.some((h) => isStateHook(h) && isGenuine2(h))) causes.push("state");
689
+ if (hookChanges.some((h) => !isStateHook(h) && isGenuine2(h))) causes.push("hooks");
690
+ const trigger = causes.length === 0 ? "parent" : causes.length === 1 ? causes[0] : "mixed";
691
+ return { propChanges, stateChanges, hookChanges, trigger };
692
+ }
693
+ function nearestRenderedAncestor(fiber, cache, trackHooks) {
694
+ let f = fiber.return;
695
+ while (f && f.tag !== HostRoot) {
696
+ if (isComponentTag(f.tag) && f.alternate && didRender(f)) {
697
+ let info = cache.get(f);
698
+ if (info === void 0) {
699
+ info = { name: fiberName(f), trigger: analyze(f, f.alternate, trackHooks).trigger };
700
+ cache.set(f, info);
701
+ }
702
+ return info;
703
+ }
704
+ f = f.return;
705
+ }
706
+ return null;
707
+ }
708
+ function onCommit(root, commitPriority) {
709
+ const s = getState();
710
+ if (!s.enabled) return;
711
+ s.commits++;
712
+ const o = s.options;
713
+ const trackHooks = o.trackHooks !== false;
714
+ const rendered = [];
715
+ let hot = false;
716
+ const stack = [root.current];
717
+ while (stack.length) {
718
+ const fiber = stack.pop();
719
+ const alt = fiber.alternate;
720
+ if (alt && isComponentTag(fiber.tag) && didRender(fiber)) {
721
+ if (isHotSwapped(fiber, alt)) hot = true;
722
+ if (shouldTrack(fiberType(fiber), o)) rendered.push(fiber);
723
+ }
724
+ if (!alt || fiber.child !== alt.child) {
725
+ for (let c = fiber.child; c; c = c.sibling) stack.push(c);
726
+ }
727
+ }
728
+ if (hot && o.ignoreHotReload !== false) return;
729
+ rendered.reverse();
730
+ if (rendered.length === 0) return;
731
+ const commitId = s.nextCommitId++;
732
+ const parentCache = /* @__PURE__ */ new Map();
733
+ for (const fiber of rendered) {
734
+ const alt = fiber.alternate;
735
+ const a = analyze(fiber, alt, trackHooks);
736
+ const durations = durationsOf(fiber);
737
+ const report = buildReport({
738
+ component: fiberName(fiber),
739
+ instanceId: instanceId(fiber),
740
+ renderCount: bumpCount(fiber),
741
+ prevProps: alt.memoizedProps ?? {},
742
+ nextProps: fiber.memoizedProps ?? {},
743
+ propChanges: a.propChanges,
744
+ stateChanges: a.stateChanges,
745
+ hookChanges: a.hookChanges,
746
+ parent: a.trigger === "parent" ? nearestRenderedAncestor(fiber, parentCache, trackHooks) : null,
747
+ owner: ownerName(fiber),
748
+ path: componentPath(fiber),
749
+ memoized: isMemoizedFiber(fiber),
750
+ selfDuration: durations ? durations.self : void 0,
751
+ treeDuration: durations ? durations.tree : void 0,
752
+ commitId,
753
+ commitPriority,
754
+ source: sourceOf(fiber)
755
+ });
756
+ dispatch(report);
757
+ }
758
+ }
759
+
760
+ // src/tracker.ts
761
+ var MEMO = /* @__PURE__ */ Symbol.for("react.memo");
762
+ var FORWARD_REF = /* @__PURE__ */ Symbol.for("react.forward_ref");
763
+ var isMemo = (t) => typeof t === "object" && t !== null && t.$$typeof === MEMO;
764
+ var isForwardRef = (t) => typeof t === "object" && t !== null && t.$$typeof === FORWARD_REF;
765
+ var isClass = (t) => typeof t === "function" && !!t.prototype?.isReactComponent;
766
+ var isPureClass = (t) => isClass(t) && !!t.prototype.isPureReactComponent;
767
+ var isComponentLike = (t) => typeof t === "function" || isMemo(t) || isForwardRef(t);
768
+ function getDisplayName(type) {
769
+ if (typeof type === "string") return type;
770
+ if (isMemo(type)) return type.displayName ?? getDisplayName(type.type);
771
+ if (isForwardRef(type)) return type.displayName ?? getDisplayName(type.render);
772
+ if (typeof type === "function") {
773
+ const t = type;
774
+ return t.displayName ?? (t.name || "Anonymous");
775
+ }
776
+ return "Anonymous";
777
+ }
778
+ function hasMarker(type) {
779
+ if (type === null || typeof type !== "function" && typeof type !== "object") return false;
780
+ if (type[MARKER] === true) return true;
781
+ if (isMemo(type)) return hasMarker(type.type);
782
+ if (isForwardRef(type)) return hasMarker(type.render);
783
+ return false;
784
+ }
785
+ function matches(m, name) {
786
+ if (typeof m === "string") return m === name;
787
+ if (m instanceof RegExp) return m.test(name);
788
+ return m(name);
789
+ }
790
+ function shouldTrack(type, o) {
791
+ if (!isComponentLike(type)) return false;
792
+ const name = getDisplayName(type);
793
+ if (o.exclude?.some((m) => matches(m, name))) return false;
794
+ if (hasMarker(type)) return true;
795
+ if (o.include?.some((m) => matches(m, name))) return true;
796
+ if (o.trackAllComponents) return true;
797
+ if (o.trackAllMemoized) return isMemo(type) || isPureClass(type);
798
+ return false;
799
+ }
800
+ function init(options = {}) {
801
+ const s = getState();
802
+ s.options = { ...options };
803
+ s.printed.clear();
804
+ if (!s.enabled) {
805
+ s.detach = attach();
806
+ s.enabled = true;
807
+ }
808
+ return disable;
809
+ }
810
+ function configure(options) {
811
+ const s = getState();
812
+ s.options = { ...s.options, ...options };
813
+ }
814
+ function disable() {
815
+ const s = getState();
816
+ if (!s.enabled) return;
817
+ s.detach?.();
818
+ s.detach = null;
819
+ s.enabled = false;
820
+ }
821
+ function isEnabled() {
822
+ return getState().enabled;
823
+ }
824
+ function track(component, name) {
825
+ const t = component;
826
+ t[MARKER] = true;
827
+ if (name) t.displayName = name;
828
+ return component;
829
+ }
5
830
  function useWhyRerender(name, values, options) {
6
831
  const ref = useRef({
7
832
  committed: null,
@@ -61,9 +886,99 @@ function combineNotifiers(...notifiers) {
61
886
  };
62
887
  }
63
888
 
889
+ // src/overlay.ts
890
+ var ROOT_ID = "rerender-lens-overlay";
891
+ var layer = null;
892
+ function ensureLayer() {
893
+ if (typeof document === "undefined" || !document.body) return null;
894
+ if (layer && layer.root.isConnected) return layer;
895
+ let root = document.getElementById(ROOT_ID);
896
+ if (!root) {
897
+ root = document.createElement("div");
898
+ root.id = ROOT_ID;
899
+ root.setAttribute("aria-hidden", "true");
900
+ Object.assign(root.style, {
901
+ position: "fixed",
902
+ inset: "0",
903
+ pointerEvents: "none",
904
+ zIndex: "2147483647",
905
+ overflow: "visible"
906
+ });
907
+ document.body.appendChild(root);
908
+ }
909
+ layer = { root, sticky: [] };
910
+ return layer;
911
+ }
912
+ function box(rect, color, fill, label) {
913
+ const b = document.createElement("div");
914
+ Object.assign(b.style, {
915
+ position: "absolute",
916
+ left: `${rect.left}px`,
917
+ top: `${rect.top}px`,
918
+ width: `${Math.max(rect.width, 2)}px`,
919
+ height: `${Math.max(rect.height, 2)}px`,
920
+ boxSizing: "border-box",
921
+ border: `2px solid ${color}`,
922
+ background: fill,
923
+ borderRadius: "2px"
924
+ });
925
+ if (label) {
926
+ const tag = document.createElement("span");
927
+ tag.textContent = label;
928
+ Object.assign(tag.style, {
929
+ position: "absolute",
930
+ left: "-2px",
931
+ top: rect.top > 20 ? "-20px" : "100%",
932
+ font: "11px/16px system-ui, sans-serif",
933
+ color: "#fff",
934
+ background: color,
935
+ padding: "1px 5px",
936
+ borderRadius: "2px",
937
+ whiteSpace: "nowrap"
938
+ });
939
+ b.appendChild(tag);
940
+ }
941
+ return b;
942
+ }
943
+ function highlight(target) {
944
+ const l = ensureLayer();
945
+ if (!l) return;
946
+ for (const s of l.sticky) s.remove();
947
+ l.sticky = [];
948
+ if (!target) return;
949
+ for (const node of target.nodes) {
950
+ const rect = node.getBoundingClientRect();
951
+ if (rect.width === 0 && rect.height === 0) continue;
952
+ const b = box(rect, "#1a73e8", "rgba(26, 115, 232, 0.12)", target.label);
953
+ l.root.appendChild(b);
954
+ l.sticky.push(b);
955
+ }
956
+ }
957
+ function clearHighlight() {
958
+ highlight(null);
959
+ }
960
+ function flash(target, duration = 500) {
961
+ const l = ensureLayer();
962
+ if (!l) return;
963
+ for (const node of target.nodes) {
964
+ const rect = node.getBoundingClientRect();
965
+ if (rect.width === 0 && rect.height === 0) continue;
966
+ const b = box(rect, "#d93025", "rgba(217, 48, 37, 0.15)");
967
+ b.style.transition = `opacity ${duration}ms ease-out`;
968
+ l.root.appendChild(b);
969
+ requestAnimationFrame(() => {
970
+ b.style.opacity = "0";
971
+ });
972
+ setTimeout(() => b.remove(), duration + 50);
973
+ }
974
+ }
975
+
976
+ // src/version.ts
977
+ var VERSION = "0.2.0" ;
978
+
64
979
  // src/devtools.ts
65
980
  var DEVTOOLS_MARKER = "__rerenderLens";
66
- var PROTOCOL_VERSION = 1;
981
+ var PROTOCOL_VERSION = 2;
67
982
  function serialize(value, maxDepth = 6, seen = /* @__PURE__ */ new WeakSet(), depth = 0) {
68
983
  if (value === null || value === void 0) return value;
69
984
  const t = typeof value;
@@ -77,7 +992,12 @@ function serialize(value, maxDepth = 6, seen = /* @__PURE__ */ new WeakSet(), de
77
992
  if (depth >= maxDepth) return "[\u2026]";
78
993
  seen.add(obj);
79
994
  try {
80
- if (isReactElement(obj)) return `<${getDisplayName(obj.type)}>`;
995
+ if (isReactElement(obj)) {
996
+ const out2 = { $type: "element", name: getDisplayName(obj.type) };
997
+ if (obj.key !== null && obj.key !== void 0) out2.key = String(obj.key);
998
+ out2.props = serialize(obj.props, maxDepth, seen, depth + 1);
999
+ return out2;
1000
+ }
81
1001
  if (obj instanceof Date) return { $type: "Date", value: obj.toISOString() };
82
1002
  if (obj instanceof RegExp) return { $type: "RegExp", value: String(obj) };
83
1003
  if (obj instanceof Map) {
@@ -95,20 +1015,66 @@ function serialize(value, maxDepth = 6, seen = /* @__PURE__ */ new WeakSet(), de
95
1015
  seen.delete(obj);
96
1016
  }
97
1017
  }
1018
+ var matcherToString = (m) => typeof m === "string" ? m : m instanceof RegExp ? String(m) : null;
1019
+ var stringToMatcher = (s) => {
1020
+ const m = /^\/(.+)\/([a-z]*)$/.exec(s);
1021
+ if (m && m[1] !== void 0) {
1022
+ try {
1023
+ return new RegExp(m[1], m[2]);
1024
+ } catch {
1025
+ return s;
1026
+ }
1027
+ }
1028
+ return s;
1029
+ };
1030
+ function serializeOptions(o) {
1031
+ const out = {};
1032
+ const bools = ["trackAllMemoized", "trackAllComponents", "trackHooks", "logAll", "silent", "collapse", "ignoreHotReload"];
1033
+ for (const k of bools) if (typeof o[k] === "boolean") out[k] = o[k];
1034
+ if (typeof o.maxReportsPerComponent === "number") out.maxReportsPerComponent = o.maxReportsPerComponent;
1035
+ if (o.include) out.include = o.include.map(matcherToString).filter((x) => x !== null);
1036
+ if (o.exclude) out.exclude = o.exclude.map(matcherToString).filter((x) => x !== null);
1037
+ return out;
1038
+ }
1039
+ function deserializeOptions(o) {
1040
+ const out = {};
1041
+ const bools = ["trackAllMemoized", "trackAllComponents", "trackHooks", "logAll", "silent", "collapse", "ignoreHotReload"];
1042
+ for (const k of bools) if (typeof o[k] === "boolean") out[k] = o[k];
1043
+ if (typeof o.maxReportsPerComponent === "number") out.maxReportsPerComponent = o.maxReportsPerComponent;
1044
+ if (Array.isArray(o.include)) out.include = o.include.filter((s) => typeof s === "string" && s).map(stringToMatcher);
1045
+ if (Array.isArray(o.exclude)) out.exclude = o.exclude.filter((s) => typeof s === "string" && s).map(stringToMatcher);
1046
+ return out;
1047
+ }
98
1048
  function createDevtoolsNotifier(options = {}) {
99
1049
  const bufferSize = options.bufferSize ?? 300;
100
1050
  const maxDepth = options.maxDepth ?? 6;
101
1051
  const target = options.target ?? (typeof window !== "undefined" ? window : void 0);
102
1052
  const buffer = [];
1053
+ let seq = 0;
1054
+ let flashOn = options.flashAvoidable ?? false;
103
1055
  const post = (type, payload) => {
104
1056
  if (!target) return;
105
1057
  const msg = { [DEVTOOLS_MARKER]: true, version: PROTOCOL_VERSION, type, payload };
106
1058
  target.postMessage(msg, "*");
107
1059
  };
1060
+ const source = options.source ?? "page";
1061
+ const info = () => ({
1062
+ count: buffer.length,
1063
+ library: VERSION,
1064
+ protocol: PROTOCOL_VERSION,
1065
+ react: getRenderers(),
1066
+ production: isProductionReact(),
1067
+ enabled: isEnabled(),
1068
+ options: serializeOptions(getState().options),
1069
+ source,
1070
+ injected: typeof window !== "undefined" && typeof window.__RERENDER_LENS_INJECTED__ === "string",
1071
+ scheduled: getState().scheduled,
1072
+ commits: getState().commits
1073
+ });
108
1074
  const bridge = {
109
1075
  replay: () => {
110
- post("hello", { count: buffer.length });
111
- for (const p of buffer) post("report", p);
1076
+ post("hello", info());
1077
+ for (const e of buffer) post("report", e.payload);
112
1078
  },
113
1079
  clear: () => {
114
1080
  buffer.length = 0;
@@ -117,18 +1083,70 @@ function createDevtoolsNotifier(options = {}) {
117
1083
  get size() {
118
1084
  return buffer.length;
119
1085
  },
120
- version: PROTOCOL_VERSION
1086
+ version: PROTOCOL_VERSION,
1087
+ library: VERSION,
1088
+ info,
1089
+ pull: (since = 0) => {
1090
+ const first = buffer[0];
1091
+ const dropped = since > 0 && !!first && first.seq > since + 1;
1092
+ const reports = buffer.filter((e) => e.seq > since).map((e) => e.payload);
1093
+ return { seq, reports, dropped };
1094
+ },
1095
+ configure: (next) => {
1096
+ configure(deserializeOptions(next ?? {}));
1097
+ return serializeOptions(getState().options);
1098
+ },
1099
+ getOptions: () => serializeOptions(getState().options),
1100
+ highlight: (id) => {
1101
+ if (id === null || id === void 0) {
1102
+ clearHighlight();
1103
+ return true;
1104
+ }
1105
+ const fiber = fiberById(id);
1106
+ if (!fiber) {
1107
+ clearHighlight();
1108
+ return false;
1109
+ }
1110
+ const nodes = hostNodesOf(fiber);
1111
+ highlight({ nodes, label: fiberName(fiber) });
1112
+ return nodes.length > 0;
1113
+ },
1114
+ flashAvoidable: (on) => {
1115
+ flashOn = !!on;
1116
+ },
1117
+ inspect: (node) => {
1118
+ const comp = nearestComponent(fiberForNode(node));
1119
+ if (!comp) return null;
1120
+ const id = instanceIdOf(comp) ?? null;
1121
+ const path = [];
1122
+ let f = comp.return;
1123
+ while (f) {
1124
+ if (f.tag === 0 || f.tag === 1 || f.tag === 11 || f.tag === 14 || f.tag === 15) path.unshift(fiberName(f));
1125
+ f = f.return;
1126
+ }
1127
+ return {
1128
+ component: fiberName(comp),
1129
+ instanceId: id,
1130
+ tracked: shouldTrack(fiberType(comp), getState().options),
1131
+ path,
1132
+ reports: id === null ? [] : buffer.filter((e) => e.instanceId === id).slice(-20).map((e) => e.payload)
1133
+ };
1134
+ }
121
1135
  };
122
1136
  if (typeof window !== "undefined") window.__RERENDER_LENS_DEVTOOLS__ = bridge;
123
- post("hello", { count: 0 });
1137
+ post("hello", info());
124
1138
  return (report) => {
125
1139
  const payload = serialize(report, maxDepth);
126
- buffer.push(payload);
1140
+ buffer.push({ seq: ++seq, instanceId: report.instanceId, payload });
127
1141
  if (buffer.length > bufferSize) buffer.splice(0, buffer.length - bufferSize);
128
1142
  post("report", payload);
1143
+ if (flashOn && report.avoidable && report.instanceId) {
1144
+ const fiber = fiberById(report.instanceId);
1145
+ if (fiber) flash({ nodes: hostNodesOf(fiber), label: report.component });
1146
+ }
129
1147
  };
130
1148
  }
131
1149
 
132
- export { DEVTOOLS_MARKER, PROTOCOL_VERSION, combineNotifiers, createCollector, createDevtoolsNotifier, serialize, useWhyRerender };
1150
+ export { DEVTOOLS_MARKER, MARKER, PROTOCOL_VERSION, VERSION, buildReport, classify, combineNotifiers, configure, createCollector, createDevtoolsNotifier, deepEqual, deserializeOptions, diffRecords, disable, ensureDevtoolsHook, getDisplayName, getRenderers, init, isEnabled, isProductionReact, printReport, serialize, serializeOptions, shouldTrack, summarize, track, useWhyRerender };
133
1151
  //# sourceMappingURL=index.js.map
134
1152
  //# sourceMappingURL=index.js.map