Skip to content

feat: add @lazarv/rsc package and migrate RSC serialization to bundler-agnostic API#311

Merged
lazarv merged 11 commits into
mainfrom
feat/rsc
Feb 23, 2026
Merged

feat: add @lazarv/rsc package and migrate RSC serialization to bundler-agnostic API#311
lazarv merged 11 commits into
mainfrom
feat/rsc

Conversation

@lazarv

@lazarv lazarv commented Feb 22, 2026

Copy link
Copy Markdown
Owner

Summary

Introduces the new @lazarv/rsc package — a bundler-agnostic React Server Components (RSC) serialization and deserialization library — and migrates all internal RSC Flight protocol usage in @lazarv/react-server to use it.

New: @lazarv/rsc package (packages/rsc/)

A standalone package that wraps react-server-dom-webpack's Flight protocol behind a clean, bundler-agnostic API:

  • @lazarv/rsc/serverrenderToReadableStream() and prerenderToReadableStream() for server-side RSC serialization
  • @lazarv/rsc/clientcreateFromReadableStream() and createFromFetch() for client-side RSC deserialization
  • Uses a moduleResolver option pattern instead of requiring webpack-specific manifest objects
  • Full TypeScript type definitions (types.d.ts)
  • Comprehensive test suite (Flight protocol, streaming, references, error handling, cross-compat, edge cases, etc.)
  • Vitest configuration with coverage reporting

Migration in @lazarv/react-server

RSC serialization (cache/rsc.mjs)

  • Replaced direct react-server-dom-webpack/server.edge and client.edge imports with @lazarv/rsc/server and @lazarv/rsc/client
  • Switched from passing a webpack manifest map as a positional argument to using the new moduleResolver option
  • Removed the large createManifest() helper and its Proxy-based module map — no longer needed with the new API
  • Simplified fromBuffer() and fromStream() to pass options directly
  • rsc.mjs now works in both server and browser environments by gracefully handling absent clientReferenceMap

Console logger (client/error-overlay.mjs, lib/dev/logger-proxy.mjs)

  • Replaced the complex pattern of monkey-patching React.__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE and dynamically importing react-server-dom-webpack/server.browser with a direct import from @lazarv/rsc/server
  • Significantly simplified the console-forwarding code in both error overlay and RSC worker logger proxy

Dev server (lib/dev/create-server.mjs)

  • Replaced react-server-dom-webpack/client.edge import in handleClientConsole with @lazarv/rsc/client
  • Removed the serverConsumerManifest option — no longer required

Storage cache (cache/storage-cache.mjs)

  • Replaced Buffer.from().toString() calls with portable encodeBytes() / decodeBytes() helper functions using Uint8Array and btoa/atob for environments without Node.js Buffer

Logger improvements (lib/dev/create-logger.mjs)

  • Improved format() usage to handle format-string patterns even without an Error argument
  • Consolidated multi-line error logging into a single logger.error() call instead of one per line

use-cache plugin (lib/plugins/use-cache-inline.mjs)

  • local and session cache providers now declare type: "rsc" in their options, enabling proper RSC serialization for browser-side caches
  • The RSC serializer import is now conditional on whether any provider needs RSC serialization (hasRscProvider)

CI & Release

  • All CI test jobs now also trigger on packages/rsc changes
  • New test-rsc CI job runs pnpm test:coverage for the @lazarv/rsc package across Node 20/22/24 and multiple OS
  • publish-commit.yml includes @lazarv/rsc in pkg-pr-new publish
  • release-experimental.yml adds steps to publish @lazarv/rsc independently and update @lazarv/react-server's dependency on it

Tests

  • New test: use cache browser component — validates RSC-serialized component caching in localStorage/sessionStorage with TTL expiration
  • Updated RSC serialization assertion to match the new Flight format

@codecov-commenter

codecov-commenter commented Feb 22, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@lazarv lazarv merged commit baa07c1 into main Feb 23, 2026
107 of 108 checks passed
@lazarv lazarv deleted the feat/rsc branch February 23, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants