react-pref-guard 0.1.0 → 0.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/README.md +247 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
|
|
2
|
+
# ⚡ React Pref Guard (PerfGuard)
|
|
3
|
+
|
|
4
|
+
A developer-first performance guardrail for **React & Next.js** applications.
|
|
5
|
+
|
|
6
|
+
Pref Guard continuously monitors how your components render during development and automatically detects performance problems, regressions, and UX issues — before they reach production.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ What is Pref Guard?
|
|
11
|
+
|
|
12
|
+
Pref Guard (Performance Guard) is a **development-only runtime performance analysis tool** for React.
|
|
13
|
+
|
|
14
|
+
It observes real renders, applies a rule engine, and reports actionable performance issues with confidence scoring, trend detection, and noise suppression.
|
|
15
|
+
|
|
16
|
+
Unlike traditional profilers, Pref Guard runs continuously and automatically while you build features.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ❓ What problem does Pref Guard solve?
|
|
21
|
+
|
|
22
|
+
### The problem today
|
|
23
|
+
- React DevTools Profiler is manual
|
|
24
|
+
- Lighthouse runs after performance is already bad
|
|
25
|
+
- Performance regressions silently slip in
|
|
26
|
+
- Console logs are noisy and repetitive
|
|
27
|
+
- Teams ship UX regressions unknowingly
|
|
28
|
+
|
|
29
|
+
### What Pref Guard does differently
|
|
30
|
+
|
|
31
|
+
| Traditional Tools | Pref Guard |
|
|
32
|
+
|------------------|------------|
|
|
33
|
+
| Manual profiling | Automatic detection |
|
|
34
|
+
| One-time snapshots | Continuous monitoring |
|
|
35
|
+
| Raw numbers | Rule-based insights |
|
|
36
|
+
| Console spam | Deduplicated, structured issues |
|
|
37
|
+
| No history | Regression + trend detection |
|
|
38
|
+
|
|
39
|
+
**Pref Guard makes performance a first-class development signal.**
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🔑 Key Features
|
|
44
|
+
|
|
45
|
+
- Automatic performance detection
|
|
46
|
+
- Regression & trend analysis
|
|
47
|
+
- Confidence-based rule engine
|
|
48
|
+
- Boundary-aware severity tuning
|
|
49
|
+
- Noise-free reporting
|
|
50
|
+
- Visual PerfGuard Panel
|
|
51
|
+
- Dev-only, production-safe
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 🧱 How Pref Guard Works
|
|
56
|
+
|
|
57
|
+
React Profiler
|
|
58
|
+
→ Metric Collector
|
|
59
|
+
→ Analyzer Worker (Rules Engine)
|
|
60
|
+
→ Issue Reporter
|
|
61
|
+
→ PerfGuard Panel + Alerts
|
|
62
|
+
|
|
63
|
+
Heavy analysis runs in a Web Worker to avoid UI blocking.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 📦 Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install react-pref-guard
|
|
71
|
+
# or
|
|
72
|
+
pnpm add react-pref-guard
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🚀 Quick Start (React)
|
|
78
|
+
|
|
79
|
+
### 1️⃣ Wrap your app
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
import { PerfProvider } from "react-pref-guard";
|
|
83
|
+
|
|
84
|
+
export function App() {
|
|
85
|
+
return (
|
|
86
|
+
<PerfProvider>
|
|
87
|
+
<YourApp />
|
|
88
|
+
</PerfProvider>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Pref Guard disables itself automatically in production.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### 2️⃣ (Optional) Wrap heavy components
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { withPerfGuard } from "react-pref-guard";
|
|
101
|
+
|
|
102
|
+
function HeavyComponent() {
|
|
103
|
+
return <div>Expensive UI</div>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default withPerfGuard(HeavyComponent);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 🖥️ PerfGuard Panel
|
|
112
|
+
|
|
113
|
+
The PerfGuard Panel appears automatically in development and shows:
|
|
114
|
+
- All detected issues
|
|
115
|
+
- Severity (LOW → CRITICAL)
|
|
116
|
+
- Confidence score
|
|
117
|
+
- Active vs Resolved lifecycle
|
|
118
|
+
- Component name and rule
|
|
119
|
+
|
|
120
|
+
It acts as the **single source of truth** for performance issues.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🚨 Critical Alerts
|
|
125
|
+
|
|
126
|
+
Critical issues:
|
|
127
|
+
- Show a visual overlay
|
|
128
|
+
- Are logged once per lifecycle
|
|
129
|
+
- Are also stored and shown in the panel
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 🎯 Boundary Types
|
|
134
|
+
|
|
135
|
+
| Boundary | Meaning |
|
|
136
|
+
|--------|---------|
|
|
137
|
+
| INLINE | Small child component |
|
|
138
|
+
| HOC | Wrapped or logical boundary |
|
|
139
|
+
| PAGE | Route-level component |
|
|
140
|
+
|
|
141
|
+
Inline components are softened automatically to reduce noise.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 🔒 Production Safety
|
|
146
|
+
|
|
147
|
+
- Disabled automatically in production
|
|
148
|
+
- No workers, no profiler, no overhead
|
|
149
|
+
- Safe to deploy
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
# ⚡ Using Pref Guard with Next.js
|
|
154
|
+
|
|
155
|
+
Pref Guard works with both **Pages Router** and **App Router**.
|
|
156
|
+
|
|
157
|
+
> Client-only, SSR-safe, RSC-safe
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Next.js – Pages Router
|
|
162
|
+
|
|
163
|
+
### Wrap `_app.tsx`
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import type { AppProps } from "next/app";
|
|
167
|
+
import { PerfProvider } from "react-pref-guard";
|
|
168
|
+
|
|
169
|
+
export default function MyApp({ Component, pageProps }: AppProps) {
|
|
170
|
+
return (
|
|
171
|
+
<PerfProvider>
|
|
172
|
+
<Component {...pageProps} />
|
|
173
|
+
</PerfProvider>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Next.js – App Router
|
|
181
|
+
|
|
182
|
+
### Create provider
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
"use client";
|
|
186
|
+
import { PerfProvider } from "react-pref-guard";
|
|
187
|
+
|
|
188
|
+
export function Providers({ children }) {
|
|
189
|
+
return <PerfProvider>{children}</PerfProvider>;
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Use in layout
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
import { Providers } from "./providers";
|
|
197
|
+
|
|
198
|
+
export default function RootLayout({ children }) {
|
|
199
|
+
return (
|
|
200
|
+
<html>
|
|
201
|
+
<body>
|
|
202
|
+
<Providers>{children}</Providers>
|
|
203
|
+
</body>
|
|
204
|
+
</html>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 🧪 Testing
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
"use client";
|
|
215
|
+
|
|
216
|
+
export function SlowComponent() {
|
|
217
|
+
const start = performance.now();
|
|
218
|
+
while (performance.now() - start < 120) {}
|
|
219
|
+
return <div>Slow render</div>;
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Use this component and observe the PerfGuard Panel.
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## 🛣️ Roadmap
|
|
228
|
+
|
|
229
|
+
- React Router auto integration
|
|
230
|
+
- Next.js preset
|
|
231
|
+
- CI performance gates
|
|
232
|
+
- Exportable reports
|
|
233
|
+
- Rule customization
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## 📄 License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## ⭐ Final Note
|
|
244
|
+
|
|
245
|
+
Performance should fail **early**, **clearly**, and **with context**.
|
|
246
|
+
|
|
247
|
+
Pref Guard makes performance a daily habit — not a late-stage fire drill.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-pref-guard",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Dev-only performance guardrail for React and Next.js using React Profiler",
|
|
5
5
|
"author": "Amiya Das",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"react-dom": ">=17"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
28
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
29
29
|
"prepublishOnly": "pnpm clean && pnpm build",
|
|
30
30
|
"dev": "tsup --watch",
|