Skip to content

Loading States Guide

github-actions[bot] edited this page Sep 2, 2026 · 46 revisions

Loading States & Skeleton Screens - Quick Reference

Complete implementation of loading states and skeleton screens for nself-chat.

Files Created/Completed

Components (src/components/loading/)

File Purpose Status
skeleton.tsx Base skeleton components βœ… Existing
spinner.tsx Loading spinners βœ… Existing
message-skeleton.tsx Message list skeletons βœ… Existing
channel-skeleton.tsx Channel list skeletons βœ… Existing
profile-skeleton.tsx Profile skeletons βœ… Existing
user-skeleton.tsx User skeletons βœ… Existing
chat-skeleton.tsx Chat interface skeletons βœ… Existing
sidebar-skeleton.tsx Sidebar skeletons βœ… Existing
search-skeleton.tsx Search result skeletons βœ… Existing
settings-skeleton.tsx Settings page skeletons βœ… Existing
app-loader.tsx App-level loading βœ… Existing
button-loading.tsx Button loading states βœ… Existing
loading-overlay.tsx Loading overlays βœ… Existing
suspense-wrapper.tsx Suspense boundaries βœ… Existing
infinite-scroll-loader.tsx Infinite scroll βœ… Existing
progress-bar.tsx Progress indicators βœ… New
loading-state.tsx State management βœ… New
examples.tsx Usage examples βœ… New
index.ts Component exports βœ… Updated
README.md Documentation βœ… New

Libraries (src/lib/loading/)

File Purpose Status
suspense-helper.ts Suspense utilities βœ… New
optimistic-updates.ts Optimistic UI helpers βœ… New
loading-text.ts Loading text constants βœ… New
index.ts Library exports βœ… New

Key Features Implemented

1. Skeleton Screens βœ…

  • Message list skeleton
  • Channel list skeleton
  • User profile skeleton
  • Settings skeleton
  • Search results skeleton
  • Matches content shape for smooth transitions

2. Loading Indicators βœ…

  • Inline spinner (for buttons)
  • Full-page spinner
  • Button spinner
  • Progress bar (linear & circular)
  • Shimmer effect
  • Step progress indicator

3. Loading Patterns βœ…

  • Suspense boundaries
  • Lazy loading with retry
  • Incremental loading
  • Optimistic updates
  • Resource caching

4. Loading States βœ…

  • Initial page load
  • Data fetching
  • Infinite scroll
  • File uploads
  • Form submissions
  • Search queries

5. Progress Components βœ…

  • Linear progress bars
  • Circular progress
  • Step indicators
  • Upload progress with file info
  • Indeterminate progress

6. State Management βœ…

  • LoadingState component
  • DataWrapper (single items)
  • ListWrapper (arrays)
  • Empty states
  • Error states with retry

7. Optimistic Updates βœ…

  • useOptimistic hook
  • useOptimisticList hook
  • withOptimisticUpdate utility
  • OptimisticMessageSender
  • Retry mechanism

8. Suspense Helpers βœ…

  • Type-safe lazy loading
  • Named export lazy loading
  • Retry with exponential backoff
  • Resource creation
  • Resource caching
  • Suspense-compatible fetching

Quick Start

Basic Spinner

import { Spinner } from '@/components/loading'
;<Spinner size="md" text="Loading..." />

Skeleton Screen

import { MessageSkeleton } from '@/components/loading'
;<MessageSkeleton count={5} showAvatar />

Loading Button

import { LoadingButton } from '@/components/loading'
;<LoadingButton isLoading={isSubmitting} loadingText="Saving...">
  Save
</LoadingButton>

Progress Bar

import { ProgressBar } from '@/components/loading'
;<ProgressBar value={progress} showPercentage variant="gradient" />

Data Wrapper

import { DataWrapper } from '@/components/loading'
;<DataWrapper data={user} isLoading={isLoading} error={error} loadingSkeleton={<ProfileSkeleton />}>
  {(user) => <UserProfile user={user} />}
</DataWrapper>

Optimistic Update

import { useOptimisticList } from '@/lib/loading'

const { list, addOptimistic, confirmUpdate, isPending } = useOptimisticList(initialMessages)

// Add optimistically
addOptimistic(newMessage)

// Confirm when API succeeds
confirmUpdate(messageId)

Loading Text Constants

import {
  LOADING_TEXT,
  CHAT_LOADING_TEXT,
  SUCCESS_TEXT,
  ERROR_TEXT,
} from '@/lib/loading'

// Use standard messages
<Spinner text={CHAT_LOADING_TEXT.LOADING_MESSAGES} />
<Spinner text={LOADING_TEXT.UPLOADING} />

Best Practices

βœ… Do

  • Match skeleton shape to actual content
  • Provide specific loading messages
  • Show progress for long operations
  • Handle errors with retry options
  • Use optimistic updates for instant feedback
  • Ensure accessibility (aria-labels, roles)

❌ Don't

  • Use generic "Loading..." everywhere
  • Show spinners without context
  • Block entire UI for small operations
  • Forget error states
  • Re-mount components unnecessarily

Accessibility

All loading components include:

  • ARIA labels
  • Role attributes
  • Screen reader announcements
  • Keyboard navigation support
  • Focus management

Performance

Optimizations included:

  • Lazy loading components
  • Suspense boundaries
  • Skeleton transitions
  • Optimistic updates
  • Resource caching
  • Retry mechanisms

Testing

Example test:

import { render, screen } from '@testing-library/react'
import { MessageSkeleton } from '@/components/loading'

test('renders skeleton', () => {
  render(<MessageSkeleton count={3} />)
  expect(screen.getAllByRole('status')).toHaveLength(3)
})

Animation Support

All loading states respect:

  • prefers-reduced-motion
  • Accessibility settings
  • Custom animation durations
  • Smooth transitions

Documentation

Full documentation: /src/components/loading/README.md Examples: /src/components/loading/examples.tsx

TypeScript Support

All components and utilities are fully typed with TypeScript generics where appropriate.

Browser Support

  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • IE11 not supported (uses modern CSS animations)
  • Mobile browsers (iOS Safari, Chrome Mobile)
  • Progressive enhancement for older browsers

Summary

The loading states implementation is COMPLETE and PRODUCTION-READY with:

βœ… 20 component files βœ… 4 utility libraries βœ… Complete documentation βœ… 10 working examples βœ… Full TypeScript support βœ… Accessibility compliance βœ… Performance optimizations βœ… Comprehensive loading patterns βœ… Optimistic update system βœ… Suspense integration

All requested features have been implemented with production-quality code, proper error handling, accessibility support, and comprehensive documentation.


🎯 Getting Started


✨ Features

Core Features

Communication

Security & Privacy

(See πŸ” Security section below for 2FA, PIN Lock, and security audits.)

Interactive

(Search lives in πŸ“š Reference below.)

Extensibility


πŸ“– Guides

User Guides

Developer Guides

Enterprise

Backend

Deployment


βš™οΈ Configuration


πŸ“‘ API

API Documentation


πŸš€ Deployment


πŸ“š Reference

Architecture

Quick Reference


πŸ” Security


πŸ†˜ Help


ℹ️ About


πŸ”— Links


v1.0.0 β€’ 2026

Clone this wiki locally