{"id":14882,"library":"react-server-dom-bun","title":"React Server Components for Bun (DOM)","description":"This package provides experimental bindings for React Server Components (RSC) specifically targeting the DOM environment and leveraging the Bun runtime. It is *not* designed for direct consumption by application developers, but rather as an internal utility for meta-frameworks to integrate RSC functionality. Being `0.0.0-experimental`, its API is highly unstable and subject to frequent changes, as evidenced by recent releases focusing on Denial-of-Service (DoS) mitigations, cycle protections, and general hardening. It is part of the broader React ecosystem, maintained by Facebook, and its release cadence is tied to React's experimental and canary channels. This means frequent, often internal-facing updates rather than strict semantic versioning, reflecting its role in cutting-edge React development. Key differentiators include its tight integration with Bun for performance and its essential role in enabling full-stack React Server Components rendering paradigms, bridging the server and client in a web application.","status":"active","version":"0.0.0-experimental-603e6108-20241029","language":"javascript","source_language":"en","source_url":"https://github.com/facebook/react","tags":["javascript","react"],"install":[{"cmd":"npm install react-server-dom-bun","lang":"bash","label":"npm"},{"cmd":"yarn add react-server-dom-bun","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-server-dom-bun","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Used by meta-frameworks to render React Server Components to a stream on the server. The package is not for direct application use.","wrong":"const { renderToReadableStream } = require('react-server-dom-bun/server');","symbol":"renderToReadableStream","correct":"import { renderToReadableStream } from 'react-server-dom-bun/server';"},{"note":"Intended for internal use by meta-frameworks to parse client-to-server communication for Server Actions. Note the `/client` subpath.","wrong":"import { decodeReply } from 'react-server-dom-bun';","symbol":"decodeReply","correct":"import { decodeReply } from 'react-server-dom-bun/client';"},{"note":"Used internally by meta-frameworks on the client-side to hydrate React Server Components from a readable stream. Requires the `/client` subpath.","wrong":"import { createFromReadableStream } from 'react-server-dom-bun/server';","symbol":"createFromReadableStream","correct":"import { createFromReadableStream } from 'react-server-dom-bun/client';"}],"quickstart":{"code":"import { renderToReadableStream } from 'react-server-dom-bun/server';\n\n// IMPORTANT: This package is NOT for direct application use.\n// This quickstart demonstrates how a meta-framework *might* internally\n// use react-server-dom-bun to render a React Server Component.\n\n// Assume a simple Server Component for demonstration\nfunction App() {\n  return (\n    <html>\n      <head>\n        <title>Bun RSC Demo</title>\n      </head>\n      <body>\n        <h1>Hello from React Server Component on Bun!</h1>\n        <p>Current time: {new Date().toLocaleTimeString()}</p>\n      </body>\n    </html>\n  );\n}\n\n// A simplified Bun server implementation for illustration purposes.\n// In a real meta-framework, this would be part of a much larger setup.\nconst server = Bun.serve({\n  port: 3000,\n  async fetch(req: Request) {\n    const url = new URL(req.url);\n\n    if (url.pathname === '/') {\n      const stream = await renderToReadableStream(<App />);\n      return new Response(stream, {\n        headers: { 'Content-Type': 'text/html' }\n      });\n    }\n\n    // Serve static assets (e.g., a client bundle if one existed)\n    if (url.pathname.startsWith('/src')) {\n      try {\n        const filePath = `.${url.pathname}`;\n        return new Response(Bun.file(filePath));\n      } catch (error) {\n        console.error(`Error serving static file: ${url.pathname}`, error);\n        return new Response('Not Found', { status: 404 });\n      }\n    }\n\n    return new Response('Not Found', { status: 404 });\n  },\n});\n\nconsole.log(`Bun Server Components server running on http://localhost:${server.port}`);","lang":"typescript","description":"Illustrates how a meta-framework might internally use `renderToReadableStream` to serve a React Server Component with Bun. Not intended for direct app use."},"warnings":[{"fix":"Avoid direct reliance on this package for application-level code. Treat it as an internal implementation detail for meta-frameworks only.","message":"This package is explicitly marked `0.0.0-experimental`. Its API is highly unstable, subject to frequent breaking changes, and not guaranteed to maintain backwards compatibility.","severity":"breaking","affected_versions":">=0.0.0-experimental-0"},{"fix":"If you are not building a meta-framework, use a framework like Next.js, Remix, or others that provide React Server Components integration out-of-the-box.","message":"The package description explicitly states: 'It is not intended to be imported directly.' Application developers should not use this package, but rather consume its functionality indirectly through a meta-framework that integrates React Server Components.","severity":"gotcha","affected_versions":">=0.0.0-experimental-0"},{"fix":"Meta-frameworks should ensure they are using the absolute latest experimental versions of `react-server-dom-bun` to benefit from the most recent security and stability improvements.","message":"Recent releases include critical security and stability patches, such as 'DoS mitigations to Server Actions' and 'cycle protections'. This indicates that previous experimental versions may have had vulnerabilities or instability, which are actively being addressed.","severity":"breaking","affected_versions":"<=19.2.4"},{"fix":"Ensure your project is configured to run with Bun if you are developing or testing a meta-framework that utilizes `react-server-dom-bun`.","message":"This package is specifically designed for the Bun runtime. Attempting to use it in Node.js or other JavaScript runtimes is unlikely to work correctly and may lead to runtime errors or unexpected behavior.","severity":"gotcha","affected_versions":">=0.0.0-experimental-0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Integrate React Server Components via a supported meta-framework (e.g., Next.js, Remix) that handles this package internally.","cause":"Attempting to import or use `react-server-dom-bun` directly in an application, rather than through a meta-framework.","error":"Error: This package is experimental and not intended for direct use."},{"fix":"Verify the correct import path (`/server` or `/client` subpath) and ensure your bundler/runtime correctly handles ESM imports from `react-server-dom-bun`.","cause":"Incorrect import path for ESM or CJS, or attempting to use a function that is not exported or available in the specific runtime environment or subpath.","error":"TypeError: (0, _react_server_dom_bun_server__WEBPACK_IMPORTED_MODULE_0__.renderToReadableStream) is not a function"},{"fix":"Ensure your server-side rendering environment is configured to use the Bun runtime for projects leveraging this package.","cause":"Attempting to run code using `react-server-dom-bun` in a non-Bun environment (e.g., Node.js, Deno).","error":"Invariant Violation: React Server Components require a Bun runtime."}],"ecosystem":"npm"}