|
| 1 | +# Adaptive Tier Rendering — Design Spec |
| 2 | + |
| 3 | +**Date:** 2026-04-05 |
| 4 | +**Status:** Phase 1 MVP complete, Phase 2 planned |
| 5 | +**Author:** Claude + annondeveloper |
| 6 | + |
| 7 | +## Vision |
| 8 | + |
| 9 | +UI Kit automatically detects client network bandwidth and renders the optimal component tier. Fast connections get Premium (spring physics, aurora glow). Slow connections get Lite (CSS-only, instant). No developer configuration needed. |
| 10 | + |
| 11 | +## Architecture |
| 12 | + |
| 13 | +### Phase 1: Motion-Based Adaptive (COMPLETE) |
| 14 | + |
| 15 | +**How it works:** |
| 16 | +1. `<UIProvider adaptive>` enables auto-detection |
| 17 | +2. `useAdaptiveTier()` runs on page mount (<50ms, non-blocking) |
| 18 | +3. Detects bandwidth via `navigator.connection` API + Performance API fallback |
| 19 | +4. Maps bandwidth to motion level: premium(3), standard(2/1), lite(0) |
| 20 | +5. Sets `MotionContext` — all components read this via `useMotionLevel()` |
| 21 | +6. Premium effects (spring animations, aurora glow) only activate on fast connections |
| 22 | +7. No component swap, no layout shift — just motion intensity changes |
| 23 | + |
| 24 | +**Detection mapping:** |
| 25 | +| Network Condition | Tier | Motion | Confidence | |
| 26 | +|---|---|---|---| |
| 27 | +| 4G + >5Mbps + !saveData | premium | 3 | high | |
| 28 | +| 4G + 1.5-5Mbps | standard | 2 | medium | |
| 29 | +| 4G + <1.5Mbps | standard | 1 | low | |
| 30 | +| 3G | standard | 1 | medium | |
| 31 | +| 2G / slow-2g | lite | 0 | high | |
| 32 | +| Save-Data header | lite | 0 | high | |
| 33 | +| prefers-reduced-motion | lite | 0 | high | |
| 34 | + |
| 35 | +**Files:** |
| 36 | +- `src/core/adaptive/use-adaptive-tier.ts` — detection hook |
| 37 | +- `src/core/adaptive/adaptive-context.tsx` — React context |
| 38 | +- `src/core/adaptive/index.ts` — barrel export |
| 39 | +- `src/__tests__/core/adaptive/use-adaptive-tier.test.ts` — 10 tests, all passing |
| 40 | + |
| 41 | +### Phase 2: Weight Tier Switching (PLANNED) |
| 42 | + |
| 43 | +**Concept:** Actually load lighter component code on slow connections. |
| 44 | + |
| 45 | +**New entry point:** `@annondeveloper/ui-kit/adaptive` |
| 46 | +- Exports wrapper components that dynamically import the right tier |
| 47 | +- Always renders Standard immediately (it's already loaded with the CSS) |
| 48 | +- On slow connections: components stay at Standard (motion 0-1) |
| 49 | +- On fast connections: lazy-loads Premium module, swaps seamlessly |
| 50 | + |
| 51 | +**Structural parity audit results (10 components sampled):** |
| 52 | + |
| 53 | +| Component | Structural Match | Notes | |
| 54 | +|---|---|---| |
| 55 | +| Button | PARTIAL | Premium adds outer wrapper div | |
| 56 | +| Card | PARTIAL | Premium adds outer wrapper div | |
| 57 | +| Badge | PARTIAL | Same DOM, animation layer only | |
| 58 | +| FormInput | PARTIAL | Premium adds effects wrapper | |
| 59 | +| Select | **NO** | Lite=native `<select>`, Standard=custom combobox | |
| 60 | +| Tabs | PARTIAL | Same structure, Premium adds indicator | |
| 61 | +| Dialog | **NO** | Premium adds dynamic particles | |
| 62 | +| MetricCard | PARTIAL | Inner DOM identical | |
| 63 | +| Tooltip | **NO** | Lite=native title, Standard=custom positioned | |
| 64 | +| Accordion | PARTIAL | DOM identical, CSS-only enhancements | |
| 65 | + |
| 66 | +**Conclusion:** 7/10 have sufficient parity. 3 need work before weight tier switching. |
| 67 | + |
| 68 | +**Phase 2 approach for incompatible components (Select, Tooltip, Dialog):** |
| 69 | +- Option A: Fix Lite variants to match Standard DOM structure |
| 70 | +- Option B: Exclude from weight tier switching (use motion-only for these 3) |
| 71 | +- Recommended: Option A for Select/Tooltip (small components), Option B for Dialog (complex) |
| 72 | + |
| 73 | +### Phase 3: Future Enhancements (NOT PLANNED) |
| 74 | + |
| 75 | +- Predictive pre-loading: detect patterns and preload Premium before user navigates |
| 76 | +- Per-component adaptive: different tiers for above-fold vs below-fold |
| 77 | +- Server-side hints: `Save-Data` header → server renders Lite HTML |
| 78 | + |
| 79 | +## Key Constraints |
| 80 | + |
| 81 | +1. **Zero developer config** — `<UIProvider adaptive>` is the only change needed |
| 82 | +2. **No initial render delay** — detection is synchronous, <50ms |
| 83 | +3. **No layout shift** — all tiers share same box model |
| 84 | +4. **Per-page detection** — re-checks on each navigation |
| 85 | +5. **Graceful fallback** — if APIs unavailable, defaults to standard |
| 86 | +6. **SSR safe** — returns 'standard' on server, detects on hydration |
| 87 | + |
| 88 | +## Testing |
| 89 | + |
| 90 | +Run `npx vitest run src/__tests__/core/adaptive/` — 10 tests cover all detection paths. |
| 91 | +Demo page at `/adaptive` for visual testing with Chrome DevTools network throttling. |
0 commit comments