DEV Community

Yuuichi Eguchi
Yuuichi Eguchi

Posted on

CapsuleRSC: Safe Server/Client Boundary Enforcement for React Server Components

Overview

CapsuleRSC is a minimal framework that enforces safe server/client boundaries for React Server Components (RSC) with strong, mechanical guarantees.

It does not rely on conventions or developer discipline. Instead, CapsuleRSC enforces correctness through three explicit layers of defense:

  1. Type-level – TypeScript types prevent non-serializable data from crossing boundaries at compile time
  2. Build-time – An ESLint plugin detects boundary violations during development
  3. RuntimeassertSerializable provides a final line of defense at execution time

Why Boundaries Matter

React Server Components introduce a new constraint: data must cross from server to client in a safe, serializable form.

Without strict boundaries, subtle but serious problems appear:

  • Functions passed to client components cause runtime failures
  • Date objects silently become strings
  • Class instances lose their methods
  • Circular references crash serialization

CapsuleRSC prevents these issues by enforcing boundaries at every layer, not by assuming developers will remember the rules.


Core Principle

Do not assume boundaries are respected — enforce them mechanically.

CapsuleRSC exists to validate this principle through implementation, not theory.


How CapsuleRSC Differs from tRPC

CapsuleRSC and tRPC solve different problems at different layers.

  • tRPC focuses on type-safe API communication between server and client. It assumes the execution boundary already exists (HTTP/RPC).
  • CapsuleRSC focuses on mechanically enforcing the server/client execution boundary itself, which is especially fragile in React Server Components.

In short:

tRPC is about type-safe communication.
CapsuleRSC is about mechanically enforced execution boundaries.

They are not competitors and can be used together.


Demo

A live demo of CapsuleRSC is available as part of my portfolio.

  • Server/client boundary enforcement
  • Serialization guarantees
  • Capability-based side effects

Demo URL:

https://yuu1ch13-portfollio-tau-sepia.vercel.app/capsule-rsc


Repository

https://github.com/yuuichieguchi/capsule-rsc


Top comments (0)