AI summary by TwinMind
React's New Controversial Override
Theo - t3․gg
13m 1s
React's Date API Patching Plan
- React planning to patch Date API during SSR and hydration in future release
- Similar to previous controversial fetch patching that was reverted
- Andrew's tweet thread sparked discussion about this upcoming change
- Expected to be controversial due to general opposition to API patching
Patching vs Polyfills Context
- Patching built-in APIs acceptable when standards compliant
- Polyfills widely accepted and used automatically by build tools
- Common practice to polyfill even supported browser features for IE compatibility
- Frameworks handle polyfilling automatically without developer awareness
Smoosh Gate Historical Context
- Classic anti-patching example involving MooTools library
- MooTools patched Array prototype with additional behaviors
- JavaScript proposal for Array.prototype.flatten broke websites using MooTools
- Web incompatibility forced rename consideration (jokingly suggested "smoosh")
- Global namespace pollution prevents future browser implementations
- Web's commitment to not breaking existing websites creates ongoing constraints
Next.js Fetch Patching Comparison
- Next.js fetch caching behavior controversial due to confusing implementation
- Problem not patching itself but unclear caching behavior
- Would be equally controversial if implemented via service worker
- Education and dev tools major challenges for Next.js caching
- Server-side fetch relatively new (undici recently added as official Node.js fetch)
- React's patches target server-side only, not client browser code
Hydration Error Problem Demonstration
- Date objects generate different results on server vs client
- Server/client timezone differences cause mismatches
- Example:
new date()called twice produces different timestamps - Client components run code on both server and client
- Server generates HTML, client reruns code for hydration
- Mismatch between server HTML and client recreation causes hydration errors
Current Solutions and Workarounds
- Move date generation to server-only components
- Pass date strings as props to client components
- Restructure app to avoid running date code in both environments
- Example: Extract time display to separate server component
Proposed React Solution Details
- During hydration, return SSR time instead of browser's current time
- Ensures server and client get identical date values
- Prevents most common hydration error source
- Implementation details unclear but affects client-side Date behavior
Alternative Approaches Discussion
- Marco team's resumability approach mentioned
- Resumability uses HTML identifiers instead of code rerunning
- Still faces similar issues when expectations mismatch HTML
- Not necessarily superior solution for date/time problems
Implementation Concerns
- Patching Date behavior on client side feels misleading
- Uncertainty about how polyfill will work in practice
- Hope for cleaner implementation using network request data
- Most hydration errors stem from date/time issues
