@reticlehq/react 2.0.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/LICENSE +202 -0
- package/README.md +18 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -0
- package/dist/render-meter.d.ts +14 -0
- package/dist/render-meter.d.ts.map +1 -0
- package/dist/render-meter.js +80 -0
- package/dist/render-meter.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Reticle Labs
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @reticlehq/react
|
|
2
|
+
|
|
3
|
+
React adapter for [Reticle](https://github.com/reticlehq/reticle). Walks the React fiber tree so `reticle_inspect` can map a DOM element back to its **component stack and source file** — the bridge from "the agent sees a bug in the UI" to "the agent edits the right file".
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i -D @reticlehq/react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { install } from '@reticlehq/react';
|
|
11
|
+
if (import.meta.env.DEV) install(); // call before reticle.connect()
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Requires [`@reticlehq/browser`](https://www.npmjs.com/package/@reticlehq/browser).
|
|
15
|
+
|
|
16
|
+
**Source-file mapping:** on React ≤18, uses dev `_debugSource` automatically. On **React 19** (`_debugSource` removed), add [`@reticlehq/babel-plugin`](https://www.npmjs.com/package/@reticlehq/babel-plugin) to your dev build — the adapter then reads its `data-reticle-source` stamp so `reticle_inspect` returns `component.source = { file, line, column }`.
|
|
17
|
+
|
|
18
|
+
See the [main README](https://github.com/reticlehq/reticle). MIT.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ComponentInfo } from '@reticlehq/browser';
|
|
2
|
+
import { type ComponentStateResult } from '@reticlehq/core';
|
|
3
|
+
/** Walk the fiber tree from a DOM node up to the root, collecting components + source. */
|
|
4
|
+
export declare function identify(el: Element): ComponentInfo | null;
|
|
5
|
+
export declare function readState(el: Element): ComponentStateResult;
|
|
6
|
+
/**
|
|
7
|
+
* True if the element's host fiber declares React enter/leave handlers. Synthetic dispatchEvent
|
|
8
|
+
* does not reliably trigger React's native enter/leave synthesis (no hit-testing), so callers warn.
|
|
9
|
+
* Fail soft: any unexpected fiber shape returns false.
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasHoverHandlers(el: Element): boolean;
|
|
12
|
+
/** Register the React adapter so `reticle.inspect` returns component stack + source file. */
|
|
13
|
+
export declare function install(): void;
|
|
14
|
+
export { installRenderMeter, resetRenderMeter, getRenderStats, type RenderStats, } from './render-meter.js';
|
|
15
|
+
export * from '@reticlehq/browser';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAwB,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AA+DlF,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,EAAE,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAmC1D;AAkED,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,oBAAoB,CA0B3D;AASD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAMrD;AAID,6FAA6F;AAC7F,wBAAgB,OAAO,IAAI,IAAI,CAI9B;AAED,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,KAAK,WAAW,GACjB,MAAM,mBAAmB,CAAC;AAO3B,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { registerAdapter } from '@reticlehq/browser';
|
|
2
|
+
import { ComponentStateReason } from '@reticlehq/core';
|
|
3
|
+
const FIBER_PREFIXES = ['__reactFiber$', '__reactInternalInstance$'];
|
|
4
|
+
const MAX_DEPTH = 200;
|
|
5
|
+
const MAX_HOOKS = 100;
|
|
6
|
+
const MAX_SERIALIZE_DEPTH = 4;
|
|
7
|
+
const MAX_SERIALIZE_KEYS = 50;
|
|
8
|
+
const MAX_SERIALIZE_ITEMS = 50;
|
|
9
|
+
/** Marker substituted for a DOM node so the agent sees the tag, never the (circular) node. */
|
|
10
|
+
const DOM_NODE_MARKER = '[Node]';
|
|
11
|
+
/**
|
|
12
|
+
* Framework plumbing to hide from the component stack (React Router/Next internals, context
|
|
13
|
+
* providers, error/suspense boundaries) so the agent sees *your* components, not the runtime.
|
|
14
|
+
*/
|
|
15
|
+
const FRAMEWORK_NOISE = /(Context|Boundary|Provider|Router|Handler)$|^(Root|ServerRoot|HotReload|Fragment|__next)/;
|
|
16
|
+
function isFrameworkNoise(name) {
|
|
17
|
+
return FRAMEWORK_NOISE.test(name);
|
|
18
|
+
}
|
|
19
|
+
function getFiber(el) {
|
|
20
|
+
const key = Object.keys(el).find((k) => FIBER_PREFIXES.some((p) => k.startsWith(p)));
|
|
21
|
+
if (key === undefined)
|
|
22
|
+
return null;
|
|
23
|
+
const value = el[key];
|
|
24
|
+
return (value ?? null);
|
|
25
|
+
}
|
|
26
|
+
/** Display name of a component type (function, forwardRef/memo object, or host string). */
|
|
27
|
+
function componentName(type) {
|
|
28
|
+
if (typeof type === 'function') {
|
|
29
|
+
const fn = type;
|
|
30
|
+
if (fn.displayName !== undefined && fn.displayName.length > 0)
|
|
31
|
+
return fn.displayName;
|
|
32
|
+
return fn.name !== undefined && fn.name.length > 0 ? fn.name : null;
|
|
33
|
+
}
|
|
34
|
+
if (typeof type === 'object' && type !== null) {
|
|
35
|
+
const obj = type;
|
|
36
|
+
return obj.displayName !== undefined && obj.displayName.length > 0 ? obj.displayName : null;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
/** Walk the fiber tree from a DOM node up to the root, collecting components + source. */
|
|
41
|
+
export function identify(el) {
|
|
42
|
+
let fiber = getFiber(el);
|
|
43
|
+
const stack = [];
|
|
44
|
+
const rawStack = [];
|
|
45
|
+
let source;
|
|
46
|
+
let depth = 0;
|
|
47
|
+
while (fiber !== null && depth < MAX_DEPTH) {
|
|
48
|
+
depth += 1;
|
|
49
|
+
const name = componentName(fiber.elementType ?? fiber.type);
|
|
50
|
+
if (name !== null && rawStack[rawStack.length - 1] !== name) {
|
|
51
|
+
rawStack.push(name);
|
|
52
|
+
if (!isFrameworkNoise(name) && stack[stack.length - 1] !== name)
|
|
53
|
+
stack.push(name);
|
|
54
|
+
}
|
|
55
|
+
if (source === undefined && fiber._debugSource !== undefined) {
|
|
56
|
+
source = { file: fiber._debugSource.fileName, line: fiber._debugSource.lineNumber };
|
|
57
|
+
if (fiber._debugSource.columnNumber !== undefined) {
|
|
58
|
+
source.column = fiber._debugSource.columnNumber;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
fiber = fiber.return;
|
|
62
|
+
}
|
|
63
|
+
// React 19 dropped `_debugSource`; fall back to a data-reticle-source stamp if present
|
|
64
|
+
// (added by @reticlehq/babel-plugin in dev).
|
|
65
|
+
if (source === undefined) {
|
|
66
|
+
source = sourceFromAttribute(el);
|
|
67
|
+
}
|
|
68
|
+
// Prefer the de-noised stack; fall back to the nearest raw name if filtering left nothing.
|
|
69
|
+
const componentStack = stack.length > 0 ? stack : rawStack.slice(0, 1);
|
|
70
|
+
if (componentStack.length === 0 && source === undefined)
|
|
71
|
+
return null;
|
|
72
|
+
const info = { componentStack };
|
|
73
|
+
if (source !== undefined)
|
|
74
|
+
info.source = source;
|
|
75
|
+
return info;
|
|
76
|
+
}
|
|
77
|
+
function sourceFromAttribute(el) {
|
|
78
|
+
const stamped = el.closest('[data-reticle-source]');
|
|
79
|
+
const raw = stamped?.getAttribute('data-reticle-source');
|
|
80
|
+
if (raw === null || raw === undefined)
|
|
81
|
+
return undefined;
|
|
82
|
+
const match = /^(.*):(\d+):(\d+)$/.exec(raw);
|
|
83
|
+
if (match === null)
|
|
84
|
+
return undefined;
|
|
85
|
+
const [, file, line, column] = match;
|
|
86
|
+
if (file === undefined || line === undefined || column === undefined)
|
|
87
|
+
return undefined;
|
|
88
|
+
return { file, line: Number(line), column: Number(column) };
|
|
89
|
+
}
|
|
90
|
+
/** Find the nearest function-component fiber above a host node. */
|
|
91
|
+
function nearestComponentFiber(el) {
|
|
92
|
+
let fiber = getFiber(el);
|
|
93
|
+
let depth = 0;
|
|
94
|
+
while (fiber !== null && depth < MAX_DEPTH) {
|
|
95
|
+
depth += 1;
|
|
96
|
+
if (typeof fiber.type === 'function' || typeof fiber.elementType === 'function')
|
|
97
|
+
return fiber;
|
|
98
|
+
fiber = fiber.return;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* JSON-safe projection of an arbitrary hook value. Drops functions/DOM nodes/cycles and
|
|
104
|
+
* bounds depth/breadth, so the result handed to `JSON.stringify` downstream can never throw.
|
|
105
|
+
* Raw hook states routinely hold `useRef` DOM nodes, dispatchers, and circular fiber backrefs —
|
|
106
|
+
* serializing those un-guarded can cause hangs. Never throws.
|
|
107
|
+
*/
|
|
108
|
+
function safeValue(value, depth, seen) {
|
|
109
|
+
if (value === null)
|
|
110
|
+
return null;
|
|
111
|
+
const t = typeof value;
|
|
112
|
+
if (t === 'string' || t === 'number' || t === 'boolean')
|
|
113
|
+
return value;
|
|
114
|
+
if (t === 'undefined' || t === 'function' || t === 'symbol' || t === 'bigint')
|
|
115
|
+
return null;
|
|
116
|
+
if (typeof Node !== 'undefined' && value instanceof Node)
|
|
117
|
+
return DOM_NODE_MARKER;
|
|
118
|
+
if (depth >= MAX_SERIALIZE_DEPTH)
|
|
119
|
+
return null;
|
|
120
|
+
const obj = value;
|
|
121
|
+
if (seen.has(obj))
|
|
122
|
+
return null;
|
|
123
|
+
seen.add(obj);
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
const out = value.slice(0, MAX_SERIALIZE_ITEMS).map((v) => safeValue(v, depth + 1, seen));
|
|
126
|
+
seen.delete(obj);
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
const out = {};
|
|
130
|
+
const keys = Object.keys(obj).slice(0, MAX_SERIALIZE_KEYS);
|
|
131
|
+
for (const key of keys) {
|
|
132
|
+
out[key] = safeValue(obj[key], depth + 1, seen);
|
|
133
|
+
}
|
|
134
|
+
seen.delete(obj);
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Best-effort, bounded read of a function component's hook states by walking memoizedState.next.
|
|
139
|
+
* React does not expose hook *names*; we return positional, sanitized state values. State for
|
|
140
|
+
* class components / host fibers is skipped. Layout is React-version-specific — fail soft to a
|
|
141
|
+
* structured `{ ok: false, reason }` rather than throwing or producing an unserializable value.
|
|
142
|
+
*/
|
|
143
|
+
/** Build a success result, omitting `component` when the name is unknown (exactOptional-safe). */
|
|
144
|
+
function ok(name, hooks) {
|
|
145
|
+
return name === null ? { ok: true, hooks } : { ok: true, component: name, hooks };
|
|
146
|
+
}
|
|
147
|
+
export function readState(el) {
|
|
148
|
+
try {
|
|
149
|
+
const fiber = nearestComponentFiber(el);
|
|
150
|
+
if (fiber === null) {
|
|
151
|
+
return { ok: false, reason: ComponentStateReason.UNAVAILABLE };
|
|
152
|
+
}
|
|
153
|
+
const name = componentName(fiber.elementType ?? fiber.type);
|
|
154
|
+
const head = fiber.memoizedState;
|
|
155
|
+
if (typeof head !== 'object' || head === null) {
|
|
156
|
+
return ok(name, []);
|
|
157
|
+
}
|
|
158
|
+
const hooks = [];
|
|
159
|
+
const seen = new WeakSet();
|
|
160
|
+
let hook = head;
|
|
161
|
+
let i = 0;
|
|
162
|
+
while (typeof hook === 'object' && i < MAX_HOOKS) {
|
|
163
|
+
hooks.push(safeValue(hook.memoizedState, 0, seen));
|
|
164
|
+
const next = hook.next;
|
|
165
|
+
if (next === null || typeof next !== 'object')
|
|
166
|
+
break;
|
|
167
|
+
hook = next;
|
|
168
|
+
i += 1;
|
|
169
|
+
}
|
|
170
|
+
return ok(name, hooks);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return { ok: false, reason: ComponentStateReason.UNAVAILABLE };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const HOVER_HANDLER_KEYS = [
|
|
177
|
+
'onMouseEnter',
|
|
178
|
+
'onMouseLeave',
|
|
179
|
+
'onPointerEnter',
|
|
180
|
+
'onPointerLeave',
|
|
181
|
+
];
|
|
182
|
+
/**
|
|
183
|
+
* True if the element's host fiber declares React enter/leave handlers. Synthetic dispatchEvent
|
|
184
|
+
* does not reliably trigger React's native enter/leave synthesis (no hit-testing), so callers warn.
|
|
185
|
+
* Fail soft: any unexpected fiber shape returns false.
|
|
186
|
+
*/
|
|
187
|
+
export function hasHoverHandlers(el) {
|
|
188
|
+
const fiber = getFiber(el);
|
|
189
|
+
const props = fiber?.memoizedProps;
|
|
190
|
+
if (typeof props !== 'object' || props === null)
|
|
191
|
+
return false;
|
|
192
|
+
const p = props;
|
|
193
|
+
return HOVER_HANDLER_KEYS.some((k) => typeof p[k] === 'function');
|
|
194
|
+
}
|
|
195
|
+
let installed = false;
|
|
196
|
+
/** Register the React adapter so `reticle.inspect` returns component stack + source file. */
|
|
197
|
+
export function install() {
|
|
198
|
+
if (installed)
|
|
199
|
+
return;
|
|
200
|
+
installed = true;
|
|
201
|
+
registerAdapter({ name: 'react', identify, readState, hasHoverHandlers });
|
|
202
|
+
}
|
|
203
|
+
export { installRenderMeter, resetRenderMeter, getRenderStats, } from './render-meter.js';
|
|
204
|
+
// This package IS the React kit: one install gives an app dev the full browser-side surface
|
|
205
|
+
// (the `reticle` instance + all sensing) plus this React adapter. Re-exporting the sensor here is
|
|
206
|
+
// what lets `reticle init` wire a single dependency (`@reticlehq/react`) instead of making the app
|
|
207
|
+
// name `@reticlehq/browser` too. `install` above is defined locally and takes precedence over any
|
|
208
|
+
// same-named star re-export (the browser package has none), so there is no collision.
|
|
209
|
+
export * from '@reticlehq/browser';
|
|
210
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA4C,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAA6B,MAAM,iBAAiB,CAAC;AAsBlF,MAAM,cAAc,GAAG,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;AACrE,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,8FAA8F;AAC9F,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC;;;GAGG;AACH,MAAM,eAAe,GACnB,0FAA0F,CAAC;AAE7F,SAAS,gBAAgB,CAAC,IAAY;IACpC,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,QAAQ,CAAC,EAAW;IAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,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C;AAED,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB,6FAA6F;AAC7F,MAAM,UAAU,OAAO;IACrB,IAAI,SAAS;QAAE,OAAO;IACtB,SAAS,GAAG,IAAI,CAAC;IACjB,eAAe,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,GAEf,MAAM,mBAAmB,CAAC;AAE3B,4FAA4F;AAC5F,kGAAkG;AAClG,mGAAmG;AACnG,kGAAkG;AAClG,sFAAsF;AACtF,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The render stats surfaced via the `__reticle_renders` store (read with reticle_state). */
|
|
2
|
+
export interface RenderStats {
|
|
3
|
+
/** Total React commits observed since install (monotonic; diff over a window for a rate). */
|
|
4
|
+
commits: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function getRenderStats(): RenderStats;
|
|
7
|
+
/** Reset the commit counter — call before a measured window so the count is window-scoped. */
|
|
8
|
+
export declare function resetRenderMeter(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Install (or augment) the React commit hook + register the `__reticle_renders` store. Idempotent and
|
|
11
|
+
* never throws. Call BEFORE react-dom loads.
|
|
12
|
+
*/
|
|
13
|
+
export declare function installRenderMeter(): void;
|
|
14
|
+
//# sourceMappingURL=render-meter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-meter.d.ts","sourceRoot":"","sources":["../src/render-meter.ts"],"names":[],"mappings":"AAwCA,6FAA6F;AAC7F,MAAM,WAAW,WAAW;IAC1B,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED,8FAA8F;AAC9F,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAsCzC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React render meter — counts commits the way React DevTools does, via the global
|
|
3
|
+
* `__REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot` callback (one call per committed render). This is
|
|
4
|
+
* the Reticle-only perf signal: Playwright/DevTools-MCP cannot observe a single React render, so a page
|
|
5
|
+
* that is thrashing (committing many times a second) while the DOM stays visually identical — a
|
|
6
|
+
* wasted-render storm — looks idle to them. Reticle sees the commit rate.
|
|
7
|
+
*
|
|
8
|
+
* Exposed as a registered store (`__reticle_renders`) so it reads through the normal `reticle_state` path —
|
|
9
|
+
* no new wire surface. Total commits is the robust, version-tolerant signal; we deliberately do NOT
|
|
10
|
+
* attribute per-component (React clears the per-fiber work flags during commit, before this fires, so
|
|
11
|
+
* a post-commit walk can't reliably tell which component re-rendered without the profiler build).
|
|
12
|
+
*
|
|
13
|
+
* HOST-SAFE BY CONSTRUCTION: everything is wrapped in try/catch and React itself guards its calls to
|
|
14
|
+
* the devtools hook in try/catch, so a fault here can never break the host app's rendering. If a real
|
|
15
|
+
* React DevTools hook is already present we AUGMENT it (call the original too); otherwise we install a
|
|
16
|
+
* complete minimal hook. MUST be installed before `react-dom` initializes (React reads the hook at
|
|
17
|
+
* renderer-inject time) — import this as the first side-effect in the app entry, before React.
|
|
18
|
+
*/
|
|
19
|
+
import { registerStore } from '@reticlehq/browser';
|
|
20
|
+
const HOOK_KEY = '__REACT_DEVTOOLS_GLOBAL_HOOK__';
|
|
21
|
+
const RENDER_STORE = '__reticle_renders';
|
|
22
|
+
let commits = 0;
|
|
23
|
+
let installed = false;
|
|
24
|
+
function noop() {
|
|
25
|
+
/* React calls these; a no-op keeps a freshly-installed hook complete. */
|
|
26
|
+
}
|
|
27
|
+
export function getRenderStats() {
|
|
28
|
+
return { commits };
|
|
29
|
+
}
|
|
30
|
+
/** Reset the commit counter — call before a measured window so the count is window-scoped. */
|
|
31
|
+
export function resetRenderMeter() {
|
|
32
|
+
commits = 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Install (or augment) the React commit hook + register the `__reticle_renders` store. Idempotent and
|
|
36
|
+
* never throws. Call BEFORE react-dom loads.
|
|
37
|
+
*/
|
|
38
|
+
export function installRenderMeter() {
|
|
39
|
+
if (installed)
|
|
40
|
+
return;
|
|
41
|
+
installed = true;
|
|
42
|
+
try {
|
|
43
|
+
const root = globalThis;
|
|
44
|
+
const existing = root[HOOK_KEY];
|
|
45
|
+
if (existing === undefined) {
|
|
46
|
+
root[HOOK_KEY] = {
|
|
47
|
+
supportsFiber: true,
|
|
48
|
+
renderers: new Map(),
|
|
49
|
+
inject: () => 1,
|
|
50
|
+
onScheduleFiberRoot: noop,
|
|
51
|
+
onCommitFiberRoot: () => {
|
|
52
|
+
commits += 1;
|
|
53
|
+
},
|
|
54
|
+
onPostCommitFiberRoot: noop,
|
|
55
|
+
onCommitFiberUnmount: noop,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const original = typeof existing.onCommitFiberRoot === 'function'
|
|
60
|
+
? existing.onCommitFiberRoot.bind(existing)
|
|
61
|
+
: undefined;
|
|
62
|
+
existing.onCommitFiberRoot = (...args) => {
|
|
63
|
+
commits += 1;
|
|
64
|
+
if (original !== undefined) {
|
|
65
|
+
try {
|
|
66
|
+
original(...args);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* a real DevTools hook faulting must not be our problem */
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
registerStore(RENDER_STORE, () => getRenderStats());
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
/* never break the host app */
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=render-meter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-meter.js","sourceR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CAAC;YAChB,QAAQ,CAAC,iBAAiB,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;gBAClD,OAAO,IAAI,CAAC,CAAC;gBACb,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;oBAC3B,IAAI,CAAC;wBACH,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;oBACpB,CAAC;oBAAC,MAAM,CAAC;wBACP,2DAA2D;oBAC7D,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;QACJ,CAAC;QACD,aAAa,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,8BAA8B;IAChC,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reticlehq/react",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Reticle React adapter — maps a DOM ref to its component stack and source file via the fiber tree.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@reticlehq/browser": "2.0.0",
|
|
16
|
+
"@reticlehq/core": "2.0.0"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"peerDependenciesMeta": {
|
|
22
|
+
"react": {
|
|
23
|
+
"optional": true
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^19.0.0",
|
|
28
|
+
"jsdom": "^26.0.0"
|
|
29
|
+
},
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"author": "Reticle contributors",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/reticlehq/reticle.git",
|
|
35
|
+
"directory": "packages/react"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/reticlehq/reticle#readme",
|
|
38
|
+
"bugs": "https://github.com/reticlehq/reticle/issues",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"keywords": [
|
|
45
|
+
"mcp",
|
|
46
|
+
"ai-agents",
|
|
47
|
+
"react",
|
|
48
|
+
"testing"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc -b",
|
|
55
|
+
"typecheck": "tsc -b",
|
|
56
|
+
"lint": "eslint src",
|
|
57
|
+
"test:unit": "vitest run src --passWithNoTests"
|
|
58
|
+
}
|
|
59
|
+
}
|