|
| 1 | +# OwnTS — React `useEffect` frontend spike (`Own.React`) |
| 2 | + |
| 3 | +The TypeScript sibling of the [Roslyn C# extractor](../roslyn/). It scans a |
| 4 | +React `.tsx`, emits **OwnIR** facts, and lets the **existing** Python core |
| 5 | +(`python -m ownlang ownir`) flag the leak. Same seam, same checker, different |
| 6 | +skin — a `useEffect` acquire without a cleanup `return` is the core's `OWN001`, |
| 7 | +exactly as a C# `event +=` without `-=` is. |
| 8 | + |
| 9 | +> The same OwnIR idea behind WPF subscription leaks can model React effect storms. |
| 10 | +
|
| 11 | +This is a **spike**, per [P-020](../../docs/proposals/P-020-ownts-react-effects.md) |
| 12 | +— deliberately *not* a TypeScript analyzer. Extraction is heuristic (brace |
| 13 | +matching + cleanup-verb detection), not a real TS parse. Its only job is to prove |
| 14 | +the seam is cross-language. |
| 15 | + |
| 16 | +## Run it |
| 17 | + |
| 18 | +```bash |
| 19 | +# print the OwnIR facts extracted from a .tsx |
| 20 | +python frontend/ownts/ownts.py frontend/ownts/examples/Dashboard.tsx |
| 21 | + |
| 22 | +# extract + run straight through the core (the "catch") |
| 23 | +python frontend/ownts/ownts.py frontend/ownts/examples/Dashboard.tsx --check |
| 24 | + |
| 25 | +# or the real two-step CLI, same as the C# side: |
| 26 | +python frontend/ownts/ownts.py frontend/ownts/examples/Dashboard.tsx -o facts.json |
| 27 | +python -m ownlang ownir facts.json --format sarif |
| 28 | + |
| 29 | +# pin the spike |
| 30 | +python frontend/ownts/test_ownts.py |
| 31 | +``` |
| 32 | + |
| 33 | +`Dashboard.tsx` drops three `OWN001` leaks; `DashboardClean.tsx` (every acquire |
| 34 | +has a cleanup `return`) is silent. |
| 35 | + |
| 36 | +``` |
| 37 | +Dashboard.tsx:13: error: [OWN001] timer 'setInterval(() =>' ... never stopped ... (leak) [resource: timer] |
| 38 | +Dashboard.tsx:21: error: [OWN001] the result of '.subscribe(...)' is ignored ... (leak) [resource: subscription token] |
| 39 | +Dashboard.tsx:27: error: [OWN001] event '.addEventListener(...)' ... never unsubscribed ... (leak) [resource: subscription token] |
| 40 | +``` |
| 41 | + |
| 42 | +## What it catches — the honest `Own.React` slice |
| 43 | + |
| 44 | +| EFF | Pattern | OwnIR `resource` | Core verdict | |
| 45 | +|-----|---------|------------------|--------------| |
| 46 | +| `EFF004` | `setInterval`/`setTimeout` in an effect, no `clearInterval`/`clearTimeout` cleanup | `timer` | `OWN001` | |
| 47 | +| `EFF003` | `X.subscribe(...)` with no `unsubscribe` cleanup | `subscribe` | `OWN001` | |
| 48 | +| `EFF003` | `addEventListener` with no `removeEventListener` cleanup | `subscription` | `OWN001` | |
| 49 | + |
| 50 | +These three **are** the existing acquire→release model, just emitted by an OwnTS |
| 51 | +frontend. The core is untouched. |
| 52 | + |
| 53 | +## What it does NOT do (and why that's honest) |
| 54 | + |
| 55 | +`EFF001/002` — the unstable-dependency "effect storm" (the Cloudflare 12-Sep-2025 |
| 56 | +shape: a `useEffect` whose dep object is re-created each render, re-firing the |
| 57 | +effect and storming the API) — **is not an acquire/release leak.** It needs a new |
| 58 | +core capability (dependency-identity *stability*), which the core does not have. |
| 59 | +Per P-020, `EFF001` must **not** masquerade as `OWN001`. |
| 60 | + |
| 61 | +So the scanner only emits a *frontend-only, clearly-labelled* heuristic note for |
| 62 | +`EFF001` candidates on **stderr** — never a core-verified finding: |
| 63 | + |
| 64 | +``` |
| 65 | +Dashboard.tsx:34: EFF001 (frontend heuristic, NOT core-verified): dependency |
| 66 | +'filters' is a fresh object/array identity every render; the effect does IO — |
| 67 | +possible request storm. Stabilise with useMemo. |
| 68 | +``` |
| 69 | + |
| 70 | +The one-liner the spike pays for: **"Not all lifecycle bugs leak memory. Some |
| 71 | +leak requests."** We make **no** "Own would have prevented the Cloudflare outage" |
| 72 | +claim — see P-020's Non-goals. |
0 commit comments