@devlens/react 2.0.0 → 2.0.2

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.
Files changed (2) hide show
  1. package/README.md +156 -21
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # @devlens/react
2
2
 
3
- DevLens React integration -- automatic runtime error detection for React applications.
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.**
4
19
 
5
20
  ## Installation
6
21
 
@@ -8,9 +23,9 @@ DevLens React integration -- automatic runtime error detection for React applica
8
23
  npm install @devlens/core @devlens/react
9
24
  ```
10
25
 
11
- **Peer dependencies:** React >= 17.0.0
26
+ **Requirements:** React >= 17.0.0
12
27
 
13
- ## Quick Start
28
+ ## Setup -- 30 Seconds
14
29
 
15
30
  ```tsx
16
31
  import { DevLensProvider, DevLensErrorBoundary } from '@devlens/react';
@@ -26,9 +41,14 @@ function App() {
26
41
  }
27
42
  ```
28
43
 
29
- ## Guarded State
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
30
50
 
31
- Automatically detect null/undefined access on state objects:
51
+ Replace `useState` with `useGuardedState`. Same API, but now null/undefined property access is detected automatically:
32
52
 
33
53
  ```tsx
34
54
  import { useGuardedState } from '@devlens/react';
@@ -36,44 +56,159 @@ import { useGuardedState } from '@devlens/react';
36
56
  function UserProfile() {
37
57
  const [user, setUser] = useGuardedState(initialUser, 'UserProfile');
38
58
 
39
- // If user.profile.avatar is null, DevLens auto-logs:
40
- // [NULL] DevLens [WARN] null-access: Property "avatar" is null at path "user.profile.avatar"
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
+
41
68
  return <img src={user.profile.avatar} />;
42
69
  }
43
70
  ```
44
71
 
45
- ## Watch Render Data
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
46
75
 
47
- Monitor multiple values for null/undefined:
76
+ Monitor multiple values for null/undefined. Perfect for components that depend on async data:
48
77
 
49
78
  ```tsx
50
79
  import { useGuardedEffect } from '@devlens/react';
51
80
 
52
81
  function Dashboard({ user, posts, settings }) {
82
+ // Watch all data dependencies in one call
53
83
  useGuardedEffect({ user, posts, settings }, 'Dashboard');
54
84
 
85
+ // If posts is undefined (still loading), DevLens logs:
86
+ //
55
87
  // [RENDER] DevLens [WARN] render-data: "posts" is undefined in Dashboard
56
- return <div>...</div>;
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
+ );
57
98
  }
58
99
  ```
59
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
+
60
161
  ## API Reference
61
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
+
62
172
  | Export | Description |
63
173
  |--------|-------------|
64
- | `DevLensProvider` | Wrapper component, initializes DevLens |
65
- | `DevLensErrorBoundary` | Error boundary with DevLens reporting |
66
- | `useDevLens()` | Access the engine instance |
67
- | `useGuardedState(initial, label?)` | useState with null/undefined detection |
68
- | `useGuardedEffect(data, label?)` | Watch data for null/undefined |
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
69
204
 
70
- ## Details
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 |
71
209
 
72
- - ~5KB ESM bundle
73
- - Dual ESM + CJS output
74
- - Full TypeScript declarations
75
- - Production-safe -- auto-disabled in production
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.
76
211
 
77
212
  ## License
78
213
 
79
- MIT -- [github.com/crashsense/devlens](https://github.com/crashsense/devlens)
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": "2.0.0",
3
+ "version": "2.0.2",
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": "2.0.0"
60
+ "@devlens/core": "2.0.2"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "^25.3.0",