react-state-basis 0.4.0 β 0.4.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.
- package/README.md +37 -56
- package/dist/index.d.mts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +316 -190
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -190
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
|
|
7
7
|
# π react-state-basis
|
|
8
|
-
### Runtime
|
|
8
|
+
### Runtime Architectural Auditor & State Profiler for React
|
|
9
9
|
|
|
10
10
|
[](https://www.npmjs.com/package/react-state-basis)
|
|
11
11
|
[](https://github.com/liovic/react-state-basis/stargazers)
|
|
12
12
|
[](https://opensource.org/licenses/MIT)
|
|
13
13
|
|
|
14
|
-
**
|
|
14
|
+
**Basis tracks the rhythm of state updates, not the data. It identifies redundant patterns and sync-leaks that standard tools miss.**
|
|
15
|
+
|
|
16
|
+
> Stop relying on architectural intuition. Start measuring architectural debt.
|
|
15
17
|
|
|
16
18
|
</div>
|
|
17
19
|
|
|
@@ -52,7 +54,7 @@ const isLoggedIn = !!user; // Computed, no second render
|
|
|
52
54
|
The optional HUD shows your state basis matrix in real-time:
|
|
53
55
|
|
|
54
56
|
<p align="center">
|
|
55
|
-
<img src="./assets/react-state-basis.gif" width="800" alt="React State Basis Demo" />
|
|
57
|
+
<img src="./assets/react-state-basis-demo.gif" width="800" alt="React State Basis Demo" />
|
|
56
58
|
</p>
|
|
57
59
|
|
|
58
60
|
---
|
|
@@ -177,9 +179,19 @@ Shows:
|
|
|
177
179
|
- **Synchronized Clusters** - Groups of variables that move together
|
|
178
180
|
- **Correlation Matrix** - Full pairwise similarity analysis (for <15 variables)
|
|
179
181
|
|
|
182
|
+
### Hardware Telemetry
|
|
183
|
+
|
|
184
|
+
Verify engine efficiency and heap stability in real-time:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
window.getBasisMetrics();
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Returns: Engine execution time, active hook count, and current memory allocation strategy.
|
|
191
|
+
|
|
180
192
|
---
|
|
181
193
|
|
|
182
|
-
## How It Works (v0.4.
|
|
194
|
+
## How It Works (v0.4.x)
|
|
183
195
|
|
|
184
196
|
### Temporal Cross-Correlation
|
|
185
197
|
|
|
@@ -253,25 +265,6 @@ const isLoggedIn = !!user; // Derived, no effect needed
|
|
|
253
265
|
|
|
254
266
|
---
|
|
255
267
|
|
|
256
|
-
## Upgrading from v0.3.x
|
|
257
|
-
|
|
258
|
-
### Breaking Changes
|
|
259
|
-
None! v0.4.0 is a drop-in replacement.
|
|
260
|
-
|
|
261
|
-
### What's Different
|
|
262
|
-
- **Better Detection:** Temporal analysis reduces false positives by distinguishing redundancy from causality
|
|
263
|
-
- **New Alert Type:** "DETECTED SYNC LEAK" identifies effect-driven update chains with directional insight
|
|
264
|
-
- **Console Throttling:** Same pair won't spam console (5-second cooldown between identical alerts)
|
|
265
|
-
- **Idle Filtering:** Variables that haven't updated are excluded from analysis
|
|
266
|
-
|
|
267
|
-
### Action Required
|
|
268
|
-
None. Just update the package and restart your dev server.
|
|
269
|
-
```bash
|
|
270
|
-
npm update react-state-basis
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
---
|
|
274
|
-
|
|
275
268
|
## Production Safety
|
|
276
269
|
|
|
277
270
|
In production builds, the entire tool is replaced with zero-op shims. **Zero runtime overhead. Zero bundle size increase.**
|
|
@@ -293,7 +286,7 @@ In production builds, the entire tool is replaced with zero-op shims. **Zero run
|
|
|
293
286
|
Add `// @basis-ignore` at the top of a file to disable instrumentation:
|
|
294
287
|
```tsx
|
|
295
288
|
// @basis-ignore
|
|
296
|
-
// This file
|
|
289
|
+
// This file contains external protocols or hardware-bound synchronization outside the scope of architectural auditing.
|
|
297
290
|
```
|
|
298
291
|
|
|
299
292
|
**Good candidates for skipping:**
|
|
@@ -322,24 +315,27 @@ These tools are complementary - use them together for best results.
|
|
|
322
315
|
|
|
323
316
|
**Development Mode**
|
|
324
317
|
|
|
325
|
-
|
|
318
|
+
**Basis is designed to be statistically invisible to the main thread.**
|
|
319
|
+
|
|
320
|
+
The v0.4.2 **Flat Memory Architecture** utilizes `Uint8Array` Ring Buffers to eliminate Garbage Collection (GC) churn and provide constant-time $O(1)$ telemetry recording.
|
|
326
321
|
|
|
327
|
-
|
|
322
|
+
### Audited Benchmarks
|
|
328
323
|
|
|
329
|
-
**
|
|
324
|
+
These metrics were recorded during a **20-minute high-frequency endurance audit** (1.2M state pulses) using the built-in **Stress Lab**.
|
|
330
325
|
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
326
|
+
* **Logic Execution Overhead:** < 1.0ms per 100-hook update cycle.
|
|
327
|
+
* **Memory Profile:** **0 Delta heap growth.** (Static allocation via Ring Buffers).
|
|
328
|
+
* **Interaction Latency (INP):** ~56ms during continuous 50-hook concurrency tests (Green Zone).
|
|
329
|
+
* **Drawing Efficiency:** ~15ms drawing cost via Path2D GPU-batching.
|
|
335
330
|
|
|
336
|
-
>
|
|
331
|
+
> π **Forensic Proof:** Detailed heap snapshots, modulo-tax analysis, and linearized math benchmarks are documented in the [**v0.4.2 Performance RFC (#33)**](https://github.com/liovic/react-state-basis/issues/33).
|
|
337
332
|
|
|
338
333
|
<p align="center">
|
|
339
|
-
<img src="./assets/
|
|
334
|
+
<img src="./assets/perf.gif" width="800" alt="Basis Stress Lab" />
|
|
340
335
|
</p>
|
|
341
336
|
|
|
342
337
|
|
|
338
|
+
|
|
343
339
|
**Production Mode:**
|
|
344
340
|
- Overhead: ~0.01ms per hook call (negligible wrapper overhead)
|
|
345
341
|
- Bundle size: ~2-3 KB minified (no-op wrappers only, no analysis engine)
|
|
@@ -348,7 +344,7 @@ Location: `/example`
|
|
|
348
344
|
|
|
349
345
|
---
|
|
350
346
|
|
|
351
|
-
## Limitations (v0.4.
|
|
347
|
+
## Limitations (v0.4.x)
|
|
352
348
|
|
|
353
349
|
**What works well:**
|
|
354
350
|
- β
Detecting synchronous redundant state
|
|
@@ -362,16 +358,21 @@ Location: `/example`
|
|
|
362
358
|
- β οΈ **Complex multi-way dependencies:** Three or more interconnected states might not show full relationship graph
|
|
363
359
|
- β οΈ **Requires judgment:** Tool points out patterns worth investigating - you decide if they're issues
|
|
364
360
|
|
|
365
|
-
**
|
|
361
|
+
**Heuristic interpretation requires context. Always verify architectural intent before refactoring.**.
|
|
366
362
|
|
|
367
363
|
---
|
|
368
364
|
|
|
369
365
|
## Roadmap
|
|
370
366
|
|
|
367
|
+
### v0.4.x
|
|
368
|
+
- [x] **v0.4.0**: Temporal Cross-Correlation Engine (Lead-Lag Analysis)
|
|
369
|
+
- [x] **v0.4.1:** Density Filtering (Eliminate false positives from animations/sliders)
|
|
370
|
+
- [x] v0.4.2: Ring Buffer (Zero-jank memory management for 500+ hooks) [**v0.4.2 Performance RFC (#33)**](https://github.com/liovic/react-state-basis/issues/33)
|
|
371
|
+
|
|
372
|
+
|
|
371
373
|
### v0.5.0 (Planned)
|
|
372
374
|
- [ ] Zustand & Redux middleware integration
|
|
373
375
|
- [ ] Visual dependency graph in HUD
|
|
374
|
-
- [ ] Automated fix suggestions with one-click apply
|
|
375
376
|
- [ ] Historical trend tracking across sessions
|
|
376
377
|
|
|
377
378
|
### Future Ideas
|
|
@@ -381,26 +382,6 @@ Location: `/example`
|
|
|
381
382
|
|
|
382
383
|
---
|
|
383
384
|
|
|
384
|
-
## Troubleshooting
|
|
385
|
-
|
|
386
|
-
**"I'm not seeing any alerts"**
|
|
387
|
-
1. Verify `debug={true}` is set in `<BasisProvider>`
|
|
388
|
-
2. Check that the Babel plugin is loaded (restart dev server after config changes)
|
|
389
|
-
3. Create a test pattern (see "Verify It's Working" section)
|
|
390
|
-
4. Open browser console and look for `Basis Auditor | Structural Relationship Check`
|
|
391
|
-
|
|
392
|
-
**"Too many alerts"**
|
|
393
|
-
- Use `// @basis-ignore` for animation-heavy files
|
|
394
|
-
- Check if your app has intentional state synchronization patterns
|
|
395
|
-
- Consider if alerts are revealing actual architectural issues
|
|
396
|
-
|
|
397
|
-
**"Alert says 'sync leak' but I need that effect"**
|
|
398
|
-
- Some effects are necessary (e.g., syncing to localStorage)
|
|
399
|
-
- Basis flags patterns, not bugs - use your judgment
|
|
400
|
-
- If it's intentional, add a comment explaining why
|
|
401
|
-
|
|
402
|
-
---
|
|
403
|
-
|
|
404
385
|
## FAQ
|
|
405
386
|
|
|
406
387
|
**Q: Will this slow down my app?**
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,18 @@ import React__default, { ReactNode } from 'react';
|
|
|
3
3
|
export { basis } from './vite-plugin.mjs';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
|
+
declare const configureBasis: (c: any) => void;
|
|
7
|
+
/**
|
|
8
|
+
* DISPLAY: window.printBasisReport()
|
|
9
|
+
*/
|
|
10
|
+
declare const printBasisHealthReport: (threshold?: number) => void;
|
|
11
|
+
declare const getBasisMetrics: () => {
|
|
12
|
+
engine: string;
|
|
13
|
+
hooks: number;
|
|
14
|
+
load: number;
|
|
15
|
+
analysis_ms: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
type GetReducerState<R extends React.Reducer<any, any>> = R extends React.Reducer<infer S, any> ? S : never;
|
|
7
19
|
type GetReducerAction<R extends React.Reducer<any, any>> = R extends React.Reducer<any, infer A> ? A : never;
|
|
8
20
|
declare function useState<S>(initialState: S | (() => S), label?: string): [S, React.Dispatch<React.SetStateAction<S>>];
|
|
@@ -34,9 +46,4 @@ declare const useBasisConfig: () => {
|
|
|
34
46
|
debug: boolean;
|
|
35
47
|
};
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
debug: boolean;
|
|
39
|
-
}>) => void;
|
|
40
|
-
declare const printBasisHealthReport: (threshold?: number) => void;
|
|
41
|
-
|
|
42
|
-
export { BasisProvider, configureBasis, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
|
49
|
+
export { BasisProvider, configureBasis, getBasisMetrics, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,18 @@ import React__default, { ReactNode } from 'react';
|
|
|
3
3
|
export { basis } from './vite-plugin.js';
|
|
4
4
|
import 'vite';
|
|
5
5
|
|
|
6
|
+
declare const configureBasis: (c: any) => void;
|
|
7
|
+
/**
|
|
8
|
+
* DISPLAY: window.printBasisReport()
|
|
9
|
+
*/
|
|
10
|
+
declare const printBasisHealthReport: (threshold?: number) => void;
|
|
11
|
+
declare const getBasisMetrics: () => {
|
|
12
|
+
engine: string;
|
|
13
|
+
hooks: number;
|
|
14
|
+
load: number;
|
|
15
|
+
analysis_ms: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
6
18
|
type GetReducerState<R extends React.Reducer<any, any>> = R extends React.Reducer<infer S, any> ? S : never;
|
|
7
19
|
type GetReducerAction<R extends React.Reducer<any, any>> = R extends React.Reducer<any, infer A> ? A : never;
|
|
8
20
|
declare function useState<S>(initialState: S | (() => S), label?: string): [S, React.Dispatch<React.SetStateAction<S>>];
|
|
@@ -34,9 +46,4 @@ declare const useBasisConfig: () => {
|
|
|
34
46
|
debug: boolean;
|
|
35
47
|
};
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
debug: boolean;
|
|
39
|
-
}>) => void;
|
|
40
|
-
declare const printBasisHealthReport: (threshold?: number) => void;
|
|
41
|
-
|
|
42
|
-
export { BasisProvider, configureBasis, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|
|
49
|
+
export { BasisProvider, configureBasis, getBasisMetrics, printBasisHealthReport, use, useActionState, useBasisConfig, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition };
|