@oxog/react-check 1.0.3 → 1.1.1
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/CHANGELOG.md +84 -0
- package/README.md +90 -0
- package/dist/browser-inject.global.js +68 -6
- package/dist/chain.d.cts +1 -1
- package/dist/chain.d.ts +1 -1
- package/dist/cli.js +1472 -104
- package/dist/cli.js.map +1 -1
- package/dist/detect.d.cts +1 -1
- package/dist/detect.d.ts +1 -1
- package/dist/fix.d.cts +1 -1
- package/dist/fix.d.ts +1 -1
- package/dist/index.cjs +572 -357
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +183 -133
- package/dist/index.d.ts +183 -133
- package/dist/index.js +572 -357
- package/dist/index.js.map +1 -1
- package/dist/{scanner-BsBnFki5.d.cts → scanner-5j2LEM-q.d.cts} +1 -1
- package/dist/{scanner-bpT7eMcv.d.ts → scanner-CTBraprQ.d.ts} +1 -1
- package/dist/scanner.d.cts +2 -2
- package/dist/scanner.d.ts +2 -2
- package/dist/{types-CVcIoqzs.d.cts → types-xAXT9cir.d.cts} +5 -0
- package/dist/{types-CVcIoqzs.d.ts → types-xAXT9cir.d.ts} +5 -0
- package/package.json +8 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.1.1] - 2025-12-31
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Comprehensive documentation for TUI keyboard shortcuts
|
|
13
|
+
- Browser overlay documentation with toggle instructions
|
|
14
|
+
- Website documentation updates for WebUI and overlay features
|
|
15
|
+
|
|
16
|
+
## [1.1.0] - 2025-12-31
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **WebUI Dashboard**: Real-time web-based dashboard for monitoring React performance
|
|
21
|
+
- Live updating summary cards (components, renders, FPS, issues)
|
|
22
|
+
- Sortable/filterable component list with severity indicators
|
|
23
|
+
- Real-time render events stream
|
|
24
|
+
- Render chain visualization
|
|
25
|
+
- WebSocket-based live updates
|
|
26
|
+
- Auto-opens in default browser
|
|
27
|
+
- `--webui` flag to enable dashboard
|
|
28
|
+
- `--webui-port` option for custom port (default: 3100)
|
|
29
|
+
|
|
30
|
+
- **Browser Overlay Enhancements**: Visual feedback for component renders
|
|
31
|
+
- Flash effect with colored background on each render
|
|
32
|
+
- Pulsing border highlight shows render boundaries
|
|
33
|
+
- Render badges showing component name and count
|
|
34
|
+
- Severity-based colors (critical=red, warning=yellow, healthy=green)
|
|
35
|
+
- Toggle overlay on/off with `o` key in TUI
|
|
36
|
+
- Console access via `__REACTCHECK__.toggleOverlay()`
|
|
37
|
+
|
|
38
|
+
- **TUI Keyboard Shortcuts**:
|
|
39
|
+
- `o` - Toggle browser overlay on/off
|
|
40
|
+
- `j/k` or arrows - Navigate component list
|
|
41
|
+
- `Enter` - View component details
|
|
42
|
+
- `f` - Show fix suggestions
|
|
43
|
+
- `c` - Show render chain view
|
|
44
|
+
- `r` - Generate report
|
|
45
|
+
- `p` - Pause/resume scanning
|
|
46
|
+
- `q` - Quit
|
|
47
|
+
|
|
48
|
+
- **Demo Scripts**: Added npm scripts for running demo React app
|
|
49
|
+
- `npm run demo` - Install and start demo app
|
|
50
|
+
- `npm run demo:dev` - Start demo development server
|
|
51
|
+
- `npm run demo:scan` - Build and scan demo app with TUI
|
|
52
|
+
- `npm run demo:scan:webui` - Build and scan demo app with WebUI
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- TUI now correctly displays real-time data via data provider pattern
|
|
57
|
+
- Force full screen redraws for proper TUI updates
|
|
58
|
+
|
|
59
|
+
## [1.0.2] - 2025-12-30
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- Install React DevTools hook before React loads for proper detection
|
|
64
|
+
|
|
65
|
+
## [1.0.1] - 2025-12-30
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- Check listener count before emitting specific key events
|
|
70
|
+
|
|
71
|
+
## [1.0.0] - 2025-12-30
|
|
72
|
+
|
|
73
|
+
### Added
|
|
74
|
+
|
|
75
|
+
- Initial release
|
|
76
|
+
- Real-time render detection via React DevTools hook
|
|
77
|
+
- Render chain analysis for cascade effect detection
|
|
78
|
+
- Fix suggestions (memo, useMemo, useCallback, context splitting)
|
|
79
|
+
- Multiple report formats (HTML, JSON, Markdown)
|
|
80
|
+
- Framework detection (Next.js, Remix, Vite, CRA, Gatsby)
|
|
81
|
+
- Interactive TUI for terminal-based monitoring
|
|
82
|
+
- Browser overlay for visual component statistics
|
|
83
|
+
- Zero-dependency core functionality
|
|
84
|
+
- CLI commands: scan, report, detect
|
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ A zero-dependency React performance scanner that detects unnecessary re-renders,
|
|
|
10
10
|
- **Multiple Report Formats**: Export reports as HTML, JSON, or Markdown
|
|
11
11
|
- **Framework Detection**: Automatic detection and framework-specific tips for Next.js, Remix, Vite, CRA, Gatsby
|
|
12
12
|
- **Interactive TUI**: Terminal-based UI for real-time monitoring
|
|
13
|
+
- **WebUI Dashboard**: Real-time web dashboard with live updates
|
|
13
14
|
- **Browser Overlay**: Visual overlay showing component render statistics
|
|
14
15
|
- **Zero Dependencies**: Core functionality has no external dependencies
|
|
15
16
|
|
|
@@ -45,6 +46,18 @@ npx react-check scan http://localhost:3000 \
|
|
|
45
46
|
--headless
|
|
46
47
|
```
|
|
47
48
|
|
|
49
|
+
With WebUI dashboard:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx react-check scan http://localhost:3000 --webui
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
WebUI + custom port:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx react-check scan http://localhost:3000 --webui --webui-port 8080
|
|
59
|
+
```
|
|
60
|
+
|
|
48
61
|
### Programmatic Usage
|
|
49
62
|
|
|
50
63
|
```typescript
|
|
@@ -104,6 +117,8 @@ Options:
|
|
|
104
117
|
--include <patterns> Component patterns to include
|
|
105
118
|
--exclude <patterns> Component patterns to exclude
|
|
106
119
|
--no-tui Disable TUI, use simple output
|
|
120
|
+
-W, --webui Enable WebUI dashboard
|
|
121
|
+
--webui-port <port> WebUI dashboard port (default: 3100)
|
|
107
122
|
```
|
|
108
123
|
|
|
109
124
|
### `report <input>`
|
|
@@ -122,6 +137,78 @@ Detect the React framework in use.
|
|
|
122
137
|
react-check detect ./my-react-app
|
|
123
138
|
```
|
|
124
139
|
|
|
140
|
+
## Demo
|
|
141
|
+
|
|
142
|
+
Run the included demo React app to test ReactCheck:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Start demo app (runs on http://localhost:5173)
|
|
146
|
+
npm run demo
|
|
147
|
+
|
|
148
|
+
# In another terminal, scan with TUI
|
|
149
|
+
npm run demo:scan
|
|
150
|
+
|
|
151
|
+
# Or scan with WebUI dashboard
|
|
152
|
+
npm run demo:scan:webui
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## TUI Keyboard Shortcuts
|
|
156
|
+
|
|
157
|
+
While scanning with the interactive TUI, use these keyboard shortcuts:
|
|
158
|
+
|
|
159
|
+
| Key | Action |
|
|
160
|
+
|-----|--------|
|
|
161
|
+
| `j` / `↓` | Move selection down |
|
|
162
|
+
| `k` / `↑` | Move selection up |
|
|
163
|
+
| `Enter` | View component details |
|
|
164
|
+
| `Esc` | Go back to list view |
|
|
165
|
+
| `f` | Show fix suggestions for selected component |
|
|
166
|
+
| `c` | Show render chain view |
|
|
167
|
+
| `o` | Toggle browser overlay on/off |
|
|
168
|
+
| `r` | Generate report |
|
|
169
|
+
| `p` | Pause/resume scanning |
|
|
170
|
+
| `q` | Quit |
|
|
171
|
+
|
|
172
|
+
## Browser Overlay
|
|
173
|
+
|
|
174
|
+
ReactCheck injects a visual overlay into the target page that highlights component renders in real-time:
|
|
175
|
+
|
|
176
|
+
- **Flash Effect**: Components flash with a colored background on each render
|
|
177
|
+
- **Border Highlight**: Pulsing border shows render boundaries
|
|
178
|
+
- **Render Badges**: Small badges show component name and render count
|
|
179
|
+
- **Severity Colors**: Critical (red), Warning (yellow), Healthy (green)
|
|
180
|
+
|
|
181
|
+
### Toggle Overlay
|
|
182
|
+
|
|
183
|
+
You can toggle the overlay on/off in several ways:
|
|
184
|
+
|
|
185
|
+
1. **TUI**: Press `o` to toggle overlay visibility
|
|
186
|
+
2. **Browser Console**: Run `__REACTCHECK__.toggleOverlay()`
|
|
187
|
+
3. **WebUI Dashboard**: Click the overlay toggle button
|
|
188
|
+
|
|
189
|
+
When overlay is disabled, render tracking continues but visual effects are hidden.
|
|
190
|
+
|
|
191
|
+
## WebUI Dashboard
|
|
192
|
+
|
|
193
|
+
The WebUI dashboard provides a real-time web interface for monitoring React performance:
|
|
194
|
+
|
|
195
|
+
- **Live Summary**: Components, renders, FPS, and issue counts update in real-time
|
|
196
|
+
- **Component List**: Sortable and filterable table with severity indicators
|
|
197
|
+
- **Render Events**: Live stream of render events as they occur
|
|
198
|
+
- **Render Chains**: Visualization of cascade render chains
|
|
199
|
+
- **Auto-open**: Dashboard opens automatically in your default browser
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# Enable WebUI alongside TUI
|
|
203
|
+
react-check scan http://localhost:3000 --webui
|
|
204
|
+
|
|
205
|
+
# Custom WebUI port
|
|
206
|
+
react-check scan http://localhost:3000 --webui --webui-port 8080
|
|
207
|
+
|
|
208
|
+
# WebUI only (no TUI)
|
|
209
|
+
react-check scan http://localhost:3000 --webui --silent
|
|
210
|
+
```
|
|
211
|
+
|
|
125
212
|
## Report Formats
|
|
126
213
|
|
|
127
214
|
### HTML Report
|
|
@@ -320,6 +407,9 @@ src/
|
|
|
320
407
|
├── cli/ # CLI implementation
|
|
321
408
|
│ ├── index.ts # CLI entry
|
|
322
409
|
│ └── tui/ # Terminal UI
|
|
410
|
+
├── webui/ # Web dashboard
|
|
411
|
+
│ ├── server.ts # HTTP + WebSocket server
|
|
412
|
+
│ └── dashboard.ts # Dashboard HTML generator
|
|
323
413
|
└── utils/ # Shared utilities
|
|
324
414
|
├── colors.ts # ANSI colors
|
|
325
415
|
├── format.ts # Formatters
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ReactCheckInjector=(function(exports){'use strict';var C=Object.defineProperty;var R=(i,e,t)=>e in i?C(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var
|
|
1
|
+
var ReactCheckInjector=(function(exports){'use strict';var C=Object.defineProperty;var R=(i,e,t)=>e in i?C(i,e,{enumerable:true,configurable:true,writable:true,value:t}):i[e]=t;var l=(i,e,t)=>R(i,typeof e!="symbol"?e+"":e,t);var p=class{constructor(){l(this,"_listeners",new Map);l(this,"_onceListeners",new Map);l(this,"maxListeners",0);}on(e,t){let n=this._listeners.get(e);return n||(n=new Set,this._listeners.set(e,n)),this.maxListeners>0&&n.size>=this.maxListeners&&console.warn(`Warning: Possible EventEmitter memory leak detected. ${n.size+1} listeners added for event "${String(e)}". Use setMaxListeners() to increase limit.`),n.add(t),this}addListener(e,t){return this.on(e,t)}once(e,t){let n=this._onceListeners.get(e);return n||(n=new Set,this._onceListeners.set(e,n)),n.add(t),this}off(e,t){let n=this._listeners.get(e);n&&(n.delete(t),n.size===0&&this._listeners.delete(e));let o=this._onceListeners.get(e);return o&&(o.delete(t),o.size===0&&this._onceListeners.delete(e)),this}removeListener(e,t){return this.off(e,t)}removeAllListeners(e){return e!==void 0?(this._listeners.delete(e),this._onceListeners.delete(e)):(this._listeners.clear(),this._onceListeners.clear()),this}emit(e,t){let n=false,o=this._listeners.get(e);if(o)for(let a of o)try{a(t),n=!0;}catch(r){if(e!=="error")this.emit("error",r);else throw r}let s=this._onceListeners.get(e);if(s){let a=Array.from(s);this._onceListeners.delete(e);for(let r of a)try{r(t),n=!0;}catch(h){if(e!=="error")this.emit("error",h);else throw h}}return n}getListeners(e){let t=this._listeners.get(e),n=this._onceListeners.get(e),o=[];return t&&o.push(...Array.from(t)),n&&o.push(...Array.from(n)),o}listenerCount(e){let t=this._listeners.get(e)?.size??0,n=this._onceListeners.get(e)?.size??0;return t+n}eventNames(){let e=new Set;for(let t of this._listeners.keys())e.add(t);for(let t of this._onceListeners.keys())e.add(t);return Array.from(e)}setMaxListeners(e){return this.maxListeners=e,this}getMaxListeners(){return this.maxListeners}prependListener(e,t){let n=this._listeners.get(e);if(!n)return this.on(e,t);let o=Array.from(n);return o.unshift(t),this._listeners.set(e,new Set(o)),this}prependOnceListener(e,t){let n=this._onceListeners.get(e);if(!n)return this.once(e,t);let o=Array.from(n);return o.unshift(t),this._onceListeners.set(e,new Set(o)),this}waitFor(e,t){return new Promise((n,o)=>{let s,a=r=>{s&&clearTimeout(s),n(r);};this.once(e,a),t!==void 0&&t>0&&(s=setTimeout(()=>{this.off(e,a),o(new Error(`Timeout waiting for event "${String(e)}"`));},t));})}};var c={FunctionComponent:0,ClassComponent:1,HostRoot:3,HostComponent:5,HostText:6,Fragment:7,ContextConsumer:9,ContextProvider:10,ForwardRef:11,Profiler:12,SuspenseComponent:13,MemoComponent:14,SimpleMemoComponent:15,LazyComponent:16,IncompleteClassComponent:17};function m(i){if(!i)return "Unknown";let{type:e,tag:t}=i;switch(t){case c.FunctionComponent:case c.ClassComponent:case c.SimpleMemoComponent:case c.IncompleteClassComponent:return f(e)||"Anonymous";case c.ForwardRef:if(e&&typeof e=="object"&&"render"in e){let n=e.render;return `ForwardRef(${f(n)||"Anonymous"})`}return "ForwardRef";case c.MemoComponent:if(e&&typeof e=="object"&&"type"in e){let n=e.type;return `Memo(${f(n)||"Anonymous"})`}return "Memo";case c.LazyComponent:return "Lazy";case c.ContextConsumer:return "Context.Consumer";case c.ContextProvider:return "Context.Provider";case c.SuspenseComponent:return "Suspense";case c.Fragment:return "Fragment";case c.Profiler:return "Profiler";case c.HostRoot:return "Root";case c.HostComponent:return typeof e=="string"?e:"HostComponent";case c.HostText:return "#text";default:return f(e)||"Unknown"}}function f(i){if(i!=null){if(typeof i=="string")return i;if(typeof i=="function")return i.displayName??i.name??void 0;if(typeof i=="object"){let e=i;return e.displayName??e.name??void 0}}}function b(i){let{tag:e}=i;return e===c.FunctionComponent||e===c.ClassComponent||e===c.MemoComponent||e===c.SimpleMemoComponent||e===c.ForwardRef||e===c.LazyComponent}function k(i,e){if(i===e)return [];if(!i||!e)return Object.keys(e??i??{});let t=[],n=new Set([...Object.keys(i),...Object.keys(e)]);for(let o of n)o!=="children"&&i[o]!==e[o]&&t.push(o);return t}function w(i,e,t,n){let o=m(i),s=i.actualDuration??0,a=t?k(t,i.memoizedProps):void 0,r=a&&a.length>0,h=n!==i.memoizedState,d={componentName:o,renderCount:1,renderTime:s,phase:e,necessary:e==="mount"||r||h,timestamp:Date.now()};return a!==void 0&&(d.changedProps=a),h&&(d.changedState=["state"]),d}var x={enabled:true,highlightRenders:true,animationSpeed:"fast",showBadges:true,showToolbar:true},T={critical:"#ef4444",warning:"#eab308",info:"#3b82f6",healthy:"#22c55e",unnecessary:"#6b7280"},E={slow:1e3,fast:300,off:0},L={critical:"rgba(239, 68, 68, 0.35)",warning:"rgba(234, 179, 8, 0.3)",info:"rgba(59, 130, 246, 0.25)",healthy:"rgba(34, 197, 94, 0.2)",unnecessary:"rgba(107, 114, 128, 0.15)"},u=class{constructor(e={}){l(this,"shadowRoot",null);l(this,"host",null);l(this,"config");l(this,"highlights",new Map);l(this,"badges",new Map);l(this,"renderCounts",new Map);l(this,"toolbar",null);l(this,"visible",true);l(this,"totalRenders",0);this.config={...x,...e};}init(){this.host=document.createElement("div"),this.host.id="reactcheck-overlay-host",this.host.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: 0;
|
|
4
4
|
left: 0;
|
|
@@ -16,12 +16,65 @@ var ReactCheckInjector=(function(exports){'use strict';var C=Object.defineProper
|
|
|
16
16
|
pointer-events: none;
|
|
17
17
|
border-width: 2px;
|
|
18
18
|
border-style: solid;
|
|
19
|
-
transition: opacity 0.3s ease-out;
|
|
20
19
|
z-index: 1;
|
|
20
|
+
animation: highlight-pulse 0.5s ease-out;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
.highlight.fade {
|
|
24
24
|
opacity: 0;
|
|
25
|
+
transition: opacity 0.3s ease-out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.flash-overlay {
|
|
29
|
+
position: fixed;
|
|
30
|
+
pointer-events: none;
|
|
31
|
+
z-index: 0;
|
|
32
|
+
animation: flash-pulse 0.4s ease-out forwards;
|
|
33
|
+
border-radius: 4px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@keyframes flash-pulse {
|
|
37
|
+
0% {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
transform: scale(1);
|
|
40
|
+
}
|
|
41
|
+
50% {
|
|
42
|
+
opacity: 0.8;
|
|
43
|
+
transform: scale(1.02);
|
|
44
|
+
}
|
|
45
|
+
100% {
|
|
46
|
+
opacity: 0;
|
|
47
|
+
transform: scale(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@keyframes highlight-pulse {
|
|
52
|
+
0% {
|
|
53
|
+
opacity: 0;
|
|
54
|
+
box-shadow: 0 0 0 0 currentColor;
|
|
55
|
+
}
|
|
56
|
+
30% {
|
|
57
|
+
opacity: 1;
|
|
58
|
+
box-shadow: 0 0 8px 2px currentColor;
|
|
59
|
+
}
|
|
60
|
+
100% {
|
|
61
|
+
opacity: 1;
|
|
62
|
+
box-shadow: 0 0 0 0 transparent;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@keyframes badge-pop {
|
|
67
|
+
0% {
|
|
68
|
+
transform: scale(0.8);
|
|
69
|
+
opacity: 0;
|
|
70
|
+
}
|
|
71
|
+
50% {
|
|
72
|
+
transform: scale(1.1);
|
|
73
|
+
}
|
|
74
|
+
100% {
|
|
75
|
+
transform: scale(1);
|
|
76
|
+
opacity: 1;
|
|
77
|
+
}
|
|
25
78
|
}
|
|
26
79
|
|
|
27
80
|
.badge {
|
|
@@ -155,16 +208,24 @@ var ReactCheckInjector=(function(exports){'use strict';var C=Object.defineProper
|
|
|
155
208
|
<button class="toolbar-btn active" id="rc-badges">Badges</button>
|
|
156
209
|
<button class="toolbar-btn" id="rc-clear">Clear</button>
|
|
157
210
|
</div>
|
|
158
|
-
`,this.setupToolbarEvents(),this.makeDraggable(this.toolbar),this.shadowRoot.appendChild(this.toolbar));}setupToolbarEvents(){if(!this.toolbar||!this.shadowRoot)return;let e=this.toolbar.querySelector(".toolbar-close");e&&e.addEventListener("click",()=>{this.hide();});let t=this.shadowRoot.getElementById("rc-highlights");t&&t.addEventListener("click",()=>{this.config.highlightRenders=!this.config.highlightRenders,t.classList.toggle("active",this.config.highlightRenders),this.config.highlightRenders||this.clearHighlights();});let n=this.shadowRoot.getElementById("rc-badges");n&&n.addEventListener("click",()=>{this.config.showBadges=!this.config.showBadges,n.classList.toggle("active",this.config.showBadges),this.config.showBadges||this.clearBadges();});let o=this.shadowRoot.getElementById("rc-clear");o&&o.addEventListener("click",()=>{this.clear();});}makeDraggable(e){let t=false,n=0,o=0,s=0,
|
|
211
|
+
`,this.setupToolbarEvents(),this.makeDraggable(this.toolbar),this.shadowRoot.appendChild(this.toolbar));}setupToolbarEvents(){if(!this.toolbar||!this.shadowRoot)return;let e=this.toolbar.querySelector(".toolbar-close");e&&e.addEventListener("click",()=>{this.hide();});let t=this.shadowRoot.getElementById("rc-highlights");t&&t.addEventListener("click",()=>{this.config.highlightRenders=!this.config.highlightRenders,t.classList.toggle("active",this.config.highlightRenders),this.config.highlightRenders||this.clearHighlights();});let n=this.shadowRoot.getElementById("rc-badges");n&&n.addEventListener("click",()=>{this.config.showBadges=!this.config.showBadges,n.classList.toggle("active",this.config.showBadges),this.config.showBadges||this.clearBadges();});let o=this.shadowRoot.getElementById("rc-clear");o&&o.addEventListener("click",()=>{this.clear();});}makeDraggable(e){let t=false,n=0,o=0,s=0,a=0;e.addEventListener("mousedown",r=>{r.target.tagName!=="BUTTON"&&(t=true,n=r.clientX,o=r.clientY,s=e.offsetLeft,a=e.offsetTop);}),document.addEventListener("mousemove",r=>{if(!t)return;let h=r.clientX-n,g=r.clientY-o;e.style.left=`${s+h}px`,e.style.top=`${a+g}px`,e.style.right="auto";}),document.addEventListener("mouseup",()=>{t=false;});}highlight(e,t){if(!this.config.highlightRenders||!this.shadowRoot||!this.visible)return;let n=t.getBoundingClientRect();if(n.width===0||n.height===0)return;let o=this.getSeverity(e),s=T[o],a=L[o];this.createFlashOverlay(n,a);let r=this.highlights.get(e.componentName);r||(r=document.createElement("div"),r.className="highlight",this.shadowRoot.appendChild(r),this.highlights.set(e.componentName,r)),r.style.animation="none",r.offsetHeight,r.style.animation="",r.style.cssText=`
|
|
159
212
|
position: fixed;
|
|
160
213
|
left: ${n.left}px;
|
|
161
214
|
top: ${n.top}px;
|
|
162
215
|
width: ${n.width}px;
|
|
163
216
|
height: ${n.height}px;
|
|
164
217
|
border: 2px solid ${s};
|
|
218
|
+
color: ${s};
|
|
165
219
|
pointer-events: none;
|
|
166
220
|
z-index: 1;
|
|
167
|
-
|
|
221
|
+
animation: highlight-pulse 0.5s ease-out;
|
|
222
|
+
`,r.classList.remove("fade");let h=E[this.config.animationSpeed];h>0&&setTimeout(()=>{r?.classList.add("fade");},h),this.config.showBadges&&this.updateBadge(e,n,s),this.updateStats();}createFlashOverlay(e,t){if(!this.shadowRoot)return;let n=document.createElement("div");n.className="flash-overlay",n.style.cssText=`
|
|
223
|
+
left: ${e.left}px;
|
|
224
|
+
top: ${e.top}px;
|
|
225
|
+
width: ${e.width}px;
|
|
226
|
+
height: ${e.height}px;
|
|
227
|
+
background: ${t};
|
|
228
|
+
`,this.shadowRoot.appendChild(n),setTimeout(()=>{n.remove();},500);}updateBadge(e,t,n){if(!this.shadowRoot)return;let o=(this.renderCounts.get(e.componentName)??0)+1;this.renderCounts.set(e.componentName,o);let s=this.badges.get(e.componentName);s||(s=document.createElement("div"),s.className="badge",this.shadowRoot.appendChild(s),this.badges.set(e.componentName,s));let a=!this.badges.has(e.componentName);s.textContent=`${e.componentName}: ${o}`,s.style.cssText=`
|
|
168
229
|
position: fixed;
|
|
169
230
|
left: ${t.left}px;
|
|
170
231
|
top: ${Math.max(0,t.top-20)}px;
|
|
@@ -178,5 +239,6 @@ var ReactCheckInjector=(function(exports){'use strict';var C=Object.defineProper
|
|
|
178
239
|
pointer-events: none;
|
|
179
240
|
z-index: 2;
|
|
180
241
|
white-space: nowrap;
|
|
181
|
-
|
|
182
|
-
|
|
242
|
+
${a?"animation: badge-pop 0.3s ease-out;":""}
|
|
243
|
+
`,a||(s.style.transform="scale(1.15)",setTimeout(()=>{s&&(s.style.transform="scale(1)");},150));}getSeverity(e){return e.necessary?e.renderCount>50?"critical":e.renderCount>20?"warning":"healthy":"unnecessary"}recordRender(e){let t=(this.renderCounts.get(e.componentName)??0)+1;this.renderCounts.set(e.componentName,t),this.totalRenders++,this.updateStats();}updateStats(){if(!this.shadowRoot)return;let e=0,t=0,n=0;for(let[,h]of this.renderCounts)h>50?e++:h>20?t++:n++;let o=this.shadowRoot.getElementById("rc-critical"),s=this.shadowRoot.getElementById("rc-warning"),a=this.shadowRoot.getElementById("rc-healthy"),r=this.shadowRoot.getElementById("rc-renders");o&&(o.textContent=String(e)),s&&(s.textContent=String(t)),a&&(a.textContent=String(n)),r&&(r.textContent=String(this.totalRenders));}clearHighlights(){for(let e of this.highlights.values())e.remove();this.highlights.clear();}clearBadges(){for(let e of this.badges.values())e.remove();this.badges.clear();}clear(){this.clearHighlights(),this.clearBadges(),this.renderCounts.clear(),this.totalRenders=0,this.updateStats();}show(){this.host&&(this.host.style.display="block",this.visible=true);}hide(){this.host&&(this.host.style.display="none",this.visible=false);}toggle(){this.visible?this.hide():this.show();}configure(e){this.config={...this.config,...e};}isVisible(){return this.visible}};var S={trackUnnecessary:true,fpsThreshold:30,highlightRenders:true,animationSpeed:"fast"},v=class extends p{constructor(t={},n){super();l(this,"config");l(this,"running",false);l(this,"reactVersion","unknown");l(this,"prevFiberStates",new WeakMap);l(this,"renderCounts",new Map);l(this,"originalOnCommitFiberRoot",null);l(this,"win");l(this,"overlay",null);this.config={...S,...t},this.win=n??(typeof window<"u"?window:{});}getDOMElement(t){if(t.stateNode instanceof Element)return t.stateNode;let n=t.child;for(;n;){if(n.stateNode instanceof Element)return n.stateNode;if(n.child)n=n.child;else if(n.sibling)n=n.sibling;else {let o=n.return;for(;o&&o!==t&&!o.sibling;)o=o.return;n=o&&o!==t?o.sibling:null;}}return null}enableOverlay(){this.overlay||(this.overlay=new u({enabled:true,highlightRenders:this.config.highlightRenders??true,animationSpeed:this.config.animationSpeed??"fast",showBadges:true,showToolbar:true}),this.overlay.init());}disableOverlay(){this.overlay&&(this.overlay.destroy(),this.overlay=null);}getOverlay(){return this.overlay}start(){if(!this.running)try{this.hookIntoReact(),this.running=!0;}catch(t){this.emit("error",t instanceof Error?t:new Error(String(t)));}}stop(){this.running&&(this.unhookFromReact(),this.disableOverlay(),this.running=false);}reset(){this.renderCounts.clear(),this.prevFiberStates=new WeakMap;}hookIntoReact(){let t=this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!t){this.installHook();return}this.originalOnCommitFiberRoot=t.onCommitFiberRoot.bind(t),t.onCommitFiberRoot=(n,o,s)=>{this.originalOnCommitFiberRoot&&this.originalOnCommitFiberRoot(n,o,s),this.processCommit(o.current);},this.reactVersion=this.detectReactVersion(t),this.emit("ready",{reactVersion:this.reactVersion});}installHook(){let t={renderers:new Map,supportsFiber:true,inject:n=>{let o=t.renderers.size+1;return t.renderers.set(o,n),o},onCommitFiberRoot:(n,o,s)=>{this.processCommit(o.current);},onCommitFiberUnmount:()=>{}};this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__=t,this.emit("ready",{reactVersion:"unknown (hook installed)"});}unhookFromReact(){let t=this.win.__REACT_DEVTOOLS_GLOBAL_HOOK__;t&&this.originalOnCommitFiberRoot&&(t.onCommitFiberRoot=this.originalOnCommitFiberRoot,this.originalOnCommitFiberRoot=null);}detectReactVersion(t){if(t.renderers.size===0)return "unknown";let n=t.renderers.values().next().value;return n&&typeof n=="object"&&"version"in n?String(n.version):"unknown"}processCommit(t){this.walkFiber(t,null);}walkFiber(t,n){t&&(b(t)&&(this.processFiber(t,n),n=m(t)),this.walkFiber(t.child,n),this.walkFiber(t.sibling,n));}processFiber(t,n){let o=m(t);if(this.shouldFilterComponent(o))return;let s=this.prevFiberStates.get(t),r=w(t,s?"update":"mount",s?.props,s?.state),g=(this.renderCounts.get(o)??0)+1;if(this.renderCounts.set(o,g),r.renderCount=g,this.prevFiberStates.set(t,{props:t.memoizedProps,state:t.memoizedState}),this.overlay&&this.config.highlightRenders){let d=this.getDOMElement(t);d?this.overlay.highlight(r,d):this.overlay.recordRender(r);}this.emit("render",r);}shouldFilterComponent(t){if(t.startsWith("__")||t==="Fragment"||t==="Suspense"||t==="Profiler")return true;let{include:n,exclude:o}=this.config;return !!(n&&n.length>0&&!n.some(a=>this.matchPattern(t,a))||o&&o.length>0&&o.some(a=>this.matchPattern(t,a)))}matchPattern(t,n){let o=n.replace(/\*/g,".*").replace(/\?/g,".");try{return new RegExp(`^${o}$`).test(t)}catch{return false}}getConfig(){return {...this.config}}configure(t){this.config={...this.config,...t};}isRunning(){return this.running}getReactVersion(){return this.reactVersion}getRenderCount(t){return this.renderCounts.get(t)??0}getAllRenderCounts(){return new Map(this.renderCounts)}};var y=class{constructor(){l(this,"scanner");l(this,"overlay");l(this,"ws",null);l(this,"wsPort");l(this,"reconnectTimeout",null);l(this,"initialized",false);l(this,"messageQueue",[]);let e=window;this.wsPort=e.__REACTCHECK_PORT__??3099,this.scanner=new v({trackUnnecessary:true,highlightRenders:true,animationSpeed:"fast"},e),this.overlay=new u({enabled:true,highlightRenders:true,showBadges:true,showToolbar:true});}init(){if(this.initialized)return;this.initialized=true,this.overlay.init(),this.setupScannerEvents(),this.scanner.start(),this.connect();let e=this._markHookReady;e&&e(),console.log("[ReactCheck] Initialized");}setupScannerEvents(){this.scanner.on("render",e=>{this.send({type:"render",payload:e}),this.overlay.recordRender(e);let t=this.findDOMElement(e.componentName);t&&this.overlay.highlight(e,t);}),this.scanner.on("ready",e=>{this.send({type:"ready",payload:e});}),this.scanner.on("error",e=>{this.send({type:"error",payload:{message:e.message,code:"SCANNER_ERROR"}});});}connect(){this.ws&&this.ws.close();try{this.ws=new WebSocket(`ws://localhost:${this.wsPort}`),this.ws.onopen=()=>{console.log("[ReactCheck] Connected to CLI"),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.send({type:"ready",payload:{reactVersion:this.scanner.getReactVersion()}}),this.flushMessageQueue(),this.scanner.start();},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t);}catch(t){console.warn("[ReactCheck] Invalid message:",t);}},this.ws.onerror=e=>{console.warn("[ReactCheck] WebSocket error:",e);},this.ws.onclose=()=>{console.log("[ReactCheck] Disconnected from CLI"),this.scheduleReconnect();};}catch(e){console.warn("[ReactCheck] Failed to connect:",e),this.scheduleReconnect();}}scheduleReconnect(){this.reconnectTimeout||(this.reconnectTimeout=setTimeout(()=>{this.reconnectTimeout=null,console.log("[ReactCheck] Attempting to reconnect..."),this.connect();},2e3));}handleMessage(e){switch(e.type){case "start":this.scanner.start(),this.overlay.show();break;case "stop":this.scanner.stop();break;case "reset":this.scanner.reset(),this.overlay.clear();break;case "config":this.handleConfig(e.payload);break;case "highlight":break;case "toggle-overlay":this.handleToggleOverlay(e.payload.enabled);break}}handleToggleOverlay(e){e?(this.overlay.show(),this.overlay.configure({highlightRenders:true}),console.log("[ReactCheck] Overlay enabled")):(this.overlay.hide(),this.overlay.configure({highlightRenders:false}),console.log("[ReactCheck] Overlay disabled"));}isOverlayEnabled(){return this.overlay.isVisible()}toggleOverlay(){let e=!this.overlay.isVisible();this.handleToggleOverlay(e);}handleConfig(e){this.scanner.configure(e),e.highlightRenders!==void 0&&this.overlay.configure({highlightRenders:e.highlightRenders}),e.animationSpeed!==void 0&&this.overlay.configure({animationSpeed:e.animationSpeed});}send(e){this.ws&&this.ws.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(e)):this.messageQueue.push(e);}flushMessageQueue(){if(this.ws&&this.ws.readyState===WebSocket.OPEN&&this.messageQueue.length>0){for(let e of this.messageQueue)this.ws.send(JSON.stringify(e));this.messageQueue=[];}}findDOMElement(e){let t=document.querySelector(`[data-component="${e}"]`);if(t)return t;let n=document.querySelectorAll('[class*="'+e+'"]');return n.length>0?n[0]??null:null}destroy(){this.reconnectTimeout&&clearTimeout(this.reconnectTimeout),this.ws&&this.ws.close(),this.scanner.stop(),this.overlay.destroy(),this.initialized=false;}};(function(){let i=window;if(i.__REACTCHECK_INJECTED__)return;i.__REACTCHECK_INJECTED__=true;let e=new y;if(!i.__REACT_DEVTOOLS_GLOBAL_HOOK__){let t=[],n=false,o={renderers:new Map,supportsFiber:true,inject:function(s){let a=this.renderers.size+1;return this.renderers.set(a,s),a},onCommitFiberRoot:function(s,a){if(n){let r=e.scanner;r&&r.processCommit(a.current);}else t.push({rendererID:s,root:a});},onCommitFiberUnmount:function(){},_processPending:function(){n=true;let s=e.scanner;if(s){for(let{root:a}of t)s.processCommit(a.current);t.length=0;}}};i.__REACT_DEVTOOLS_GLOBAL_HOOK__=o,console.log("[ReactCheck] DevTools hook installed"),e._markHookReady=()=>{o._processPending();};}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{e.init();}):e.init(),window.__REACTCHECK__=e;})();
|
|
244
|
+
exports.BrowserScanner=v;exports.Overlay=u;exports.ReactCheckInjector=y;return exports;})({});
|
package/dist/chain.d.cts
CHANGED
package/dist/chain.d.ts
CHANGED