@devlens/react 1.0.0 → 2.0.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/README.md +214 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# @devlens/react
|
|
2
|
+
|
|
3
|
+
**Drop in two components. Never miss a silent failure in React again.**
|
|
4
|
+
|
|
5
|
+
Your `useEffect` fetches data, but `user.profile` comes back `null`. The page renders blank -- no error, no crash, just... nothing. You open DevTools, add 15 `console.log` statements, and finally find it 20 minutes later.
|
|
6
|
+
|
|
7
|
+
DevLens catches it the moment it happens. Two lines of setup. Zero config.
|
|
8
|
+
|
|
9
|
+
## The Problem
|
|
10
|
+
|
|
11
|
+
React is great at catching render errors, but terrible at surfacing data problems:
|
|
12
|
+
|
|
13
|
+
- API returns `null` instead of an object -- no error, blank UI
|
|
14
|
+
- A prop is `undefined` because a parent didn't load yet -- silent failure
|
|
15
|
+
- `fetch` returns 500 -- the Promise resolves, `.json()` fails silently
|
|
16
|
+
- A deeply nested property is `null` -- `Cannot read property of null` only after the user clicks
|
|
17
|
+
|
|
18
|
+
**DevLens surfaces all of these instantly, with full context, before your users notice.**
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @devlens/core @devlens/react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Requirements:** React >= 17.0.0
|
|
27
|
+
|
|
28
|
+
## Setup -- 30 Seconds
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { DevLensProvider, DevLensErrorBoundary } from '@devlens/react';
|
|
32
|
+
|
|
33
|
+
function App() {
|
|
34
|
+
return (
|
|
35
|
+
<DevLensProvider>
|
|
36
|
+
<DevLensErrorBoundary>
|
|
37
|
+
<YourApp />
|
|
38
|
+
</DevLensErrorBoundary>
|
|
39
|
+
</DevLensProvider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
That's it. Open your browser console. DevLens auto-installs:
|
|
45
|
+
- **Network interceptor** -- detects failed fetch/XHR calls
|
|
46
|
+
- **Global catcher** -- captures uncaught errors and unhandled rejections
|
|
47
|
+
- **Error boundary** -- catches React render errors with component stack traces
|
|
48
|
+
|
|
49
|
+
## Guarded State -- Catch Null Access Before It Crashes
|
|
50
|
+
|
|
51
|
+
Replace `useState` with `useGuardedState`. Same API, but now null/undefined property access is detected automatically:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { useGuardedState } from '@devlens/react';
|
|
55
|
+
|
|
56
|
+
function UserProfile() {
|
|
57
|
+
const [user, setUser] = useGuardedState(initialUser, 'UserProfile');
|
|
58
|
+
|
|
59
|
+
// If user.profile.avatar is null, DevLens immediately logs:
|
|
60
|
+
//
|
|
61
|
+
// [NULL] DevLens [WARN] null-access: Property "avatar" is null
|
|
62
|
+
// at path "user.profile.avatar"
|
|
63
|
+
// |- Path: user.profile.avatar
|
|
64
|
+
// |- Value: null
|
|
65
|
+
// |- Source: UserProfile
|
|
66
|
+
// \- Suggestion: Check if "avatar" is loaded/initialized before accessing
|
|
67
|
+
|
|
68
|
+
return <img src={user.profile.avatar} />;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**How it works:** `useGuardedState` wraps your state in an ES6 Proxy that detects null/undefined access at any depth. The original state is untouched -- the proxy only observes.
|
|
73
|
+
|
|
74
|
+
## Guarded Effect -- Watch Data Dependencies
|
|
75
|
+
|
|
76
|
+
Monitor multiple values for null/undefined. Perfect for components that depend on async data:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { useGuardedEffect } from '@devlens/react';
|
|
80
|
+
|
|
81
|
+
function Dashboard({ user, posts, settings }) {
|
|
82
|
+
// Watch all data dependencies in one call
|
|
83
|
+
useGuardedEffect({ user, posts, settings }, 'Dashboard');
|
|
84
|
+
|
|
85
|
+
// If posts is undefined (still loading), DevLens logs:
|
|
86
|
+
//
|
|
87
|
+
// [RENDER] DevLens [WARN] render-data: "posts" is undefined in Dashboard
|
|
88
|
+
// |- Path: Dashboard.posts
|
|
89
|
+
// |- Value: undefined
|
|
90
|
+
// \- Suggestion: "posts" is undefined -- check data loading in Dashboard
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<h1>{user.name}</h1>
|
|
95
|
+
{posts.map(p => <Post key={p.id} {...p} />)}
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Error Boundary -- Catch Render Crashes with Context
|
|
102
|
+
|
|
103
|
+
DevLens error boundary captures React render errors and reports them with full component stack traces:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { DevLensErrorBoundary } from '@devlens/react';
|
|
107
|
+
|
|
108
|
+
<DevLensErrorBoundary
|
|
109
|
+
fallback={(error, reset) => (
|
|
110
|
+
<div>
|
|
111
|
+
<h2>Something went wrong</h2>
|
|
112
|
+
<p>{error.message}</p>
|
|
113
|
+
<button onClick={reset}>Try Again</button>
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
onError={(error, errorInfo) => {
|
|
117
|
+
// Optional: send to your error tracking service
|
|
118
|
+
Sentry.captureException(error);
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<RiskyComponent />
|
|
122
|
+
</DevLensErrorBoundary>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Features:**
|
|
126
|
+
- Render prop fallback with `error` and `reset` function
|
|
127
|
+
- `onError` callback for external error tracking integration
|
|
128
|
+
- Auto-reports to DevLens engine with component stack
|
|
129
|
+
- Default fallback UI if no custom fallback provided
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
<DevLensProvider
|
|
135
|
+
config={{
|
|
136
|
+
enabled: true,
|
|
137
|
+
minSeverity: 'warn',
|
|
138
|
+
throttleMs: 1000,
|
|
139
|
+
maxIssues: 100,
|
|
140
|
+
modules: {
|
|
141
|
+
network: {
|
|
142
|
+
fetch: true,
|
|
143
|
+
xhr: true,
|
|
144
|
+
ignoreUrls: ['/health', /\.hot-update\./],
|
|
145
|
+
},
|
|
146
|
+
guardian: { maxDepth: 5 },
|
|
147
|
+
catcher: {
|
|
148
|
+
windowErrors: true,
|
|
149
|
+
unhandledRejections: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
ignore: {
|
|
153
|
+
messages: [/ResizeObserver/],
|
|
154
|
+
},
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
<App />
|
|
158
|
+
</DevLensProvider>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## API Reference
|
|
162
|
+
|
|
163
|
+
### Components
|
|
164
|
+
|
|
165
|
+
| Export | Description |
|
|
166
|
+
|--------|-------------|
|
|
167
|
+
| `DevLensProvider` | Wraps your app. Initializes the detection engine, network interceptor, and global catcher. Renders only `children` when disabled. |
|
|
168
|
+
| `DevLensErrorBoundary` | React error boundary that auto-reports to DevLens. Supports render prop fallback with reset, `onError` callback. |
|
|
169
|
+
|
|
170
|
+
### Hooks
|
|
171
|
+
|
|
172
|
+
| Export | Description |
|
|
173
|
+
|--------|-------------|
|
|
174
|
+
| `useDevLens()` | Returns the `DevLensEngine` instance (or `null` if disabled). Use for custom reporting. |
|
|
175
|
+
| `useGuardedState(initial, label?)` | Drop-in `useState` replacement. Wraps state in a Proxy to detect null/undefined property access at any depth. |
|
|
176
|
+
| `useGuardedEffect(data, label?)` | Watches a `Record<string, unknown>` for null/undefined values. Runs on every render. |
|
|
177
|
+
|
|
178
|
+
### Types
|
|
179
|
+
|
|
180
|
+
| Export | Description |
|
|
181
|
+
|--------|-------------|
|
|
182
|
+
| `DevLensProviderProps` | Props for `DevLensProvider` (`children`, `config?`) |
|
|
183
|
+
| `DevLensErrorBoundaryProps` | Props for `DevLensErrorBoundary` (`children`, `fallback?`, `onError?`) |
|
|
184
|
+
| `DevLensConfig` | Re-exported from `@devlens/core` |
|
|
185
|
+
| `DetectedIssue` | Re-exported from `@devlens/core` |
|
|
186
|
+
|
|
187
|
+
## Works With
|
|
188
|
+
|
|
189
|
+
- **React 17, 18, 19** -- all supported
|
|
190
|
+
- **Next.js** -- client components only (DevLens is browser-side)
|
|
191
|
+
- **Remix, Vite, CRA** -- any React setup
|
|
192
|
+
- **@devlens/ui** -- add the [visual debug panel](https://www.npmjs.com/package/@devlens/ui) for a full browser overlay
|
|
193
|
+
|
|
194
|
+
## Why @devlens/react
|
|
195
|
+
|
|
196
|
+
- **30-second setup** -- wrap your app, done
|
|
197
|
+
- **Zero config** -- detects network, null access, render data, errors out of the box
|
|
198
|
+
- **~5KB** ESM bundle -- barely noticeable
|
|
199
|
+
- **Production-safe** -- auto-disabled in production, zero overhead, tree-shakeable
|
|
200
|
+
- **Non-invasive** -- no patching React internals, clean Proxy-based detection
|
|
201
|
+
- **Full TypeScript** -- complete type declarations, strict mode compatible
|
|
202
|
+
|
|
203
|
+
## Roadmap
|
|
204
|
+
|
|
205
|
+
| Version | Feature | Status |
|
|
206
|
+
|---------|---------|--------|
|
|
207
|
+
| v2.0 | React integration with guarded hooks and error boundary | Current |
|
|
208
|
+
| v3.0 | AI-powered analysis -- integrate Claude and Gemini models to analyze detected issues and generate root-cause explanations with fix suggestions | Planned |
|
|
209
|
+
|
|
210
|
+
The v3.0 AI integration will analyze patterns across your detected issues, identify root causes, and suggest fixes -- directly in your dev console or UI panel.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT -- [GitHub](https://github.com/crashsense/devlens) -- [Changelog](https://github.com/crashsense/devlens/blob/main/CHANGELOG.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devlens/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "DevLens React integration - automatic error detection for React apps",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"react-dom": ">=17.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@devlens/core": "
|
|
60
|
+
"@devlens/core": "2.0.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^25.3.0",
|