react-state-basis 0.5.0 → 0.6.0

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 CHANGED
@@ -45,7 +45,10 @@ export default defineConfig({
45
45
  import { BasisProvider } from 'react-state-basis';
46
46
 
47
47
  root.render(
48
- <BasisProvider debug={true}>
48
+ <BasisProvider
49
+ debug={true}
50
+ showHUD={true} // Set to false for console-only forensics
51
+ >
49
52
  <App />
50
53
  </BasisProvider>
51
54
  );
@@ -59,42 +62,55 @@ const [a, setA] = useState(0);
59
62
  const [b, setB] = useState(0);
60
63
 
61
64
  useEffect(() => {
62
- setB(a); // ⚡ BASIS: "Double Render Detected"
65
+ setB(a + 1); // ⚡ BASIS: "Double Render Detected"
63
66
  }, [a]);
64
67
 
65
68
  return <button onClick={() => setA(a + 1)}>Pulse Basis</button>;
66
69
  ```
67
70
 
68
- Click the button. You should see this in your console within ~100ms:
71
+ Click the button. You should see this in your console:
69
72
  ```
70
73
  ⚡ BASIS | DOUBLE RENDER
71
74
  📍 Location: YourComponent.tsx
72
- Issue: a triggers b in a separate frame.
73
- Fix: Derive b during the first render.
75
+ Issue: effect_L5 triggers b in a separate frame.
76
+ Fix: Derive b during the render phase (remove effect) or wrap in useMemo.
74
77
  ```
75
78
 
76
79
  ---
77
80
 
81
+ ### 5. Control & Scope
82
+ * **Ghost Mode:** Disable the Matrix UI while keeping console-based forensics active by setting `showHUD={false}` on the provider.
83
+ * **Selective Auditing:** Add `// @basis-ignore` at the top of any file to disable instrumentation. Recommended for:
84
+ * High-frequency animation logic (>60fps)
85
+ * Third-party library wrappers
86
+ * Intentional synchronization (e.g., local mirrors of external caches)
87
+
88
+ ---
89
+
78
90
  ## Visual Proof
79
91
 
80
92
  The optional HUD shows your **State Basis Matrix** in real-time. Purple pulses ($\Omega$) are Context anchors; Red pulses (!) are redundant shadows.
81
93
 
82
94
  <p align="center">
83
- <img src="./assets/050Basis.gif" width="800" alt="Basis v0.5.0 Demo" />
95
+ <img src="./assets/050Basis.gif" width="800" alt="Basis Demo" />
84
96
  </p>
85
97
 
98
+ > **Note:** While the HUD visualizes real-time updates, the **Architectural Health Report** (Console) provides the deep topological analysis.
99
+
86
100
  ---
87
101
 
88
102
  ## What Basis Detects
89
103
 
90
- Basis treats every hook as a signal to catch these architectural violations:
104
+ Basis uses **Graph Theory**, **Signal Processing**, and **Linear Algebra** to identify architectural violations that static linters miss:
91
105
 
92
- - **Ω Context Mirroring** - Local state shadowing global context
93
- - **♊ Duplicate State** - Independent variables that always update together
94
- - **⚡ Sync Leaks** - 1-frame delays forcing double renders
95
- - **🛑 Recursive Oscillation** - Infinite loops (with circuit breaker)
106
+ - **⚡ Double Renders (Sync Leaks)** - Detects when a `useEffect` triggers a state update immediately after a render, forcing the browser to paint twice.
107
+ - **⚡ Prime Movers (Root Causes)** - Ignores downstream symptoms and points you to the exact hook or event that started the chain reaction.
108
+ - **⚡ Fragmented Updates** - Detects when a single click forces updates in multiple different files/contexts simultaneously (Tearing risk).
109
+ - **Ω Context Mirroring** - Detects when you redundanty copy Global Context data into Local State (creating two sources of truth).
110
+ - **♊ Duplicate State** - Identifies variables that always update at the exact same time and should be merged (e.g. `isLoading` + `isSuccess`).
111
+ - **🛑 Infinite Loops** - A safety circuit-breaker that kills the auditor before a recursive update freezes your browser.
96
112
 
97
- [**See examples & fixes →**](https://github.com/liovic/react-state-basis/wiki/03%3A-The-Forensic-Catalog)
113
+ [**See examples & fixes →**](https://github.com/liovic/react-state-basis/wiki/The-Forensic-Catalog)
98
114
 
99
115
  ---
100
116
 
@@ -103,9 +119,9 @@ Basis treats every hook as a signal to catch these architectural violations:
103
119
  ### Architectural Health Report
104
120
  Check your entire app's state architecture by running `window.printBasisReport()` in the console.
105
121
 
106
- * **Efficiency Score:** Ratio of independent signals to total hooks.
107
- * **Entangled Clusters:** Groups of variables that move in sync (Boolean Explosion).
108
- * **Correlation Matrix:** Raw pairwise similarity data for deep-dive forensics.
122
+ * **Refactor Priorities:** Uses **Spectral Influence** (Eigenvector Centrality) to rank bugs by their systemic impact. It tells you *what* to fix first.
123
+ * **Efficiency Score:** A calculated percentage of how "clean" your architecture is (Sources of Truth - Causal Leaks).
124
+ * **Sync Issues:** Groups entangled variables into clusters (e.g., Boolean Explosions).
109
125
 
110
126
  ### Hardware Telemetry
111
127
  Verify engine efficiency and heap stability in real-time via `window.getBasisMetrics()`.
@@ -117,7 +133,7 @@ Verify engine efficiency and heap stability in real-time via `window.getBasisMet
117
133
  Basis is verified against industry-standard codebases to ensure high-fidelity detection:
118
134
 
119
135
  * **Excalidraw (114k⭐)** - Caught a theme-sync leak forcing a double-render on every toggle. [**PR #10637**](https://github.com/excalidraw/excalidraw/pull/10637)
120
- * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274)
136
+ * **shadcn-admin (10k⭐)** - Detected redundant state pattern in viewport detection hooks. [**PR #274**](https://github.com/satnaing/shadcn-admin/pull/274) (MERGED)
121
137
 
122
138
  ---
123
139
 
@@ -133,7 +149,7 @@ Basis is verified against industry-standard codebases to ensure high-fidelity de
133
149
 
134
150
  ## Documentation & Theory
135
151
 
136
- Basis is built on heuristics inspired by **Linear Algebra** and **Signal Processing**. To understand the underlying math, visit the [**Full Wiki**](https://github.com/liovic/react-state-basis/wiki).
152
+ Basis is built on heuristics inspired by **Signal Processing**, **Linear Algebra**, and **Graph Theory**. To understand the underlying math, visit the [**Full Wiki**](https://github.com/liovic/react-state-basis/wiki).
137
153
 
138
154
  ---
139
155
 
@@ -142,8 +158,8 @@ Basis is built on heuristics inspired by **Linear Algebra** and **Signal Process
142
158
  Each era of Basis answers a different architectural question:
143
159
 
144
160
  ✓ **v0.4.x** - The Correlation Era - *Are these states moving together?*
145
- **v0.5.x** - The Decomposition Era - *Is this local state just a copy of Context?*
146
- **v0.6.x** - The Graph Era - *Which bug should I fix first for maximum impact?*
161
+ **v0.5.x** - The Decomposition Era - *Is this local state just a copy of Context?*
162
+ **v0.6.x** - The Graph Era - *Which bug should I fix first for maximum impact?*
147
163
  **v0.7.x** - The Information Era - *Does this state carry real information, or is it derivative?*
148
164
  **v0.8.x** - The Manifold Era - *How many hooks does your component actually need?*
149
165
 
package/dist/index.d.mts CHANGED
@@ -38,6 +38,7 @@ declare const use: <T>(usable: React.Usable<T>) => T;
38
38
  interface BasisProviderProps {
39
39
  children: ReactNode;
40
40
  debug?: boolean;
41
+ showHUD?: boolean;
41
42
  }
42
43
  declare const BasisProvider: React__default.FC<BasisProviderProps>;
43
44
  declare const useBasisConfig: () => {
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ declare const use: <T>(usable: React.Usable<T>) => T;
38
38
  interface BasisProviderProps {
39
39
  children: ReactNode;
40
40
  debug?: boolean;
41
+ showHUD?: boolean;
41
42
  }
42
43
  declare const BasisProvider: React__default.FC<BasisProviderProps>;
43
44
  declare const useBasisConfig: () => {