@lensmcp/react-instrumentation 1.18.4 → 1.18.7
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/index.js +1 -10
- package/lib/babel-plugin.js +1 -259
- package/lib/context.js +1 -6
- package/lib/fiber-renders.js +1 -237
- package/lib/flow-fetch.js +1 -143
- package/lib/hoc.js +1 -45
- package/lib/identity.js +1 -74
- package/lib/lensmcp-root.js +1 -59
- package/lib/publish.js +1 -236
- package/lib/trace-slot.js +1 -67
- package/lib/traced-hooks.js +1 -143
- package/lib/types.js +1 -1
- package/package.json +2 -2
package/lib/traced-hooks.js
CHANGED
|
@@ -1,143 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { useLensmcpContext } from './context.js';
|
|
3
|
-
import { depsHash } from './identity.js';
|
|
4
|
-
import { publish } from './publish.js';
|
|
5
|
-
/**
|
|
6
|
-
* Drop-in replacement for `useEffect` that emits an `effect-run` event
|
|
7
|
-
* on every run + a separate event on cleanup. The transform (T5.1)
|
|
8
|
-
* rewrites bare `useEffect(fn, deps)` calls to
|
|
9
|
-
* `tracedUseEffect("<file>:<line>:<index>", fn, deps)`.
|
|
10
|
-
*/
|
|
11
|
-
export function tracedUseEffect(hookLogicalId, effect, deps) {
|
|
12
|
-
const ctx = useLensmcpContext();
|
|
13
|
-
const hookInstanceId = useStableHookInstance(hookLogicalId);
|
|
14
|
-
const prevHashRef = useRef(undefined);
|
|
15
|
-
reactUseEffect(() => {
|
|
16
|
-
const startedAt = typeof performance !== 'undefined' && performance.now
|
|
17
|
-
? performance.now()
|
|
18
|
-
: Date.now();
|
|
19
|
-
const hash = depsHash(deps);
|
|
20
|
-
const prevHash = prevHashRef.current;
|
|
21
|
-
prevHashRef.current = hash;
|
|
22
|
-
let cleanup;
|
|
23
|
-
try {
|
|
24
|
-
cleanup = effect();
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
const endedAt = typeof performance !== 'undefined' && performance.now
|
|
28
|
-
? performance.now()
|
|
29
|
-
: Date.now();
|
|
30
|
-
publish({
|
|
31
|
-
source: 'react',
|
|
32
|
-
category: 'render',
|
|
33
|
-
severity: 'info',
|
|
34
|
-
title: `effect-run ${hookLogicalId}`,
|
|
35
|
-
fingerprint: `effect-run:${hookLogicalId}`,
|
|
36
|
-
raw: {
|
|
37
|
-
kind: 'effect-run',
|
|
38
|
-
effect: {
|
|
39
|
-
hookInstanceId,
|
|
40
|
-
hookLogicalId,
|
|
41
|
-
componentInstanceId: ctx.componentInstanceId,
|
|
42
|
-
depsHash: hash,
|
|
43
|
-
prevDepsHash: prevHash,
|
|
44
|
-
durationMs: Math.max(0, endedAt - startedAt),
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return () => {
|
|
50
|
-
if (typeof cleanup === 'function')
|
|
51
|
-
cleanup();
|
|
52
|
-
publish({
|
|
53
|
-
source: 'react',
|
|
54
|
-
category: 'render',
|
|
55
|
-
severity: 'info',
|
|
56
|
-
title: `effect-cleanup ${hookLogicalId}`,
|
|
57
|
-
fingerprint: `effect-cleanup:${hookLogicalId}`,
|
|
58
|
-
raw: {
|
|
59
|
-
kind: 'effect-run',
|
|
60
|
-
effect: {
|
|
61
|
-
hookInstanceId,
|
|
62
|
-
hookLogicalId,
|
|
63
|
-
componentInstanceId: ctx.componentInstanceId,
|
|
64
|
-
depsHash: prevHashRef.current ?? hash,
|
|
65
|
-
durationMs: 0,
|
|
66
|
-
cleanupRan: true,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
}, deps);
|
|
72
|
-
}
|
|
73
|
-
/** Same idea for `useMemo` — emits a `hook-run` event with `recomputed`. */
|
|
74
|
-
export function tracedUseMemo(hookLogicalId, compute, deps) {
|
|
75
|
-
const ctx = useLensmcpContext();
|
|
76
|
-
const hookInstanceId = useStableHookInstance(hookLogicalId);
|
|
77
|
-
const prevHashRef = useRef(undefined);
|
|
78
|
-
const hash = depsHash(deps);
|
|
79
|
-
const recomputed = hash !== prevHashRef.current;
|
|
80
|
-
const value = reactUseMemo(compute, deps ?? []);
|
|
81
|
-
if (recomputed) {
|
|
82
|
-
publish({
|
|
83
|
-
source: 'react',
|
|
84
|
-
category: 'render',
|
|
85
|
-
severity: 'debug',
|
|
86
|
-
title: `useMemo recomputed ${hookLogicalId}`,
|
|
87
|
-
fingerprint: `hook-run:${hookLogicalId}`,
|
|
88
|
-
raw: {
|
|
89
|
-
kind: 'hook-run',
|
|
90
|
-
hook: {
|
|
91
|
-
hookInstanceId,
|
|
92
|
-
hookLogicalId,
|
|
93
|
-
componentInstanceId: ctx.componentInstanceId,
|
|
94
|
-
hookType: 'useMemo',
|
|
95
|
-
depsHash: hash,
|
|
96
|
-
prevDepsHash: prevHashRef.current,
|
|
97
|
-
recomputed: true,
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
prevHashRef.current = hash;
|
|
103
|
-
return value;
|
|
104
|
-
}
|
|
105
|
-
/** Drop-in `useCallback` with the same accounting as `tracedUseMemo`. */
|
|
106
|
-
export function tracedUseCallback(hookLogicalId, cb, deps) {
|
|
107
|
-
const ctx = useLensmcpContext();
|
|
108
|
-
const hookInstanceId = useStableHookInstance(hookLogicalId);
|
|
109
|
-
const prevHashRef = useRef(undefined);
|
|
110
|
-
const hash = depsHash(deps);
|
|
111
|
-
const recomputed = hash !== prevHashRef.current;
|
|
112
|
-
const memoised = reactUseCallback(cb, deps ?? []);
|
|
113
|
-
if (recomputed) {
|
|
114
|
-
publish({
|
|
115
|
-
source: 'react',
|
|
116
|
-
category: 'render',
|
|
117
|
-
severity: 'debug',
|
|
118
|
-
title: `useCallback recomputed ${hookLogicalId}`,
|
|
119
|
-
fingerprint: `hook-run:${hookLogicalId}`,
|
|
120
|
-
raw: {
|
|
121
|
-
kind: 'hook-run',
|
|
122
|
-
hook: {
|
|
123
|
-
hookInstanceId,
|
|
124
|
-
hookLogicalId,
|
|
125
|
-
componentInstanceId: ctx.componentInstanceId,
|
|
126
|
-
hookType: 'useCallback',
|
|
127
|
-
depsHash: hash,
|
|
128
|
-
prevDepsHash: prevHashRef.current,
|
|
129
|
-
recomputed: true,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
prevHashRef.current = hash;
|
|
135
|
-
return memoised;
|
|
136
|
-
}
|
|
137
|
-
function useStableHookInstance(hookLogicalId) {
|
|
138
|
-
const ref = useRef(undefined);
|
|
139
|
-
if (!ref.current) {
|
|
140
|
-
ref.current = `${hookLogicalId}#${(Math.random() * 1e9) | 0}`;
|
|
141
|
-
}
|
|
142
|
-
return ref.current;
|
|
143
|
-
}
|
|
1
|
+
"use strict";var y=Object.defineProperty;var u=(e,n)=>y(e,"name",{value:n,configurable:!0});var g=Object.defineProperty,f=u((e,n)=>g(e,"name",{value:n,configurable:!0}),"f");import{useCallback as v,useEffect as b,useMemo as w,useRef as d}from"react";import{useLensmcpContext as l}from"./context.js";import{depsHash as h}from"./identity.js";import{publish as i}from"./publish.js";export function tracedUseEffect(e,n,t){const a=l(),s=m(e),r=d(void 0);b(()=>{const o=typeof performance<"u"&&performance.now?performance.now():Date.now(),c=h(t),p=r.current;r.current=c;let I;try{I=n()}finally{const k=typeof performance<"u"&&performance.now?performance.now():Date.now();i({source:"react",category:"render",severity:"info",title:`effect-run ${e}`,fingerprint:`effect-run:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,depsHash:c,prevDepsHash:p,durationMs:Math.max(0,k-o)}}})}return()=>{typeof I=="function"&&I(),i({source:"react",category:"render",severity:"info",title:`effect-cleanup ${e}`,fingerprint:`effect-cleanup:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,depsHash:r.current??c,durationMs:0,cleanupRan:!0}}})}},t)}u(tracedUseEffect,"tracedUseEffect"),f(tracedUseEffect,"tracedUseEffect");export function tracedUseMemo(e,n,t){const a=l(),s=m(e),r=d(void 0),o=h(t),c=o!==r.current,p=w(n,t??[]);return c&&i({source:"react",category:"render",severity:"debug",title:`useMemo recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,hookType:"useMemo",depsHash:o,prevDepsHash:r.current,recomputed:!0}}}),r.current=o,p}u(tracedUseMemo,"tracedUseMemo"),f(tracedUseMemo,"tracedUseMemo");export function tracedUseCallback(e,n,t){const a=l(),s=m(e),r=d(void 0),o=h(t),c=o!==r.current,p=v(n,t??[]);return c&&i({source:"react",category:"render",severity:"debug",title:`useCallback recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:s,hookLogicalId:e,componentInstanceId:a.componentInstanceId,hookType:"useCallback",depsHash:o,prevDepsHash:r.current,recomputed:!0}}}),r.current=o,p}u(tracedUseCallback,"tracedUseCallback"),f(tracedUseCallback,"tracedUseCallback");function m(e){const n=d(void 0);return n.current||(n.current=`${e}#${Math.random()*1e9|0}`),n.current}u(m,"y"),f(m,"useStableHookInstance");
|
package/lib/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
"use strict";export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/react-instrumentation",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@lensmcp/protocol-types": "1.18.
|
|
22
|
+
"@lensmcp/protocol-types": "1.18.7",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|