Skip to content

Commit 9e5734f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into perf-track-diagram
2 parents e369ebd + 046f17d commit 9e5734f

271 files changed

Lines changed: 45878 additions & 2063 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/settings.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"Skill(docs-voice)",
1717
"Skill(docs-components)",
1818
"Skill(docs-sandpack)",
19+
"Skill(docs-rsc-sandpack)",
1920
"Skill(docs-writer-learn)",
2021
"Skill(docs-writer-reference)",
2122
"Bash(yarn lint:*)",
Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
---
2+
name: docs-rsc-sandpack
3+
description: Use when adding interactive RSC (React Server Components) code examples to React docs using <SandpackRSC>, or when modifying the RSC sandpack infrastructure.
4+
---
5+
6+
# RSC Sandpack Patterns
7+
8+
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.
9+
10+
## Quick Start Template
11+
12+
Minimal single-file `<SandpackRSC>` example:
13+
14+
```mdx
15+
<SandpackRSC>
16+
17+
` ` `js src/App.js
18+
export default function App() {
19+
return <h1>Hello from a Server Component!</h1>;
20+
}
21+
` ` `
22+
23+
</SandpackRSC>
24+
```
25+
26+
---
27+
28+
## How It Differs from `<Sandpack>`
29+
30+
| Feature | `<Sandpack>` | `<SandpackRSC>` |
31+
|---------|-------------|-----------------|
32+
| Execution model | All code runs in iframe | Server code runs in Web Worker, client code in iframe |
33+
| `'use client'` directive | Ignored (everything is client) | Required to mark client components |
34+
| `'use server'` directive | Not supported | Marks Server Functions callable from client |
35+
| `async` components | Not supported | Supported (server components can be async) |
36+
| External dependencies | Supported via `package.json` | Not supported (only React + react-dom) |
37+
| Entry point | `App.js` with `export default` | `src/App.js` with `export default` |
38+
| Component tag | `<Sandpack>` | `<SandpackRSC>` |
39+
40+
---
41+
42+
## File Directives
43+
44+
Files are classified by the directive at the top of the file:
45+
46+
| Directive | Where it runs | Rules |
47+
|-----------|--------------|-------|
48+
| (none) | Web Worker (server) | Default. Can be `async`. Can import other server files. Cannot use hooks, event handlers, or browser APIs. |
49+
| `'use client'` | Sandpack iframe (browser) | Must be first statement. Can use hooks, event handlers, browser APIs. Cannot be `async`. Cannot import server files. |
50+
| `'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`. |
51+
52+
---
53+
54+
## Common Patterns
55+
56+
### 1. Server + Client Components
57+
58+
```mdx
59+
<SandpackRSC>
60+
61+
` ` `js src/App.js
62+
import Counter from './Counter';
63+
64+
export default function App() {
65+
return (
66+
<div>
67+
<h1>Server-rendered heading</h1>
68+
<Counter />
69+
</div>
70+
);
71+
}
72+
` ` `
73+
74+
` ` `js src/Counter.js
75+
'use client';
76+
77+
import { useState } from 'react';
78+
79+
export default function Counter() {
80+
const [count, setCount] = useState(0);
81+
return (
82+
<button onClick={() => setCount(count + 1)}>
83+
Count: {count}
84+
</button>
85+
);
86+
}
87+
` ` `
88+
89+
</SandpackRSC>
90+
```
91+
92+
### 2. Async Server Component with Suspense
93+
94+
```mdx
95+
<SandpackRSC>
96+
97+
` ` `js src/App.js
98+
import { Suspense } from 'react';
99+
import Albums from './Albums';
100+
101+
export default function App() {
102+
return (
103+
<Suspense fallback={<p>Loading...</p>}>
104+
<Albums />
105+
</Suspense>
106+
);
107+
}
108+
` ` `
109+
110+
` ` `js src/Albums.js
111+
async function fetchAlbums() {
112+
await new Promise(resolve => setTimeout(resolve, 1000));
113+
return ['Abbey Road', 'Let It Be', 'Revolver'];
114+
}
115+
116+
export default async function Albums() {
117+
const albums = await fetchAlbums();
118+
return (
119+
<ul>
120+
{albums.map(album => (
121+
<li key={album}>{album}</li>
122+
))}
123+
</ul>
124+
);
125+
}
126+
` ` `
127+
128+
</SandpackRSC>
129+
```
130+
131+
### 3. Server Functions (Actions)
132+
133+
```mdx
134+
<SandpackRSC>
135+
136+
` ` `js src/App.js
137+
import { addLike, getLikeCount } from './actions';
138+
import LikeButton from './LikeButton';
139+
140+
export default async function App() {
141+
const count = await getLikeCount();
142+
return (
143+
<div>
144+
<p>Likes: {count}</p>
145+
<LikeButton addLike={addLike} />
146+
</div>
147+
);
148+
}
149+
` ` `
150+
151+
` ` `js src/actions.js
152+
'use server';
153+
154+
let count = 0;
155+
156+
export async function addLike() {
157+
count++;
158+
}
159+
160+
export async function getLikeCount() {
161+
return count;
162+
}
163+
` ` `
164+
165+
` ` `js src/LikeButton.js
166+
'use client';
167+
168+
export default function LikeButton({ addLike }) {
169+
return (
170+
<form action={addLike}>
171+
<button type="submit">Like</button>
172+
</form>
173+
);
174+
}
175+
` ` `
176+
177+
</SandpackRSC>
178+
```
179+
180+
---
181+
182+
## File Structure Requirements
183+
184+
### Entry Point
185+
186+
- **`src/App.js` is required** as the main entry point
187+
- Must have `export default` (function component)
188+
- Case-insensitive fallback: `src/app.js` also works
189+
190+
### Auto-Injected Infrastructure Files
191+
192+
These files are automatically injected by `sandpack-rsc-setup.ts` and should never be included in MDX:
193+
194+
| File | Purpose |
195+
|------|---------|
196+
| `/src/index.js` | Bootstraps the RSC pipeline |
197+
| `/src/rsc-client.js` | Client bridge — creates Worker, consumes Flight stream |
198+
| `/src/rsc-server.js` | Wraps pre-bundled worker runtime as ES module |
199+
| `/node_modules/__webpack_shim__/index.js` | Minimal webpack compatibility layer |
200+
| `/node_modules/__rsdw_client__/index.js` | `react-server-dom-webpack/client` as local dependency |
201+
202+
### No External Dependencies
203+
204+
`<SandpackRSC>` does not support external npm packages. Only `react` and `react-dom` are available. Do not include `package.json` in RSC examples.
205+
206+
---
207+
208+
## Architecture Reference
209+
210+
### Three-Layer Architecture
211+
212+
```
213+
react.dev page (Next.js)
214+
┌─────────────────────────────────────────┐
215+
│ <SandpackRSC> │
216+
│ ┌─────────┐ ┌──────────────────────┐ │
217+
│ │ Editor │ │ Preview (iframe) │ │
218+
│ │ App.js │ │ Client React app │ │
219+
│ │ (edit) │ │ consumes Flight │ │
220+
│ │ │ │ stream from Worker │ │
221+
│ └─────────┘ └──────────┬───────────┘ │
222+
└───────────────────────────┼─────────────┘
223+
│ postMessage
224+
┌───────────────────────────▼─────────────┐
225+
│ Web Worker (Blob URL) │
226+
│ - React server build (pre-bundled) │
227+
│ - react-server-dom-webpack/server │
228+
│ - webpack shim │
229+
│ - User server code (Sucrase → CJS) │
230+
└─────────────────────────────────────────┘
231+
```
232+
233+
### Key Source Files
234+
235+
| File | Purpose |
236+
|-----------------------------------------------------------------|--------------------------------------------------------------------------------|
237+
| `src/components/MDX/Sandpack/sandpack-rsc/RscFileBridge.tsx` | Monitors Sandpack; posts raw files to iframe |
238+
| `src/components/MDX/Sandpack/SandpackRSCRoot.tsx` | SandpackProvider setup, custom bundler URL, UI layout |
239+
| `src/components/MDX/Sandpack/templateRSC.ts` | RSC template files |
240+
| `.../sandbox-code/src/__react_refresh_init__.js` | React Refresh shim |
241+
| `.../sandbox-code/src/rsc-server.js` | Worker runtime: module system, Sucrase compilation, `renderToReadableStream()` |
242+
| `.../sandbox-code/src/rsc-client.source.js` | Client bridge: Worker creation, file classification, Flight stream consumption |
243+
| `.../sandbox-code/src/webpack-shim.js` | Minimal `__webpack_require__` / `__webpack_module_cache__` shim |
244+
| `.../sandbox-code/src/worker-bundle.dist.js` | Pre-bundled IIFE (generated): React server + RSDW/server + Sucrase |
245+
| `scripts/buildRscWorker.mjs` | esbuild script: bundles rsc-server.js into worker-bundle.dist.js |
246+
247+
---
248+
249+
## Build System
250+
251+
### Rebuilding the Worker Bundle
252+
253+
After modifying `rsc-server.js` or `webpack-shim.js`:
254+
255+
```bash
256+
node scripts/buildRscWorker.mjs
257+
```
258+
259+
This runs esbuild with:
260+
- `format: 'iife'`, `platform: 'browser'`
261+
- `conditions: ['react-server', 'browser']` (activates React server export conditions)
262+
- `minify: true`
263+
- Prepends `webpack-shim.js` to the output
264+
265+
### Raw-Loader Configuration
266+
267+
In `templateRSC.js` files are loaded as raw strings with the `!raw-loader`.
268+
269+
The strings are necessary to provide to Sandpack as local files (skips Sandpack bundling).
270+
271+
272+
### Development Commands
273+
274+
```bash
275+
node scripts/buildRscWorker.mjs # Rebuild worker bundle after source changes
276+
yarn dev # Start dev server to test examples
277+
```

‎.claude/skills/docs-writer-blog/SKILL.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ See [How to Upgrade to React X.Y](/blog/YYYY/MM/DD/react-xy-upgrade-guide) for s
159159

160160
### React {/*react*/}
161161

162-
* Add `useNewHook` for [purpose]. ([#12345](https://github.com/facebook/react/pull/12345) by [@contributor](https://github.com/contributor))
162+
* Add `useNewHook` for [purpose]. ([#12345](https://github.com/react/react/pull/12345) by [@contributor](https://github.com/contributor))
163163

164164
---
165165

@@ -603,7 +603,7 @@ npm install react@latest react-dom@latest
603603

604604
| Type | Pattern |
605605
|------|---------|
606-
| GitHub PR | `[#12345](https://github.com/facebook/react/pull/12345)` |
606+
| GitHub PR | `[#12345](https://github.com/react/react/pull/12345)` |
607607
| GitHub user | `[@username](https://github.com/username)` |
608608
| Twitter/X | `[@username](https://x.com/username)` |
609609
| Bluesky | `[Name](https://bsky.app/profile/handle)` |
@@ -623,8 +623,8 @@ For more information, see the docs for [`useActionState`](/reference/react/useAc
623623
### Bullet Pattern
624624

625625
```markdown
626-
* Add `useTransition` for concurrent rendering. ([#10426](https://github.com/facebook/react/pull/10426) by [@acdlite](https://github.com/acdlite))
627-
* Fix `useReducer` observing incorrect props. ([#22445](https://github.com/facebook/react/pull/22445) by [@josephsavona](https://github.com/josephsavona))
626+
* Add `useTransition` for concurrent rendering. ([#10426](https://github.com/react/react/pull/10426) by [@acdlite](https://github.com/acdlite))
627+
* Fix `useReducer` observing incorrect props. ([#22445](https://github.com/react/react/pull/22445) by [@josephsavona](https://github.com/josephsavona))
628628
```
629629

630630
**Structure:** `Verb` + backticked API + description + `([#PR](url) by [@user](url))`

‎.claude/skills/react-expert/SKILL.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This skill produces exhaustive documentation research on any React API or concep
3232
2. **React Source Code** - Warnings, errors, implementation details
3333
3. **Git History** - Commit messages with context
3434
4. **GitHub PRs & Comments** - Design rationale (via `gh` CLI)
35-
5. **GitHub Issues** - Confusion/questions (facebook/react + reactjs/react.dev)
35+
5. **GitHub Issues** - Confusion/questions (react/react + reactjs/react.dev)
3636
6. **React Working Group** - Design discussions for newer APIs
3737
7. **Flow Types** - Source of truth for type signatures
3838
8. **TypeScript Types** - Note discrepancies with Flow
@@ -51,7 +51,7 @@ First, ensure the React repo is available locally:
5151
if [ -d ".claude/react" ]; then
5252
cd .claude/react && git pull origin main
5353
else
54-
git clone --depth=100 https://github.com/facebook/react.git .claude/react
54+
git clone --depth=100 https://github.com/react/react.git .claude/react
5555
fi
5656
```
5757

@@ -71,8 +71,8 @@ Spawn these agents IN PARALLEL using the Task tool. Each agent receives the skep
7171
| test-explorer | Explore | Test files for usage patterns | Search `.claude/react/packages/*/src/__tests__/` for test files mentioning the topic. Extract actual usage examples WITH file paths and line numbers. |
7272
| source-explorer | Explore | Warnings/errors in source | Search `.claude/react/packages/*/src/` for console.error, console.warn, and error messages mentioning the topic. Document trigger conditions. |
7373
| git-historian | Explore | Commit messages | Run `git log --all --grep="<topic>" --oneline -50` in `.claude/react`. Read full commit messages for context. |
74-
| pr-researcher | Explore | PRs introducing/modifying API | Run `gh pr list -R facebook/react --search "<topic>" --state all --limit 20`. Read key PR descriptions and comments. |
75-
| issue-hunter | Explore | Issues showing confusion | Search issues in both `facebook/react` and `reactjs/react.dev` repos. Look for common questions and misunderstandings. |
74+
| pr-researcher | Explore | PRs introducing/modifying API | Run `gh pr list -R react/react --search "<topic>" --state all --limit 20`. Read key PR descriptions and comments. |
75+
| issue-hunter | Explore | Issues showing confusion | Search issues in both `react/react` and `reactjs/react.dev` repos. Look for common questions and misunderstandings. |
7676
| types-inspector | Explore | Flow + TypeScript signatures | Find Flow types in `.claude/react/packages/*/src/*.js` (look for `@flow` annotations). Find TS types in `.claude/react/packages/*/index.d.ts`. Note discrepancies. |
7777

7878
### Step 3: Agent Prompts
@@ -164,8 +164,8 @@ CRITICAL: Do NOT rely on your prior knowledge. Only report what you find in PRs.
164164

165165
Your task: Find PRs that introduced or modified <TOPIC>.
166166

167-
1. Run: gh pr list -R facebook/react --search "<topic>" --state all --limit 20 --json number,title,url
168-
2. For promising PRs, read details: gh pr view <number> -R facebook/react
167+
1. Run: gh pr list -R react/react --search "<topic>" --state all --limit 20 --json number,title,url
168+
2. For promising PRs, read details: gh pr view <number> -R react/react
169169
3. Look for:
170170
- The original RFC/motivation
171171
- Design discussions in comments
@@ -189,7 +189,7 @@ CRITICAL: Do NOT rely on your prior knowledge. Only report what you find in issu
189189

190190
Your task: Find issues that reveal common confusion about <TOPIC>.
191191

192-
1. Search facebook/react: gh issue list -R facebook/react --search "<topic>" --state all --limit 20 --json number,title,url
192+
1. Search react/react: gh issue list -R react/react --search "<topic>" --state all --limit 20 --json number,title,url
193193
2. Search reactjs/react.dev: gh issue list -R reactjs/react.dev --search "<topic>" --state all --limit 20 --json number,title,url
194194
3. For each issue, identify:
195195
- What the user was confused about
@@ -199,7 +199,7 @@ Your task: Find issues that reveal common confusion about <TOPIC>.
199199
Format your output as:
200200
## Common Confusion
201201
### Issue #<number>: <title>
202-
**Repo:** <facebook/react or reactjs/react.dev>
202+
**Repo:** <react/react or reactjs/react.dev>
203203
**Confusion:** <what they misunderstood>
204204
**Resolution:** <correct understanding>
205205
**Gotcha:** <if applicable>

0 commit comments

Comments
 (0)