From 701a98bd49711e5b2e170b7e79d693a0115166da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Thu, 11 Dec 2025 18:11:59 +0100 Subject: [PATCH] ai: event render system analysis --- TODO.md | 177 +++ claudedocs/event-rendering-system-analysis.md | 1127 +++++++++++++++++ 2 files changed, 1304 insertions(+) create mode 100644 claudedocs/event-rendering-system-analysis.md diff --git a/TODO.md b/TODO.md index c4083c3..9ecee5a 100644 --- a/TODO.md +++ b/TODO.md @@ -56,6 +56,7 @@ Current RTL implementation is partial and has limitations: - **Window crashes on unsupported kind event** - Need graceful error handling for unknown kinds - **Nested lists in Markdown should be padded** - Markdown renderer spacing issue - **Text rendering**: Avoid inserting `
` tags, investigate noStrudel's EOL metadata approach +- **JSON viewer scrolling**: Expandable JSON in event details cannot be scrolled when content exceeds available height - needs overflow handling ## Command Palette / UX Improvements @@ -185,3 +186,179 @@ Show timestamps/dates for notes in feed views for better chronological context. - [NIP-10 Threading](https://github.com/nostr-protocol/nips/blob/master/10.md) (for contrast - what NOT to do) **Note**: This is a significant feature requiring careful attention to the threading model differences between NIP-10 (kind 1 notes) and NIP-22 (kind 1111 comments). + +--- + +## Event Rendering System Improvements + +**Reference**: See `claudedocs/event-rendering-system-analysis.md` for comprehensive analysis + +### Phase 1: Foundation Fixes (1-2 weeks) +**Goal:** Fix critical architectural issues and quick wins + +#### 1.1 Unified Detail Renderer Registry +**Priority**: High | **Effort**: Low +**Files**: `src/components/nostr/kinds/index.tsx`, `src/components/EventDetailViewer.tsx` + +**Problem**: EventDetailViewer uses hardcoded switch statement instead of registry pattern +```tsx +// Current anti-pattern: +event.kind === kinds.Metadata ? +: event.kind === kinds.Contacts ? +``` + +**Solution**: Create `detailRenderers` map parallel to `kindRenderers` with fallback logic + +#### 1.2 Systematic Depth Tracking +**Priority**: High | **Effort**: Medium +**Files**: All `*Renderer.tsx` files + +**Problem**: Depth tracking inconsistent - can cause infinite loops in Kind6Renderer (reposts), Kind9735Renderer (zaps) + +**Solution**: +- Add `MAX_EMBED_DEPTH = 3` constant +- Update `BaseEventProps` to require depth +- Audit all renderers using `EmbeddedEvent` +- Implement `CollapsedPreview` component for max depth exceeded + +#### 1.3 Error Boundaries +**Priority**: High | **Effort**: Low +**File**: `src/components/EventErrorBoundary.tsx` + +**Problem**: One broken event crashes entire feed + +**Solution**: Create `EventErrorBoundary` component wrapping all events with diagnostic error cards + +#### 1.4 Renderer Memoization +**Priority**: Medium | **Effort**: Low +**Files**: All `*Renderer.tsx` files + +**Problem**: Renderers recalculate on every parent render - no performance optimization + +**Solution**: +- Wrap all renderer components with `React.memo` +- Add `useMemo` for expensive computations (parsing, extraction) +- Add `useCallback` for event handlers + +### Phase 2: Component Library (2-3 weeks) +**Goal:** Build reusable abstractions for common patterns + +#### 2.1 Generic Threading Components +**Priority**: High | **Effort**: High +**Files**: `src/lib/threading.ts`, `src/components/Thread/` + +**Problem**: Only NIP-10 threading supported, need NIP-22, NIP-28, NIP-29 + +**Solution**: Create abstraction layer +- `getThreadReferences()` helper supporting multiple NIPs +- `` component (universal "replying to") +- `` for parent preview +- `` for detail view reply chains + +**Related**: Works with NIP-22 Comment Support (existing TODO) + +#### 2.2 Relationship Panels +**Priority**: Medium | **Effort**: Medium +**Files**: `src/components/nostr/Relationships/` + +**Problem**: Detail views don't show replies, zaps, reactions + +**Solution**: Create reusable relationship components +- `` - Show replies to event +- `` - Show zaps with total/list +- `` - Group reactions by emoji +- `` - Universal engagement indicators + +#### 2.3 Enhanced Media Components +**Priority**: Medium | **Effort**: Medium +**Files**: `src/components/nostr/MediaEmbed.tsx` + +**Problem**: No multi-stage rendering, no lazy loading, no NSFW handling + +**Solution**: Enhance MediaEmbed with +- Multi-stage rendering (placeholder → thumbnail → full → error) +- Lazy loading with IntersectionObserver +- NSFW blur with content-warning tag support +- Quality selection for videos +- Accessibility improvements (alt text, captions) + +#### 2.4 Context-Aware Rendering +**Priority**: Medium | **Effort**: Low +**Files**: `src/components/nostr/kinds/index.tsx`, all renderers + +**Problem**: Same rendering for feed, detail, and embed contexts + +**Solution**: Add `context` prop to BaseEventProps, renderers adapt display + +### Phase 3: Architecture Evolution (3-4 weeks) +**Goal:** Transform into production-grade framework + +#### 3.1 Performance Optimization +**Priority**: High | **Effort**: Medium +**Files**: `src/components/ReqViewer.tsx`, `EventDetailViewer.tsx` + +**Target**: Feed with 10,000 events scrolls at 60fps + +**Tasks**: +- Virtual scrolling with react-virtuoso +- Code splitting for detail renderers (lazy load) +- Batch profile fetching (avoid N+1 queries) +- Suspense boundaries for async content +- Performance monitoring + +#### 3.2 Helper Library Expansion +**Priority**: High | **Effort**: High +**Files**: `src/lib/helpers/` directory + +**Problem**: Many renderers parse tags manually instead of using helpers + +**Solution**: Create helpers for all NIPs +- File metadata (1063): url, hash, size, mime, dimensions +- Media events (20, 21, 22): URLs, thumbnails, dimensions +- Lists (30000+): systematic list item extraction +- Reposts (6, 16, 18): reposted event extraction +- Highlights (9802): context, highlight text +- Calendar (31922-31925): date/time parsing +- Polls (1068): options, votes, tally + +**Note**: Submit generic ones to applesauce-core upstream + +#### 3.3 Accessibility Improvements +**Priority**: Medium | **Effort**: Medium +**Files**: All renderers, BaseEventContainer + +**Target**: WCAG AA compliance + +**Tasks**: +- Semantic HTML (`
`, `