Skip to content

Commit 87382b2

Browse files
committed
feat: add docs-writer-error skill for React error pages
1 parent 8b68ded commit 87382b2

File tree

1 file changed

+294
-0
lines changed
  • .claude/skills/docs-writer-error

1 file changed

+294
-0
lines changed
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
---
2+
name: docs-writer-error
3+
description: Use when writing or editing error pages in src/content/errors/. Provides error page structure, research workflow, and troubleshooting guide conventions.
4+
---
5+
6+
# Error Page Writer
7+
8+
## Persona
9+
10+
**Voice:** Empathetic debugger helping a frustrated developer
11+
**Tone:** Direct, diagnostic, reassuring — never condescending
12+
13+
## Voice & Style
14+
15+
For tone, capitalization, jargon, and prose patterns, invoke `/docs-voice`.
16+
17+
**Key tone adjustments for error pages:**
18+
- Developers arrive mid-debugging. Be concise and actionable.
19+
- Lead with "what happened" before "how to fix it."
20+
- Avoid "simply", "just", "easy" — the developer is already stuck.
21+
- Use "you" to address the reader directly.
22+
- Name the specific React behavior that triggered the error.
23+
24+
## Workflow: Research First
25+
26+
Before writing any error page, you must research the error thoroughly.
27+
28+
### Step 1: Invoke `/react-expert` in Error Code Mode
29+
30+
Run:
31+
```
32+
/react-expert error <CODE>
33+
```
34+
35+
This dispatches 7 parallel research agents that will:
36+
- Find every throw site for this error in the React source
37+
- Find test files that trigger this error
38+
- Search GitHub issues for user reports of this error
39+
- Search the web for Stack Overflow questions, blog posts, and forum discussions to understand how real developers encounter and struggle with this error
40+
- Find PRs and commits for design context
41+
42+
Wait for the research to complete. The output will be saved to `.claude/research/error-<CODE>.md`.
43+
44+
### Step 2: Analyze the Research
45+
46+
From the research output, determine:
47+
1. **What the error message means** — use throw site conditions and `%s` argument context
48+
2. **Common causes** — prioritize by:
49+
- Frequency in web search results and GitHub issues (most common first)
50+
- What developers struggle with most (from web-researcher findings)
51+
- What scenarios are reproducible in Sandpack
52+
3. **Developer pain points** — what confuses people about this error? Use this to inform the prose explanation.
53+
4. **Related docs** — which existing react.dev pages help explain the concepts involved
54+
55+
### Step 3: Write the Error Page
56+
57+
Place the file at `src/content/errors/{code}.md`. Use the template below.
58+
59+
## Page Template
60+
61+
```mdx
62+
<Intro>
63+
64+
In the minified production build of React, we avoid sending down full error messages in order to reduce the number of bytes sent over the wire.
65+
66+
</Intro>
67+
68+
We highly recommend using the development build locally when debugging your app since it tracks additional debug info and provides helpful warnings about potential problems in your apps, but if you encounter an exception while using the production build, this page will reassemble the original error message.
69+
70+
The full text of the error you just encountered is:
71+
72+
<ErrorDecoder />
73+
74+
## What This Error Means {/*what-this-error-means*/}
75+
76+
[Plain-language explanation. 1-3 paragraphs.]
77+
78+
## Common Causes {/*common-causes*/}
79+
80+
### Cause Title {/*cause-title*/}
81+
82+
[Explanation. 1-2 paragraphs.]
83+
84+
Here is an example of code that would trigger this error:
85+
86+
<Sandpack>
87+
88+
` ` `js
89+
// 🔴 This will cause the error
90+
[problem code]
91+
` ` `
92+
93+
</Sandpack>
94+
95+
[Transition sentence explaining the fix:]
96+
97+
<Sandpack>
98+
99+
` ` `js
100+
// ✅ Fixed: [what changed]
101+
[solution code]
102+
` ` `
103+
104+
</Sandpack>
105+
106+
## Related Documentation {/*related-documentation*/}
107+
108+
- [Link text](/path/to/page)
109+
```
110+
111+
## Section Guidelines
112+
113+
### Boilerplate (Required, Verbatim)
114+
115+
The `<Intro>` block, the paragraph about development builds, and `<ErrorDecoder />` must appear on every error page exactly as shown. Do not modify, reword, or omit any part.
116+
117+
### What This Error Means
118+
119+
- Open with: "This error occurs when [condition]."
120+
- Explain what React was doing when it threw the error.
121+
- If the message has `%s` placeholders, explain what each represents.
122+
- Do not repeat the error message text — `<ErrorDecoder />` already shows it.
123+
- Name the specific React concept involved.
124+
- Address the developer pain points found in research — if people commonly misunderstand why this error happens, address that confusion directly.
125+
126+
**Opening sentence patterns:**
127+
128+
| Category | Pattern |
129+
|----------|---------|
130+
| Hooks | "This error occurs when a Hook is called in a way that violates the [Rules of Hooks](/reference/rules/rules-of-hooks)." |
131+
| Rendering | "This error occurs when React encounters [invalid element/children] during rendering." |
132+
| Hydration | "This error occurs when the HTML generated by the server does not match what the client renders." |
133+
| Server Components | "This error occurs when a value that is not serializable is passed from a Server Component to a Client Component." |
134+
| Suspense | "This error occurs when a component suspends during rendering without a `<Suspense>` boundary to catch it." |
135+
136+
### Common Causes
137+
138+
- 1-4 causes per page. Most errors have 2-3.
139+
- Each cause gets its own `###` heading under `## Common Causes`.
140+
- Each cause must include: prose explanation, Problem Sandpack, Solution Sandpack.
141+
- Use descriptive headings: "Calling a Hook inside a condition", not "Cause 1".
142+
- **Order by real-world frequency**: Use web search and GitHub issue data from the research to determine which causes developers hit most often. The most common cause goes first.
143+
- **Address real confusion**: If the research shows developers struggle to understand why a particular pattern causes this error, explain it clearly in the prose.
144+
145+
### Related Documentation
146+
147+
- At least one link. Bulleted list.
148+
- Learn pages for concepts, Reference pages for APIs.
149+
- Format API links with backticks: [`useState`](/reference/react/useState)
150+
151+
## Sandpack Guidelines
152+
153+
For general Sandpack conventions, invoke `/docs-sandpack`.
154+
155+
### Problem Sandpacks
156+
157+
- Mark problematic code with `// 🔴`.
158+
- Keep examples minimal — only code needed to trigger the error.
159+
- Must have `export default` in main file.
160+
- **Base examples on real-world patterns** found in web search results — not abstract/contrived scenarios.
161+
162+
### Solution Sandpacks
163+
164+
- Mark fix with `// ✅ Fixed: [description]`.
165+
- Change only what's necessary. Don't refactor unrelated code.
166+
- Must be runnable and produce a visible result.
167+
168+
### Transition Sentences Between Pairs
169+
170+
- "To fix this, move the Hook call to the top level of your component:"
171+
- "Instead, convert the value to a supported type before passing it:"
172+
- "To fix this, wrap the component in a `<Suspense>` boundary:"
173+
174+
### When Sandpack Can't Reproduce the Error
175+
176+
Use plain fenced code blocks instead:
177+
178+
```mdx
179+
This error occurs during server rendering. The problematic pattern looks like this:
180+
181+
` ` `js
182+
// 🔴 This will cause the error during server rendering
183+
function App() {
184+
return <ServerComponent data={new Map()} />;
185+
}
186+
` ` `
187+
```
188+
189+
### Multi-File Sandpacks
190+
191+
Use when the error involves component relationships (parent/child, server/client):
192+
193+
```mdx
194+
<Sandpack>
195+
196+
` ` `js src/App.js active
197+
import Child from './Child';
198+
199+
export default function App() {
200+
// 🔴 Passing an invalid value to Child
201+
return <Child data={Symbol('test')} />;
202+
}
203+
` ` `
204+
205+
` ` `js src/Child.js
206+
export default function Child({ data }) {
207+
return <div>{String(data)}</div>;
208+
}
209+
` ` `
210+
211+
</Sandpack>
212+
```
213+
214+
## Component Usage
215+
216+
For full component patterns, invoke `/docs-components`.
217+
218+
| Component | Use For |
219+
|-----------|---------|
220+
| `<Note>` | Edge cases, version differences |
221+
| `<Pitfall>` | A fix that introduces a new common mistake |
222+
| `<DeepDive>` | Why React enforces this rule (optional) |
223+
| `<ConsoleBlock level="error">` | Showing exact console output |
224+
225+
Use `<ConsoleBlock>` sparingly — only when the dev-mode message differs meaningfully from the production error.
226+
227+
## Handling Error Variations
228+
229+
### Errors That Are React Bugs
230+
231+
For errors saying "This is likely caused by a bug in React":
232+
233+
```mdx
234+
## What This Error Means {/*what-this-error-means*/}
235+
236+
This error indicates an internal invariant violation in React. It is not caused by your application code.
237+
238+
If you encounter this error, please [file an issue](https://github.com/facebook/react/issues/new?template=bug_report.md) on the React GitHub repository with a reproduction.
239+
```
240+
241+
Keep these pages minimal. Do not invent common causes.
242+
243+
### Server-Specific Errors
244+
245+
- Note that these errors occur on the server, not in the browser.
246+
- Use plain code blocks instead of Sandpack.
247+
- Link to RSC documentation.
248+
249+
### Hooks Errors
250+
251+
- Always link to [Rules of Hooks](/reference/rules/rules-of-hooks).
252+
- Common causes: conditional calls, calls in loops, calls outside components, mismatched React versions.
253+
254+
## Do's and Don'ts
255+
256+
**Do:**
257+
- Invoke `/react-expert error <CODE>` before writing
258+
- Use the boilerplate verbatim
259+
- Explain what `%s` placeholders represent
260+
- Show problem code before solution (problem-first)
261+
- Keep Sandpack examples minimal
262+
- Order causes by real-world frequency (from research)
263+
- Base examples on real developer scenarios (from web search)
264+
- Address common developer confusion (from research)
265+
- Link to at least one related docs page
266+
- Use `// 🔴` and `// ✅` markers
267+
268+
**Don't:**
269+
- Write error pages without research
270+
- Add frontmatter to error pages
271+
- Modify the boilerplate text
272+
- Repeat the error message in prose
273+
- Include more than 4 causes
274+
- Use contrived/abstract examples when real-world patterns exist
275+
- Use `<Challenges>`, `<Recipes>`, `<YouWillLearn>`, or `<Recap>`
276+
- Use `<InlineToc />`
277+
- Use `---` section dividers
278+
- Place consecutive `<Pitfall>` or `<Note>` without separating prose
279+
280+
## Critical Rules
281+
282+
1. **Research first:** Always invoke `/react-expert error <CODE>` before writing.
283+
2. **Boilerplate is sacred:** `<Intro>`, dev build paragraph, and `<ErrorDecoder />` must appear verbatim.
284+
3. **No frontmatter:** Error pages have no YAML frontmatter.
285+
4. **All headings require IDs:** `## Title {/*title-id*/}` in kebab-case.
286+
5. **Problem-first Sandpacks:** Show broken code before the fix.
287+
6. **One pair per cause:** Each cause gets one problem + one solution Sandpack (or plain code blocks).
288+
7. **Real-world examples:** Base Sandpack examples on patterns from web research, not contrived scenarios.
289+
8. **No consecutive callouts:** Separate `<Pitfall>`/`<Note>` with prose.
290+
9. **Minimal examples:** Keep Sandpack files under 50 lines when possible.
291+
10. **File naming:** `{code}.md` in `src/content/errors/`.
292+
11. **`export default` required:** All Sandpack main files need it.
293+
294+
For component patterns, invoke `/docs-components`. For Sandpack patterns, invoke `/docs-sandpack`.

0 commit comments

Comments
 (0)