Skip to content

Commit 1a60e6a

Browse files
committed
wip devtools - squashed
1 parent bbed2f2 commit 1a60e6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+6727
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ out
9090
# Nuxt.js build / generate output
9191
.nuxt
9292
dist
93+
build
9394

9495
# Gatsby files
9596
.cache/

db-devtools-summary.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# TanStack DB DevTools Architecture - Implementation Summary
2+
3+
## What Was Accomplished
4+
5+
Successfully implemented a comprehensive devtools architecture for TanStack DB with the following components:
6+
7+
### 1. Core DevTools Package (`@tanstack/db-devtools`)
8+
- **Complete implementation** with SolidJS-based UI components
9+
- Comprehensive collection and transaction monitoring
10+
- Real-time performance tracking for live queries
11+
- Garbage collection aware weak reference management
12+
- Global registry system for collection tracking
13+
14+
#### Key Features:
15+
- Collection metadata tracking (status, size, transactions, timings)
16+
- Transaction details with mutation history
17+
- Live query performance metrics
18+
- Memory-efficient weak reference system
19+
- Automatic cleanup and garbage collection
20+
21+
#### Files Created:
22+
- `packages/db-devtools/src/index.ts` - Main exports
23+
- `packages/db-devtools/src/devtools.ts` - Core devtools functions
24+
- `packages/db-devtools/src/registry.ts` - Collection registry implementation
25+
- `packages/db-devtools/src/types.ts` - TypeScript definitions
26+
- `packages/db-devtools/src/DbDevtools.tsx` - Main devtools component
27+
- `packages/db-devtools/src/DbDevtoolsPanel.tsx` - Panel implementation
28+
- `packages/db-devtools/src/components/` - UI components for collections, transactions, etc.
29+
30+
### 2. React Integration Package (`@tanstack/react-db-devtools`)
31+
- React wrapper component for the core devtools
32+
- Proper integration with React applications
33+
- Dynamic loading and mounting of SolidJS components
34+
35+
#### Files Created:
36+
- `packages/react-db-devtools/src/ReactDbDevtools.tsx` - React wrapper component
37+
- `packages/react-db-devtools/src/index.ts` - Exports
38+
39+
### 3. Vue Integration Package (`@tanstack/vue-db-devtools`)
40+
- Vue wrapper component (basic structure)
41+
- Type definitions for Vue integration
42+
43+
#### Files Created:
44+
- `packages/vue-db-devtools/src/VueDbDevtools.vue` - Vue component
45+
- `packages/vue-db-devtools/src/index.ts` - Exports
46+
47+
### 4. Package Configuration
48+
- Complete `package.json` files for all three packages
49+
- Build configurations with `tsup` for JavaScript/TypeScript compilation
50+
- Proper dependency management and workspace integration
51+
- ESLint configuration and linting fixes applied
52+
53+
### 5. React Example Integration
54+
- Added devtools dependency to the React todo example
55+
- Imported and integrated `ReactDbDevtools` component
56+
- Updated package.json with workspace reference
57+
58+
## Architecture Overview
59+
60+
### React Integration Solution
61+
Following TanStack Query and Router patterns, we implemented a mount/unmount class approach:
62+
63+
**Core Package (`@tanstack/db-devtools`)**
64+
- `TanstackDbDevtools` class with `.mount()` and `.unmount()` methods
65+
- Uses SolidJS `render()` to mount components into provided DOM elements
66+
- Registry, types, and SolidJS components all in one package
67+
- Clean separation between class API and UI implementation
68+
69+
**React Package (`@tanstack/react-db-devtools`)**
70+
- Simple React wrapper that creates `TanstackDbDevtools` instance
71+
- Uses `useRef` to get DOM element and calls `devtools.mount(ref.current)`
72+
- Handles prop updates via class setter methods
73+
- No component duplication - reuses original SolidJS components
74+
75+
This approach eliminates JSX conflicts by using DOM mounting instead of component transpilation.
76+
77+
### Global Registry System
78+
```typescript
79+
interface DbDevtoolsRegistry {
80+
collections: Map<string, CollectionRegistryEntry>
81+
registerCollection: (collection: CollectionImpl) => void
82+
unregisterCollection: (id: string) => void
83+
getCollectionMetadata: (id: string) => CollectionMetadata | undefined
84+
getAllCollectionMetadata: () => Array<CollectionMetadata>
85+
getCollection: (id: string) => CollectionImpl | undefined
86+
releaseCollection: (id: string) => void
87+
getTransactions: (collectionId?: string) => Array<TransactionDetails>
88+
getTransaction: (id: string) => TransactionDetails | undefined
89+
cleanup: () => void
90+
garbageCollect: () => void
91+
}
92+
```
93+
94+
### Memory Management
95+
- Uses `WeakRef` for collection references to prevent memory leaks
96+
- Automatic garbage collection of dead collection references
97+
- Hard references only created when actively viewing collections
98+
- Polling system for metadata updates with configurable intervals
99+
100+
### Performance Tracking
101+
- Live query execution timing
102+
- Incremental run statistics
103+
- Transaction state monitoring
104+
- Collection size and status tracking
105+
106+
### UI Components
107+
- **CollectionList**: Overview of all collections with metadata
108+
- **CollectionDetails**: Detailed view of individual collections
109+
- **TransactionList**: List of transactions with filtering
110+
- **TransactionDetails**: Detailed mutation history view
111+
- **Query Inspector**: Live query analysis and performance metrics
112+
113+
## Current Status
114+
115+
### ✅ Completed
116+
- Core devtools architecture and implementation
117+
- SolidJS-based UI components with full functionality
118+
- TypeScript definitions and type safety
119+
- Package structure and build configuration
120+
- Linting and code quality fixes
121+
- React wrapper component structure
122+
- Vue wrapper component basic structure
123+
124+
### ✅ Recently Fixed
125+
- **React Integration Type Conflicts**: Successfully resolved using TanStack mount/unmount pattern
126+
- **Component Duplication**: Eliminated by reusing SolidJS components via DOM mounting
127+
- **Architecture**: Implemented consistent TanStack Query/Router patterns for framework integration
128+
129+
### ⚠️ Partial/In Progress
130+
- TypeScript type declarations need to be generated for better developer experience
131+
- Vue integration is basic structure only
132+
- React example has some runtime TypeScript errors but functionality works
133+
134+
### 🔄 Next Steps
135+
1. **Generate Type Declarations**: Add proper .d.ts files for all packages to resolve TypeScript import issues
136+
2. **Complete Vue Integration**: Implement proper Vue SFC handling in build process
137+
3. **Testing**: Add comprehensive test coverage
138+
4. **Documentation**: Create usage guides and API documentation
139+
5. **Performance Optimization**: Profile and optimize the devtools overhead
140+
6. **Polish React Integration**: Fix remaining TypeScript compilation issues
141+
142+
## Technical Challenges Addressed
143+
144+
1. **Cross-Framework Compatibility**: Created a core devtools that can be wrapped by any framework
145+
2. **Memory Management**: Implemented weak reference system to prevent memory leaks
146+
3. **Real-time Updates**: Built polling system for live collection metadata
147+
4. **Type Safety**: Comprehensive TypeScript definitions throughout
148+
5. **Build System**: Set up proper package compilation with external dependencies
149+
6. **SolidJS/React Type Conflicts**: Resolved using TanStack mount/unmount pattern, eliminating JSX transpilation conflicts while reusing SolidJS components
150+
151+
## Package Versions and Dependencies
152+
- Core: `@tanstack/[email protected]`
153+
- React: `@tanstack/[email protected]`
154+
- Vue: `@tanstack/[email protected]`
155+
156+
All packages are properly configured with workspace references and external dependency management.
157+
158+
## Code Quality
159+
- All packages pass ESLint with consistent formatting
160+
- Proper TypeScript configuration
161+
- Clean separation of concerns between core and framework-specific packages
162+
- Follow TanStack conventions and patterns

0 commit comments

Comments
 (0)