Lifecycle
This document describes the lifecycle of the rhinoartisan-web-3d web component, from initialization to cleanup.
📊 Lifecycle Overview
┌─────────────────────────────────────────────────────────────┐
│ Component Created │
│ (Custom Element Defined) │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Component Mounted to DOM │
│ (connectedCallback triggered) │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ React Component Initializes │
│ - State setup │
│ - Options parsing │
│ - Refs initialization │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Canvas & Scene Setup │
│ - Three.js renderer │
│ - Camera initialization │
│ - Controls setup │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Model Loading Phase │
│ - Fetch GLTF/GLB file │
│ - Parse geometry │
│ - Apply materials │
│ - Compute bounding box │
│ │
│ Progress: 0% → 100% │
│ Event: 'model-loaded' (on success) │
│ Event: 'model-load-error' (on failure) │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Viewer Ready State │
│ - All methods exposed │
│ - Interactive controls enabled │
│ - Event: 'ready' dispatched │
│ │
│ ✅ FULLY OPERATIONAL │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Active/Interactive │
│ - User interactions │
│ - Material changes → 'material-changed' │
│ - Selection changes → 'selection-changed' │
│ - Method calls │
└───────────────────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Component Unmounted │
│ (disconnectedCallback triggered) │
│ - Cleanup resources │
│ - Dispose geometries │
│ - Clear caches │
└─────────────────────────────────────────────────────────────┘🔄 Lifecycle Stages
1. Component Creation
2. Component Mount
3. Initialization
4. Scene Setup
5. Model Loading
6. Ready State
7. Active State
8. Model Change
9. Component Unmount
📍 Key Lifecycle Events
Event Timeline
🎯 Best Practices
1. Wait for Ready State
2. Handle Loading States
3. Cleanup on Unmount
4. Preload for Better UX
⚠️ Common Pitfalls
Calling Methods Too Early
Not Handling Model Load Errors
Memory Leaks
🔗 Related Documentation
📊 Lifecycle State Diagram
Last updated
Was this helpful?