MCPInstall

docs-rsc-sandpack

Use when adding interactive RSC (React Server Components) code examples to React docs using , or when modifying the RSC sandpack infrastructure.

Installs
62
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/reactjs/react.dev --skill docs-rsc-sandpack
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads docs-rsc-sandpack automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

RSC Sandpack Patterns

For general Sandpack conventions (code style, naming, file naming, line highlighting, hidden files, CSS guidelines), see /docs-sandpack. This skill covers only RSC-specific patterns.

Quick Start Template

Minimal single-file <SandpackRSC> example:

<SandpackRSC>

` ` `js src/App.js
export default function App() {
  return <h1>Hello from a Server Component!</h1>;
}
` ` `

</SandpackRSC>

How It Differs from <Sandpack>

Feature<Sandpack><SandpackRSC>
Execution modelAll code runs in iframeServer code runs in Web Worker, client code in iframe
'use client' directiveIgnored (everything is client)Required to mark client components
'use server' directiveNot supportedMarks Server Functions callable from client
async componentsNot supportedSupported (server components can be async)
External dependenciesSupported via package.jsonNot supported (only React + react-dom)
Entry pointApp.js with export defaultsrc/App.js with export default
Component tag<Sandpack><SandpackRSC>

File Directives

Files are classified by the directive at the top of the file:

DirectiveWhere it runsRules
(none)Web Worker (server)Default. Can be async. Can import other server files. Cannot use hooks, event handlers, or browser APIs.
'use client'Sandpack iframe (browser)Must be first statement. Can use hooks, event handlers, browser APIs. Cannot be async. Cannot import server files.
'use server'Web Worker (server)Marks Server Functions. Can be module-level (all exports are actions) or function-level. Callable from client via props or form action.

Common Patterns

1. Server + Client Components

<SandpackRSC>

` ` `js src/App.js
import Counter from './Counter';

export default function App() {
  return (
    <div>
      <h1>Server-rendered heading</h1>
      <Counter />
    </div>
  );
}
` ` `

` ` `js src/Counter.js
'use client';

import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);
  return (
    <button onClick={() => setCount(count + 1)}>
      Count: {count}
    </button>
  );
}
` ` `

</SandpackRSC>

2. Async Server Component with Suspense

<SandpackRSC>

` ` `js src/App.js
import { Suspense } from 'react';
import Albums from './Albums';

export default function App() {
  return (
    <Suspense fallback={<p>Loading...</p>}>
      <Albums />
    </Suspense>
  );
}
` ` `

` ` `js src/Albums.js
async function fetchAlbums() {
  await new Promise(resolve => setTimeout(resolve, 1000));
  return ['Abbey Road', 'Let It Be', 'Revolver'];
}

export default async function Albums() {
  const albums = await fetchAlbums();
  return (
    <ul>
      {albums.map(album => (
        <li key={album}>{album}</li>
      ))}
    </ul>
  );
}
` ` `

</SandpackRSC>

3. Server Functions (Actions)

<SandpackRSC>

` ` `js src/App.js
import { addLike, getLikeCount } from './actions';
import LikeButton from './LikeButton';

export default async function App() {
  const count = await getLikeCount();
  return (
    <div>
      <p>Likes: {count}</p>
      <LikeButton addLike={addLike} />
    </div>
  );
}
` ` `

` ` `js src/actions.js
'use server';

let count = 0;

export async function addLike() {
  count++;
}

export async function getLikeCount() {
  return count;
}
` ` `

` ` `js src/LikeButton.js
'use client';

export default function LikeButton({ addLike }) {
  return (
    <form action={addLike}>
      <button type="submit">Like</button>
    </form>
  );
}
` ` `

</SandpackRSC>

File Structure Requirements

Entry Point

  • src/App.js is required as the main entry point
  • Must have export default (function component)
  • Case-insensitive fallback: src/app.js also works

Auto-Injected Infrastructure Files

These files are automatically injected by sandpack-rsc-setup.ts and should never be included in MDX:

FilePurpose
/src/index.jsBootstraps the RSC pipeline
/src/rsc-client.jsClient bridge — creates Worker, consumes Flight stream
/src/rsc-server.jsWraps pre-bundled worker runtime as ES module
/node_modules/__webpack_shim__/index.jsMinimal webpack compatibility layer
/node_modules/__rsdw_client__/index.jsreact-server-dom-webpack/client as local dependency

No External Dependencies

<SandpackRSC> does not support external npm packages. Only react and react-dom are available. Do not include package.json in RSC examples.


Architecture Reference

Three-Layer Architecture

react.dev page (Next.js)
  ┌─────────────────────────────────────────┐
  │  <SandpackRSC>                          │
  │  ┌─────────┐  ┌──────────────────────┐  │
  │  │ Editor  │  │ Preview (iframe)     │  │
  │  │ App.js  │  │ Client React app     │  │
  │  │ (edit)  │  │ consumes Flight      │  │
  │  │         │  │ stream from Worker   │  │
  │  └─────────┘  └──────────┬───────────┘  │
  └───────────────────────────┼─────────────┘
                              │ postMessage
  ┌───────────────────────────▼─────────────┐
  │  Web Worker (Blob URL)                  │
  │  - React server build (pre-bundled)     │
  │  - react-server-dom-webpack/server      │
  │  - webpack shim                         │
  │  - User server code (Sucrase → CJS)    │
  └─────────────────────────────────────────┘

