Electron + React App Debugger
This skill provides comprehensive debugging capabilities for Electron applications with React frontends, specifically designed for epub-based ebook readers.
Quick Start
Manual Debugging Workflow
- •Launch the app with developer tools enabled
- •Capture console logs for JavaScript errors
- •Inspect application state using React DevTools
- •Test specific features with reproduction steps
- •Analyze errors with context from codebase
See COMMON_ISSUES.md for typical Electron+React bugs and their solutions.
Debugging Tools
1. Console Log Capture
Use DevTools console to catch:
- •JavaScript runtime errors
- •React component errors
- •epubjs rendering issues
- •Network failures (fetch, WebSocket, IPC)
Key patterns to watch:
// epubjs errors TypeError: Cannot read properties of undefined (reading 'destroy') Uncaught Error: XML parsing failed // React errors Warning: Can't perform a React state update on an unmounted component Error: Too many re-renders. React limits the number of renders // IPC errors Error: IPC handler 'get-book-server-port' not registered Error: window.electronAPI is not defined
2. IPC Communication Debugging
Test IPC handlers by checking:
// In renderer (DevTools console)
console.log('electronAPI available:', !!window.electronAPI)
window.electronAPI?.getBookServerPort().then(port => {
console.log('Server port:', port)
}).catch(err => {
console.error('IPC error:', err)
})
Verify handlers are registered in main process:
// In main.cjs
ipcMain.handle('get-book-server-port', () => serverPort)
3. State Inspection
Use React DevTools Components tab to inspect:
- •Component props and state
- •Hook values (useState, useEffect, useRef)
- •Context values
- •Rendering issues
Common state issues:
- •Stale closures
- •Missing dependencies in useEffect
- •Incorrect state updates
- •Race conditions in async operations
4. LocalForage Debugging
Check IndexedDB/LocalForage operations:
// In DevTools console
localforage.getItem('books').then(books => {
console.log('Library:', books)
}).catch(err => {
console.error('LocalForage error:', err)
})
// Check all keys
localforage.keys().then(keys => {
console.log('Stored keys:', keys)
})
5. epubjs Debugging
Common epubjs issues and solutions:
Issue: Book won't load
- •Check if viewer ref is null when rendering starts
- •Verify epubjs version compatibility
- •Check for CORS errors when loading from server
Issue: Memory leaks
- •Always call
book.destroy()before loading new book - •Remove event listeners:
rendition.off('relocated', handler) - •Cleanup selections and annotations
Issue: Styling not applying
- •Check if rendition.contents() is ready
- •Verify CSS rules have
!importantflag - •Wait for location change before applying styles
Automated Testing
Use scripts/test_reset_bug.py to automate testing the reset functionality.
Use scripts/test_epub_loading.py to test book loading with various EPUB files.
Common Debugging Patterns
Pattern 1: Reproduction Steps
When reporting or fixing bugs:
- •Clear application data
- •Reproduce bug with exact steps
- •Capture console output
- •Note application state before/after
- •Verify fix resolves issue
Pattern 2: Isolating Components
If React component has issues:
- •Test component in isolation (create minimal reproduction)
- •Check props passed to component
- •Verify state updates are correct
- •Check useEffect dependencies
- •Remove side effects to narrow down issue
Pattern 3: Testing IPC
For Electron IPC issues:
- •Verify preload script exposes API
- •Check main process registers handler
- •Test with different data types
- •Verify async/error handling
- •Check for race conditions in startup
Known Issues in Lumina Reader
See LUMINA_BUGS.md for documented bugs, their root causes, and verified fixes.
Best Practices
- •Always check
window.electronAPIbefore calling methods (graceful degradation in browser dev mode) - •Clean up event listeners when components unmount or books change
- •Use refs for persistent values across renders (e.g., handler refs for event cleanup)
- •Validate user input before async operations (file uploads, book IDs)
- •Test with both dev mode and production build (behavior can differ)
- •Clear console between tests to avoid confusion
- •Use try/catch around all async operations with meaningful error logging
- •Check IndexedDB using browser DevTools Application tab