@lensmcp/react-instrumentation 1.21.2 → 1.21.4
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.d.ts +2 -0
- package/index.js +1 -1
- package/lib/component-identity.d.ts +46 -0
- package/lib/component-identity.js +1 -0
- package/lib/traced-hooks.js +1 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { tracedUseEffect, tracedUseMemo, tracedUseCallback, } from './lib/traced
|
|
|
4
4
|
export { TraceSlot, type TraceSlotProps } from './lib/trace-slot.js';
|
|
5
5
|
export { withTraceComponent, type WithTraceOptions } from './lib/hoc.js';
|
|
6
6
|
export { installFlowFetch, type FlowFetchOptions } from './lib/flow-fetch.js';
|
|
7
|
+
export { useComponentIdentity } from './lib/component-identity.js';
|
|
8
|
+
export type { ComponentIdentity } from './lib/component-identity.js';
|
|
7
9
|
export { installFiberRenderPublisher, resetFiberRenderPublisherForTests } from './lib/fiber-renders.js';
|
|
8
10
|
export { publish, setPublisher, drainQueue, runInFlow, currentFlow, activeFlow, extendFlowWindow, beginBackgroundFlow, withFlow, type PublishEnvelope, type PublishCategory, type FlowSpec, } from './lib/publish.js';
|
|
9
11
|
export { componentLogicalId, hookLogicalId, slotLogicalId, makeInstanceId, depsHash, resetIdentityState, } from './lib/identity.js';
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";export{LensmcpRoot}from"./lib/lensmcp-root.js";export{LensmcpContext,useLensmcpContext}from"./lib/context.js";export{tracedUseEffect,tracedUseMemo,tracedUseCallback}from"./lib/traced-hooks.js";export{TraceSlot}from"./lib/trace-slot.js";export{withTraceComponent}from"./lib/hoc.js";export{installFlowFetch}from"./lib/flow-fetch.js";export{installFiberRenderPublisher,resetFiberRenderPublisherForTests}from"./lib/fiber-renders.js";export{publish,setPublisher,drainQueue,runInFlow,currentFlow,activeFlow,extendFlowWindow,beginBackgroundFlow,withFlow}from"./lib/publish.js";export{componentLogicalId,hookLogicalId,slotLogicalId,makeInstanceId,depsHash,resetIdentityState}from"./lib/identity.js";export{default as lensmcpBabelPlugin}from"./lib/babel-plugin.js";
|
|
1
|
+
"use strict";export{LensmcpRoot}from"./lib/lensmcp-root.js";export{LensmcpContext,useLensmcpContext}from"./lib/context.js";export{tracedUseEffect,tracedUseMemo,tracedUseCallback}from"./lib/traced-hooks.js";export{TraceSlot}from"./lib/trace-slot.js";export{withTraceComponent}from"./lib/hoc.js";export{installFlowFetch}from"./lib/flow-fetch.js";export{useComponentIdentity}from"./lib/component-identity.js";export{installFiberRenderPublisher,resetFiberRenderPublisherForTests}from"./lib/fiber-renders.js";export{publish,setPublisher,drainQueue,runInFlow,currentFlow,activeFlow,extendFlowWindow,beginBackgroundFlow,withFlow}from"./lib/publish.js";export{componentLogicalId,hookLogicalId,slotLogicalId,makeInstanceId,depsHash,resetIdentityState}from"./lib/identity.js";export{default as lensmcpBabelPlugin}from"./lib/babel-plugin.js";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is this hook running inside?
|
|
3
|
+
*
|
|
4
|
+
* Every valtio subscription the lens recorded was attributed to
|
|
5
|
+
* `react:component:anonymous` — 364 of 364 in a live foodguard window — because
|
|
6
|
+
* `useSnapshot` read `ctx.componentInstanceId` from `LensmcpContext` and nothing ever
|
|
7
|
+
* set it: `LensmcpRoot` builds its context value from `{ rendererId, page, route }` and
|
|
8
|
+
* the babel transform stamps JSX attributes rather than wrapping components in a
|
|
9
|
+
* provider. So `valtio://subscribers` collapsed every subscriber in the app onto one
|
|
10
|
+
* key, and the question it exists to answer — WHO re-renders when this path changes —
|
|
11
|
+
* had no answer. The same blank rode along on every `effect-run` / `hook-run` record.
|
|
12
|
+
*
|
|
13
|
+
* `useId` is React's own per-instance identity: stable across that component instance's
|
|
14
|
+
* renders, distinct between instances, and part of the public API — no internals, no
|
|
15
|
+
* version coupling. That alone makes subscribers countable and distinguishable, which is
|
|
16
|
+
* most of the value.
|
|
17
|
+
*
|
|
18
|
+
* The NAME is best-effort on top. React exposes the currently-rendering component's
|
|
19
|
+
* owner only through internals whose shape has changed across majors, so a failed lookup
|
|
20
|
+
* yields no name rather than a wrong one or a throw — the identity stands on `useId`.
|
|
21
|
+
*/
|
|
22
|
+
export interface ComponentIdentity {
|
|
23
|
+
/** Stable for the life of this component instance. */
|
|
24
|
+
componentInstanceId: string;
|
|
25
|
+
/** `react:component:<Name>` when the name could be resolved. */
|
|
26
|
+
componentLogicalId?: string;
|
|
27
|
+
componentName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the currently-rendering component's name out of a React module object.
|
|
31
|
+
*
|
|
32
|
+
* Exported (and taking the module rather than requiring it) purely so the internals
|
|
33
|
+
* shapes below are testable without a renderer — they are the one part of this file that
|
|
34
|
+
* can silently stop working on a React major.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readOwnerName(React: Record<string, unknown> | undefined): string | undefined;
|
|
37
|
+
/** Build the identity from React's per-instance id plus an optional resolved name. */
|
|
38
|
+
export declare function composeComponentIdentity(id: string, name: string | undefined): ComponentIdentity;
|
|
39
|
+
/**
|
|
40
|
+
* Identify the component instance this hook is running in.
|
|
41
|
+
*
|
|
42
|
+
* MUST be called unconditionally from a hook (it calls `useId`/`useRef`), like any other
|
|
43
|
+
* hook. The name is resolved once, on first render, and reused — an owner lookup is
|
|
44
|
+
* cheap but not free, and a component's identity does not change between renders.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useComponentIdentity(): ComponentIdentity;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var t=(n,e)=>a(n,"name",{value:e,configurable:!0});var _=Object.defineProperty,o=t((n,e)=>_(n,"name",{value:e,configurable:!0}),"r");import{useId as p,useRef as m}from"react";export function readOwnerName(n){try{if(!n)return;const e=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE??n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;if(!e)return;const u=e.A,r=((typeof u?.getOwner=="function"?u.getOwner():null)??e.owner??e.ReactCurrentOwner?.current)?.type;if(!r)return;if(typeof r=="string")return r;const c=r.displayName??r.name;return typeof c=="string"&&c.length>0?c:void 0}catch{return}}t(readOwnerName,"readOwnerName"),o(readOwnerName,"readOwnerName");export function composeComponentIdentity(n,e){return{componentInstanceId:`react:component:${e??"fn"}${n}`,...e?{componentLogicalId:`react:component:${e}`,componentName:e}:{}}}t(composeComponentIdentity,"composeComponentIdentity"),o(composeComponentIdentity,"composeComponentIdentity");function i(){try{return readOwnerName(require("react"))}catch{return}}t(i,"f"),o(i,"currentOwnerName");export function useComponentIdentity(){const n=p(),e=m(void 0);return e.current||(e.current=composeComponentIdentity(n,i())),e.current}t(useComponentIdentity,"useComponentIdentity"),o(useComponentIdentity,"useComponentIdentity");
|
package/lib/traced-hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var p=(e,n)=>v(e,"name",{value:n,configurable:!0});var b=Object.defineProperty,f=p((e,n)=>b(e,"name",{value:n,configurable:!0}),"p");import{useCallback as w,useEffect as $,useMemo as H,useRef as i}from"react";import{useComponentIdentity as h}from"./component-identity.js";import{useLensmcpContext as k}from"./context.js";import{depsHash as y}from"./identity.js";import{publish as m}from"./publish.js";export function tracedUseEffect(e,n,r){const a=k(),s=h(),u=I(e),o=i(void 0);$(()=>{const t=typeof performance<"u"&&performance.now?performance.now():Date.now(),c=y(r),d=o.current;o.current=c;let l;try{l=n()}finally{const g=typeof performance<"u"&&performance.now?performance.now():Date.now();m({source:"react",category:"render",severity:"info",title:`effect-run ${e}`,fingerprint:`effect-run:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:c,prevDepsHash:d,durationMs:Math.max(0,g-t)}}})}return()=>{typeof l=="function"&&l(),m({source:"react",category:"render",severity:"info",title:`effect-cleanup ${e}`,fingerprint:`effect-cleanup:${e}`,raw:{kind:"effect-run",effect:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,depsHash:o.current??c,durationMs:0,cleanupRan:!0}}})}},r)}p(tracedUseEffect,"tracedUseEffect"),f(tracedUseEffect,"tracedUseEffect");export function tracedUseMemo(e,n,r){const a=k(),s=h(),u=I(e),o=i(void 0),t=y(r),c=t!==o.current,d=H(n,r??[]);return c&&m({source:"react",category:"render",severity:"debug",title:`useMemo recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,hookType:"useMemo",depsHash:t,prevDepsHash:o.current,recomputed:!0}}}),o.current=t,d}p(tracedUseMemo,"tracedUseMemo"),f(tracedUseMemo,"tracedUseMemo");export function tracedUseCallback(e,n,r){const a=k(),s=h(),u=I(e),o=i(void 0),t=y(r),c=t!==o.current,d=w(n,r??[]);return c&&m({source:"react",category:"render",severity:"debug",title:`useCallback recomputed ${e}`,fingerprint:`hook-run:${e}`,raw:{kind:"hook-run",hook:{hookInstanceId:u,hookLogicalId:e,componentInstanceId:a.componentInstanceId??s.componentInstanceId,hookType:"useCallback",depsHash:t,prevDepsHash:o.current,recomputed:!0}}}),o.current=t,d}p(tracedUseCallback,"tracedUseCallback"),f(tracedUseCallback,"tracedUseCallback");function I(e){const n=i(void 0);return n.current||(n.current=`${e}#${Math.random()*1e9|0}`),n.current}p(I,"H"),f(I,"useStableHookInstance");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/react-instrumentation",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.4",
|
|
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.21.
|
|
22
|
+
"@lensmcp/protocol-types": "1.21.4",
|
|
23
23
|
"tslib": "^2.3.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|