Key Source Files

FilePurpose
src/components/MDX/Sandpack/sandpack-rsc/RscFileBridge.tsxMonitors Sandpack; posts raw files to iframe
src/components/MDX/Sandpack/SandpackRSCRoot.tsxSandpackProvider setup, custom bundler URL, UI layout
src/components/MDX/Sandpack/templateRSC.tsRSC template files
.../sandbox-code/src/__react_refresh_init__.jsReact Refresh shim
.../sandbox-code/src/rsc-server.jsWorker runtime: module system, Sucrase compilation, renderToReadableStream()
.../sandbox-code/src/rsc-client.source.jsClient bridge: Worker creation, file classification, Flight stream consumption
.../sandbox-code/src/webpack-shim.jsMinimal __webpack_require__ / __webpack_module_cache__ shim
.../sandbox-code/src/worker-bundle.dist.jsPre-bundled IIFE (generated): React server + RSDW/server + Sucrase
scripts/buildRscWorker.mjsesbuild script: bundles rsc-server.js into worker-bundle.dist.js

Build System

Rebuilding the Worker Bundle

After modifying rsc-server.js or webpack-shim.js:

node scripts/buildRscWorker.mjs

This runs esbuild with:

  • format: 'iife', platform: 'browser'
  • conditions: ['react-server', 'browser'] (activates React server export conditions)
  • minify: true
  • Prepends webpack-shim.js to the output

Raw-Loader Configuration

In templateRSC.js files are loaded as raw strings with the !raw-loader.

The strings are necessary to provide to Sandpack as local files (skips Sandpack bundling).

Development Commands

node scripts/buildRscWorker.mjs   # Rebuild worker bundle after source changes
yarn dev                           # Start dev server to test examples

FAQ

What does the docs-rsc-sandpack skill do?

Use when adding interactive RSC (React Server Components) code examples to React docs using , or when modifying the RSC sandpack infrastructure.

How do I install docs-rsc-sandpack?

Run npx skills add https://github.com/reactjs/react.dev --skill docs-rsc-sandpack in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/docs-rsc-sandpack/ (personal) or .claude/skills/docs-rsc-sandpack/ (project).

Which AI agents can use docs-rsc-sandpack?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is docs-rsc-sandpack safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains docs-rsc-sandpack?

It is published by reactjs in reactjs/react.dev. It has 62 recorded installs.

More from reactjs/react.dev

View all →

react-expert

reactjs/react.dev

Use when researching React APIs or concepts for documentation. Use when you need authoritative usage examples, caveats, warnings, or errors for a React feature.

Frontend & Design1.3K installs

docs-components

reactjs/react.dev

Comprehensive MDX component patterns (Note, Pitfall, DeepDive, Recipes, etc.) for all documentation types. Authoritative source for component usage, examples, and heading conventions.

Docs & Writing88 installs

docs-sandpack

reactjs/react.dev

Use when adding interactive code examples to React docs.

Docs & Writing83 installs

review-docs

reactjs/react.dev

Use when reviewing React documentation for structure, components, and style compliance

Docs & Writing78 installs

docs-writer-learn

reactjs/react.dev

Use when writing or editing files in src/content/learn/. Provides Learn page structure and tone.

Docs & Writing70 installs

docs-writer-reference

reactjs/react.dev

Reference page structure, templates, and writing patterns for src/content/reference/. For components, see /docs-components. For code examples, see /docs-sandpack.

Docs & Writing70 installs

Popular docs & writing skills

View category →

grill-with-docs

mattpocock/skills

A relentless interview to sharpen a plan or design, which also creates docs (ADR's and glossary) as we go.

Docs & Writing1.2M installs

lark-markdown

open.feishu.cn

飞书 Markdown:查看、创建、上传、编辑和比较飞书中的原生 Markdown 文件。当用户要操作飞书 Markdown 文件,或比较其远端版本及本地草稿时使用。纯本地 Markdown 文件操作不触发本 skill。不负责将 Markdown 导入为飞书在线文档,也不负责文件搜索、权限、评论、移动、删除等云空间管理操作。

Docs & Writing778.7K installs

writing-beats

mattpocock/skills

Writing, exploit; assemble raw material into a journey of beats, grounding each term before a beat leans on it.

Docs & Writing490.7K installs

writing-shape

mattpocock/skills

Writing, exploit: shape raw material into an article, paragraph by paragraph.

Docs & Writing490.2K installs

writing-fragments

mattpocock/skills

Writing, explore: mine raw fragments, no structure yet.

Docs & Writing489.6K installs

writing-for-agents

mattpocock/skills

Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.

Docs & Writing479.3K installs