Skip to content

Commit d297195

Browse files
committed
Updated docs
1 parent a627b79 commit d297195

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/common/COMMON_ISSUES.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,65 @@ See `note.tsx` for grep and translate examples.
177177

178178
See `space-setup.tsx` for an example of handling this with prompts and cache busting.
179179

180+
## JSX in Utility Files
181+
182+
### Issue: Cannot Export JSX Components from Utility Files
183+
184+
**Symptom**: When trying to create reusable JSX components in utility files (e.g., `lib/my-utils.tsx`), you get compilation errors like:
185+
```
186+
[ERROR] This JSX tag requires 'h' to be in scope, but it could not be found.
187+
[ERROR] Module '"commontools"' has no exported member 'h'.
188+
```
189+
190+
**Cause**: JSX compilation requires `h` to be in scope, which is only available within recipe contexts. Utility files can't import or use JSX because they're not recipes.
191+
192+
**Solution**: Share utility functions instead of JSX components:
193+
194+
**✅ DO THIS** - Export pure functions from utility files:
195+
```typescript
196+
/// <cts-enable />
197+
198+
// lib/diff-utils.tsx
199+
export function computeWordDiff(from: string, to: string): DiffChunk[] {
200+
// Pure function logic - no JSX
201+
return [...];
202+
}
203+
```
204+
205+
Then use the function with inline JSX in your recipe:
206+
```typescript
207+
// my-pattern.tsx
208+
import { computeWordDiff } from "./lib/diff-utils.tsx";
209+
210+
export default recipe("MyPattern", ({ data }) => {
211+
return {
212+
[UI]: (
213+
<div>
214+
{computeWordDiff(data.from, data.to).map((part) => {
215+
if (part.type === "added") {
216+
return <span style={{ color: "green" }}>{part.word}</span>;
217+
}
218+
// ... more rendering
219+
})}
220+
</div>
221+
)
222+
};
223+
});
224+
```
225+
226+
**❌ DON'T DO THIS** - Try to export JSX components from utilities:
227+
```typescript
228+
// lib/diff-utils.tsx
229+
export function DiffText({ from, to }) { // Won't compile!
230+
return <div>{from} → {to}</div>; // Error: h not in scope
231+
}
232+
```
233+
234+
**Key Principles**:
235+
- Utility files: Export pure functions, types, and non-JSX logic
236+
- Recipe files: Use JSX and compose with utility functions
237+
- Use `/// <cts-enable />` directive at the top of utility files
238+
180239
## Transaction Conflicts and Retry Storms
181240

182241
If you see `ConflictError` messages in console, this is normal - the system retries transactions automatically. These warnings don't indicate a problem unless they occur continuously (retry storm).

0 commit comments

Comments
 (0)