AI summary by TwinMind

Phoenix LiveView Is Making Me Reconsider React...

Theo - t3․gg

36m 58s

LiveView 1.0 RC Release Overview

  • LiveView 1.0 rc0 released after almost 6 years of development
  • First commit October 18th, 2018
  • Goal: create dynamic server-rendered apps without writing JavaScript
  • Alternative to WASM/Rust-in-browser approaches that haven't gained adoption

Core Problem Statement & Solution Philosophy

  • Traditional stack complexity: HTTP glue, GraphQL schemas, validation logic duplication, localization, serializers, websockets, IPC, JS bundle management
  • Solution: remove HTTP concerns entirely, server handles all rendering and dynamic updates
  • Programming model feels like "cheating" - fast, tiny payloads, best-in-class latency
  • Less code to write, fewer concepts to think about

Technical Architecture & Optimizations

LiveView Diffing Engine

  • Splits templates into static and dynamic parts at compile time
  • Static parts never change, sent once on mount
  • Dynamic parts tracked with change detection based on variables accessed
  • Only executes template expressions when values actually change
  • Network updates send only changed dynamic values with their indices

Performance Benefits

  • Payloads smaller than handwritten JSON APIs or GraphQL queries
  • Virtual DOM implementation for efficient client-side updates
  • Automatic optimizations including fingerprinting, tree shaking
  • VKs migrated from React to Phoenix LiveView due to faster client rendering

Connection Management

  • Stateful websocket connection for entire user session
  • Single TLS handshake, authentication happens once
  • Page navigation via single websocket frame
  • Fewer database queries per client action
  • ~40KB memory per connection = 25,000 concurrent users per 1GB server

Component System (HEEx)

  • HTML-aware declarative component system developed by Marcus from Surface project
  • Compile-time validation of component attributes and slots
  • Components are annotated functions with type checking
  • Slot system allows extensible components without bespoke templates
  • Debug features: HTML comments show source file/line, click-to-jump-to-code

Advanced Features

Interactive Uploads

  • Single abstraction for direct-to-cloud and direct-to-server uploads
  • Drag-and-drop, progress tracking, file previews built-in
  • Upload writer behavior for raw stream access during chunking
  • Stream uploads to different servers, transcode video during upload
  • Progress reflection trivial due to existing LiveView connection

Async Operations & Streams

  • assign_async primitive offloads operations to separate processes
  • async_result renders loading/success/failure states (similar to React Suspense)
  • Automatic cleanup of async processes when LiveView disconnects
  • Streams primitive for large collections without holding in server memory

Hot Code Deployment Demo

  • Production hot code upgrades while maintaining browser connections
  • Deploy new release → websocket automatically updates CSS and content
  • Contrast with Vercel's skew protection (keeping old backends around)
  • Elixir VM allows swapping running code without taking down server
  • Guarantees client-server sync through live updates

Global Distributed Demo

  • 350 lines of code for planet-wide app with cluster work aggregation
  • Real-time results streamed back to UI
  • Flame integration for provisioning machines and running distributed tasks
  • Demonstrates Elixir VM's networking capabilities

Industry Context & Comparisons

Acknowledgment of React's Value

  • Explicitly credits React for declarative programming model benefits
  • Working to catch up rather than dismissing client-side innovations
  • Recognizes composability problems that React solved

Comparison with Other Approaches

  • Most other server-rendering solutions require manual element update annotations
  • Large payloads sent on every event unless manually fine-tuned
  • React Server Components tackle similar goals but lack real-time event support
  • HTMx mentioned as good starting point for similar concepts

Authentication & API Efficiency

  • Traditional client-side apps require multiple authentication calls per page load
  • Example: topnav + sidebar + content = 3 separate auth requests
  • Server components reduce this to single auth + streaming responses
  • Significantly lower server costs due to reduced request volume

Platform Advantages

  • Elixir/Erlang VM uniquely suited for stateful bidirectional communication
  • Built-in globally distributed clustering and pubsub
  • Most platforms poorly suited for scalable bidirectional layers
  • WhatsApp, Discord examples of Erlang VM scaling to millions of users

Future Roadmap

  • Collocated JavaScript hooks
  • Web component integration
  • Navigation guards
  • Continued ecosystem development

Development Experience Improvements

  • Real-time server logs streamed to JS console in development
  • Better error messages than most languages
  • Tailwind CSS heavily adopted in Elixir community
  • Vim integration for click-to-source functionality

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome