AI summary by TwinMind
Theo Reacts: Ryan Florence's "Remixing React Router" Talk
Theo - t3․gg
47m 32s
Background and Introduction
- Speaker discusses React Router evolution, trajectory showing npm downloads growth over 8 years
- Goal: migrate users to Remix while improving React Router with Remix learnings
- React Router v6 development, bringing Remix features to client-side routing
Current Data Fetching Problems
- Status quo: custom
useFetchhooks with multiple issues- Can't use async functions directly in useEffect
- Need error handling, loading states
- URL changes don't update UI without proper state management
- Race conditions when clicking links rapidly (out-of-order responses)
- Need abort controllers for request cancellation
- Remote component updates require complex refetch coordination
React Query Limitations
- React Query solves many DIY fetching problems
- Still creates waterfall loading patterns
- Multiple loading spinners appear sequentially
- User sees 5 different loading states on faster internet
- Component still handles: initiating fetch, reading result, rendering fallback
- Parent fallback blocks child component fetch initialization
Solution: Decoupling Fetch Concerns
- Need to separate: initiating, reading, falling back (3 separate concerns)
- Initiate fetches before rendering to enable parallelization
- React 18/Server Components don't solve initiation timing
- RSC moves rendering/fetching to server, no opinion on initiation timing
- Suspense defines fallback locations, not initiation points
- Initiating under Suspense boundary creates component fetching waterfalls
React Router Loader API
- New
loaderfunction on routes - async function returning data - Web Fetch API support (Request/Response objects)
useLoaderDatahook - reads pre-initiated data, doesn't trigger fetch- Nested routes enable parallel data loading
- Route segments coupled to URL segments for predictable data needs
Before/After Code Comparison
- Before: 24 lines with useParams, useQuery, error/loading states
- After: ~10 lines with useLoaderData, no conditional rendering
- Compatible with React Query - can initiate in loader, read with useQuery
- Type safety story still needs work
Performance Improvements
- Network waterfall eliminated - all requests parallel
- Page load time reduced ~50% through parallelization
- Loading states consolidated
- Time to Interactive = Largest Contentful Paint (no intermediate states)
Server-Side Rendering Benefits
- Server knows URL, can initiate fetches server-side
- Further performance gains but slower Time to First Byte
- Trade-off lever: fast TTFB vs better LCP/reduced layout shift
- Static generation options available for optimal TTFB
Transitions and Prefetching
- Same parallel loading benefits apply to client-side navigation
- Prefetch on intent (hover/focus) using
prefetch="intent"prop - Users operate in seconds, not milliseconds - sufficient time for prefetching
- Smart partial fetching - only refetch changed route segments
Streaming Implementation
- 18 React logos represent streaming concept
- Server sends initial document chunk with assets/spinners
- Browser downloads JS/CSS while server fetches data
- Everything happens in parallel during streaming window
- CSS still blocks render, but starts downloading earlier
Live Demo Results
- Without streaming: 4.8s DOM content loaded
- With streaming: 3s DOM content loaded
- Granular control with
awaitkeyword as "lever" defer()function instead ofjson()enables streaming mode- Selective awaiting: critical data waits, non-critical streams
API Design Philosophy
- "Levers" concept - simple APIs for performance trade-offs
awaitkeyword controls what blocks initial render- Deferred data streams in after initial paint
- Cache headers and cookies still supported with streaming
