# Use Suspense Events for Loading State Tracking ## Rule `` emits three events: `pending`, `resolve`, and `fallback`. Use these events to track loading states, implement analytics, coordinate UI updates, or trigger side effects at appropriate times. ## Why This Matters Relying solely on the fallback slot for loading indication limits your options. The events provide programmatic access to Suspense state changes, enabling: - Loading progress tracking - Analytics for perceived performance - Coordinated animations - Custom loading indicators outside the Suspense boundary - Debugging async component behavior ## Basic Usage ```vue ``` ## Advanced: Global Loading Indicator ```vue ``` ## Event Sequence ``` Initial Load: 1. @pending - Suspense enters pending state 2. @fallback - Fallback content is displayed (may not fire if resolved quickly) 3. @resolve - Async content is ready On Content Change (with timeout): 1. @pending - New async dependency detected 2. (Previous content still visible during timeout period) 3. @fallback - Timeout exceeded, fallback shown 4. @resolve - New content ready On Content Change (fast): 1. @pending - New async dependency detected 2. @resolve - Resolved before timeout, fallback never shown ``` ## Coordinating with Transitions ```vue ``` ## Key Points 1. `@pending` fires when Suspense starts waiting for async dependencies 2. `@fallback` fires when fallback content becomes visible (respects timeout) 3. `@resolve` fires when default slot content is ready to display 4. Use events for analytics, debugging, and coordinating UI outside Suspense 5. Events enable global loading indicators across multiple Suspense boundaries 6. `@fallback` may not fire if content resolves before the timeout ## References - [Vue.js Suspense Events](https://vuejs.org/guide/built-ins/suspense#events)