AI summary by TwinMind

getServerSideProps is WEIRD

Theo - t3․gg

24m 19s

Introduction to getServerSideProps Issues

  • Next.js getServerSideProps was revolutionary initially - allowed backend data fetching in same file as component
  • Made metadata easier, enabled good SEO, revolutionized React code thinking
  • Patterns haven't aged well compared to better solutions like Remix, SolidStart, tRPC
  • Requires deep understanding of data flow before meaningful use

Four Main Problem Categories

  • Type safety issues
  • Data flow problems
  • Routing and conditional data challenges
  • Performance concerns

Type Safety Problems

  • Types are not correct/reliable
  • Demo setup issues with create-next-app:
    • Uses Yarn by default even when using npx (should respect package manager choice)
    • No semicolons by default
    • Template has errors (missing meta definitions)
    • Recommends using create-t3-app instead
  • Type inference issues:
    • InferGetServerSidePropsType can lie about available props
    • Easy to break type contracts through conditional rendering
    • Non-serializable data (like Date objects) causes runtime errors despite TypeScript approval
    • JSON serialization limitations - can't pass Date objects, functions, etc.
    • Remix loaders with proper typing will error on non-JSON serializable returns

Data Flow and Routing Issues

  • Complex, unintuitive data flow: getServerSideProps → document → app file → page component
  • Data flow is not deterministic - fetching data doesn't guarantee it reaches component
  • Conditional rendering can break prop drilling
  • Example: auth state check can prevent page props from reaching component
  • Top-down data requirements - must know all page data needs upfront
  • Components deep in tree requiring data forces prop drilling through multiple layers
  • All component data needs must be anticipated in getServerSideProps function

Component-Level Data Fetching Problems

  • Components used across multiple pages create data architecture complexity
  • No clean way to fetch data at component level
  • Alternative approaches:
    • tRPC with create-t3-app: minimal SSR, component-level data requests
    • SolidStart: component-level getData functions
    • Next SWR endpoints improving these flows
  • Current pattern requires understanding entire data flow before implementation

Performance Issues

  • Blocks first byte on data requests - bad user experience
  • User sees blank page during entire data fetch duration
  • Can take 3+ seconds with heavy implementations (e.g., Prisma)
  • Requires caching layers for performance, which breaks auth use cases
  • Cold start delays with Lambda functions
  • Blocking HTML delivery significantly longer than necessary

Comparison with Better Patterns

  • tRPC approach: render minimal static HTML, then batch data requests based on rendered components
  • Solid Start: component-level data functions with better DX
  • Next SWR endpoints: improving component-level data flows
  • These allow components to import needed data rather than implicit top-level fetching

Future Outlook

  • New Next.js RFC promises to solve these problems
  • Current getServerSideProps feels more like anti-pattern than feature
  • Was revolutionary initially but now rough in current state
  • Recommendation: avoid if possible until improvements arrive

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