@mandujs/mcp 0.9.19 → 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +320 -0
- package/package.json +1 -1
- package/src/activity-monitor.ts +847 -231
- package/src/resources/handlers.ts +244 -0
- package/src/resources/skills/guides.ts +1136 -0
- package/src/resources/skills/index.ts +12 -0
- package/src/resources/skills/loader.ts +218 -0
- package/src/resources/skills/mandu-composition/SKILL.md +91 -0
- package/src/resources/skills/mandu-composition/metadata.json +13 -0
- package/src/resources/skills/mandu-composition/rules/_sections.md +26 -0
- package/src/resources/skills/mandu-composition/rules/_template.md +77 -0
- package/src/resources/skills/mandu-composition/rules/comp-arch-avoid-boolean-props.md +146 -0
- package/src/resources/skills/mandu-composition/rules/comp-arch-compound-components.md +164 -0
- package/src/resources/skills/mandu-composition/rules/comp-island-event.md +161 -0
- package/src/resources/skills/mandu-composition/rules/comp-island-slot-split.md +167 -0
- package/src/resources/skills/mandu-composition/rules/comp-pattern-children.md +149 -0
- package/src/resources/skills/mandu-composition/rules/comp-state-context-interface.md +148 -0
- package/src/resources/skills/mandu-composition/rules/comp-state-lift-state.md +150 -0
- package/src/resources/skills/mandu-deployment/SKILL.md +92 -0
- package/src/resources/skills/mandu-deployment/_sections.md +41 -0
- package/src/resources/skills/mandu-deployment/_template.md +38 -0
- package/src/resources/skills/mandu-deployment/metadata.json +13 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-build-bun.md +109 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-build-output.md +115 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-cicd-github.md +219 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-docker-bun.md +150 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-docker-compose.md +223 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-fly.md +152 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-render.md +179 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-supabase.md +323 -0
- package/src/resources/skills/mandu-deployment/rules/deploy-platform-vercel.md +140 -0
- package/src/resources/skills/mandu-fs-routes/SKILL.md +82 -0
- package/src/resources/skills/mandu-fs-routes/metadata.json +12 -0
- package/src/resources/skills/mandu-fs-routes/rules/_sections.md +36 -0
- package/src/resources/skills/mandu-fs-routes/rules/_template.md +69 -0
- package/src/resources/skills/mandu-fs-routes/rules/routes-api-methods.md +65 -0
- package/src/resources/skills/mandu-fs-routes/rules/routes-dynamic-param.md +93 -0
- package/src/resources/skills/mandu-fs-routes/rules/routes-naming-page.md +55 -0
- package/src/resources/skills/mandu-guard/SKILL.md +129 -0
- package/src/resources/skills/mandu-guard/metadata.json +12 -0
- package/src/resources/skills/mandu-guard/rules/_sections.md +36 -0
- package/src/resources/skills/mandu-guard/rules/_template.md +82 -0
- package/src/resources/skills/mandu-guard/rules/guard-config-rules.md +100 -0
- package/src/resources/skills/mandu-guard/rules/guard-layer-direction.md +76 -0
- package/src/resources/skills/mandu-guard/rules/guard-preset-mandu.md +81 -0
- package/src/resources/skills/mandu-guard/rules/guard-validate-import.md +80 -0
- package/src/resources/skills/mandu-hydration/SKILL.md +91 -0
- package/src/resources/skills/mandu-hydration/metadata.json +12 -0
- package/src/resources/skills/mandu-hydration/rules/_sections.md +31 -0
- package/src/resources/skills/mandu-hydration/rules/_template.md +72 -0
- package/src/resources/skills/mandu-hydration/rules/hydration-data-event.md +109 -0
- package/src/resources/skills/mandu-hydration/rules/hydration-directive-use-client.md +55 -0
- package/src/resources/skills/mandu-hydration/rules/hydration-island-setup.md +113 -0
- package/src/resources/skills/mandu-hydration/rules/hydration-priority-visible.md +68 -0
- package/src/resources/skills/mandu-performance/SKILL.md +85 -0
- package/src/resources/skills/mandu-performance/metadata.json +14 -0
- package/src/resources/skills/mandu-performance/rules/_sections.md +31 -0
- package/src/resources/skills/mandu-performance/rules/_template.md +64 -0
- package/src/resources/skills/mandu-performance/rules/perf-async-defer-await.md +103 -0
- package/src/resources/skills/mandu-performance/rules/perf-async-parallel.md +95 -0
- package/src/resources/skills/mandu-performance/rules/perf-bun-file.md +124 -0
- package/src/resources/skills/mandu-performance/rules/perf-bun-serve.md +125 -0
- package/src/resources/skills/mandu-performance/rules/perf-bundle-imports.md +80 -0
- package/src/resources/skills/mandu-performance/rules/perf-bundle-island-lazy.md +145 -0
- package/src/resources/skills/mandu-performance/rules/perf-cache-react.md +98 -0
- package/src/resources/skills/mandu-performance/rules/perf-render-transitions.md +154 -0
- package/src/resources/skills/mandu-security/SKILL.md +87 -0
- package/src/resources/skills/mandu-security/metadata.json +13 -0
- package/src/resources/skills/mandu-security/rules/_sections.md +31 -0
- package/src/resources/skills/mandu-security/rules/_template.md +74 -0
- package/src/resources/skills/mandu-security/rules/sec-auth-guard.md +127 -0
- package/src/resources/skills/mandu-security/rules/sec-env-management.md +133 -0
- package/src/resources/skills/mandu-security/rules/sec-input-validate.md +148 -0
- package/src/resources/skills/mandu-security/rules/sec-protect-csrf.md +146 -0
- package/src/resources/skills/mandu-security/rules/sec-protect-headers.md +138 -0
- package/src/resources/skills/mandu-slot/SKILL.md +85 -0
- package/src/resources/skills/mandu-slot/metadata.json +12 -0
- package/src/resources/skills/mandu-slot/rules/_sections.md +36 -0
- package/src/resources/skills/mandu-slot/rules/_template.md +63 -0
- package/src/resources/skills/mandu-slot/rules/slot-basic-structure.md +38 -0
- package/src/resources/skills/mandu-slot/rules/slot-ctx-response.md +56 -0
- package/src/resources/skills/mandu-slot/rules/slot-guard-auth.md +59 -0
- package/src/resources/skills/mandu-slot/rules/slot-http-methods.md +64 -0
- package/src/resources/skills/mandu-styling/SKILL.md +118 -0
- package/src/resources/skills/mandu-styling/_sections.md +36 -0
- package/src/resources/skills/mandu-styling/_template.md +32 -0
- package/src/resources/skills/mandu-styling/metadata.json +13 -0
- package/src/resources/skills/mandu-styling/rules/style-component-compound.md +235 -0
- package/src/resources/skills/mandu-styling/rules/style-component-slots.md +255 -0
- package/src/resources/skills/mandu-styling/rules/style-component-tokens.md +205 -0
- package/src/resources/skills/mandu-styling/rules/style-island-animations.md +272 -0
- package/src/resources/skills/mandu-styling/rules/style-island-scoping.md +167 -0
- package/src/resources/skills/mandu-styling/rules/style-island-variants.md +221 -0
- package/src/resources/skills/mandu-styling/rules/style-perf-critical.md +209 -0
- package/src/resources/skills/mandu-styling/rules/style-perf-purge.md +192 -0
- package/src/resources/skills/mandu-styling/rules/style-setup-modules.md +162 -0
- package/src/resources/skills/mandu-styling/rules/style-setup-panda.md +164 -0
- package/src/resources/skills/mandu-styling/rules/style-setup-tailwind.md +161 -0
- package/src/resources/skills/mandu-styling/rules/style-theme-darkmode.md +229 -0
- package/src/resources/skills/mandu-testing/SKILL.md +99 -0
- package/src/resources/skills/mandu-testing/metadata.json +13 -0
- package/src/resources/skills/mandu-testing/rules/_sections.md +26 -0
- package/src/resources/skills/mandu-testing/rules/_template.md +65 -0
- package/src/resources/skills/mandu-testing/rules/test-component-island.md +195 -0
- package/src/resources/skills/mandu-testing/rules/test-e2e-playwright.md +196 -0
- package/src/resources/skills/mandu-testing/rules/test-mock-fetch.md +219 -0
- package/src/resources/skills/mandu-testing/rules/test-slot-unit.md +192 -0
- package/src/resources/skills/mandu-ui/SKILL.md +117 -0
- package/src/resources/skills/mandu-ui/_sections.md +23 -0
- package/src/resources/skills/mandu-ui/_template.md +32 -0
- package/src/resources/skills/mandu-ui/metadata.json +13 -0
- package/src/resources/skills/mandu-ui/rules/ui-accessibility-aria.md +232 -0
- package/src/resources/skills/mandu-ui/rules/ui-accessibility-focus.md +238 -0
- package/src/resources/skills/mandu-ui/rules/ui-composition-patterns.md +259 -0
- package/src/resources/skills/mandu-ui/rules/ui-island-integration.md +258 -0
- package/src/resources/skills/mandu-ui/rules/ui-radix-patterns.md +213 -0
- package/src/resources/skills/mandu-ui/rules/ui-shadcn-setup.md +209 -0
- package/src/resources/skills/recipes.ts +932 -0
- package/src/server.ts +3 -0
- package/src/tools/hydration.ts +8 -8
- package/src/tools/index.ts +1 -0
- package/src/tools/seo.ts +417 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use useIslandEvent for Island Communication
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Enables Island-to-Island data flow
|
|
5
|
+
tags: hydration, event, communication
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use useIslandEvent for Island Communication
|
|
9
|
+
|
|
10
|
+
Islands are isolated by default. Use `useIslandEvent` to communicate between them.
|
|
11
|
+
|
|
12
|
+
**Incorrect (shared global state):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
// ❌ Don't use global variables for Island communication
|
|
16
|
+
let globalCount = 0;
|
|
17
|
+
|
|
18
|
+
// Island A
|
|
19
|
+
export function CounterIsland() {
|
|
20
|
+
const [count, setCount] = useState(globalCount);
|
|
21
|
+
// This won't sync with other Islands
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (useIslandEvent):**
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// Island A: Counter (emits updates)
|
|
29
|
+
"use client";
|
|
30
|
+
|
|
31
|
+
import { useState } from "react";
|
|
32
|
+
import { useIslandEvent } from "@mandujs/core/client";
|
|
33
|
+
|
|
34
|
+
export function CounterIsland() {
|
|
35
|
+
const [count, setCount] = useState(0);
|
|
36
|
+
const { emit } = useIslandEvent<{ count: number }>("counter-update");
|
|
37
|
+
|
|
38
|
+
const increment = () => {
|
|
39
|
+
const newCount = count + 1;
|
|
40
|
+
setCount(newCount);
|
|
41
|
+
emit({ count: newCount }); // Notify other Islands
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return <button onClick={increment}>Count: {count}</button>;
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// Island B: Display (receives updates)
|
|
50
|
+
"use client";
|
|
51
|
+
|
|
52
|
+
import { useState } from "react";
|
|
53
|
+
import { useIslandEvent } from "@mandujs/core/client";
|
|
54
|
+
|
|
55
|
+
export function DisplayIsland() {
|
|
56
|
+
const [lastCount, setLastCount] = useState(0);
|
|
57
|
+
|
|
58
|
+
useIslandEvent<{ count: number }>("counter-update", (data) => {
|
|
59
|
+
setLastCount(data.count); // React to counter updates
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return <p>Last count received: {lastCount}</p>;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// Emit events
|
|
70
|
+
const { emit } = useIslandEvent<T>(eventName);
|
|
71
|
+
emit(data);
|
|
72
|
+
|
|
73
|
+
// Listen to events
|
|
74
|
+
useIslandEvent<T>(eventName, (data) => {
|
|
75
|
+
// Handle received data
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Both emit and listen
|
|
79
|
+
const { emit } = useIslandEvent<T>(eventName, (data) => {
|
|
80
|
+
// Handle received data
|
|
81
|
+
});
|
|
82
|
+
emit(otherData);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Common Patterns
|
|
86
|
+
|
|
87
|
+
### Cart Updates
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
// Product Island
|
|
91
|
+
emit({ action: "add", productId: 123 });
|
|
92
|
+
|
|
93
|
+
// Cart Island
|
|
94
|
+
useIslandEvent("cart-update", ({ action, productId }) => {
|
|
95
|
+
if (action === "add") addToCart(productId);
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Form Validation
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
// Form Field Island
|
|
103
|
+
emit({ field: "email", valid: true, value: "user@example.com" });
|
|
104
|
+
|
|
105
|
+
// Submit Button Island
|
|
106
|
+
useIslandEvent("field-change", ({ field, valid }) => {
|
|
107
|
+
updateFieldStatus(field, valid);
|
|
108
|
+
});
|
|
109
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Add "use client" Directive for Client Components
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: Required for client-side interactivity
|
|
5
|
+
tags: hydration, client, directive
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Add "use client" Directive for Client Components
|
|
9
|
+
|
|
10
|
+
Client components must have `"use client"` directive at the top of the file.
|
|
11
|
+
|
|
12
|
+
**Incorrect (missing directive):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
// app/counter/client.tsx
|
|
16
|
+
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
|
|
19
|
+
export default function Counter() {
|
|
20
|
+
const [count, setCount] = useState(0); // ❌ Will error
|
|
21
|
+
return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (with directive):**
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// app/counter/client.tsx
|
|
29
|
+
|
|
30
|
+
"use client";
|
|
31
|
+
|
|
32
|
+
import { useState } from "react";
|
|
33
|
+
|
|
34
|
+
export default function Counter() {
|
|
35
|
+
const [count, setCount] = useState(0); // ✅ Works
|
|
36
|
+
return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## When to Use "use client"
|
|
41
|
+
|
|
42
|
+
Use the directive when your component:
|
|
43
|
+
- Uses React hooks (useState, useEffect, useRef, etc.)
|
|
44
|
+
- Has event handlers (onClick, onChange, etc.)
|
|
45
|
+
- Uses browser-only APIs (window, document, localStorage)
|
|
46
|
+
- Needs client-side interactivity
|
|
47
|
+
|
|
48
|
+
## File Naming Convention
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
app/
|
|
52
|
+
├── counter/
|
|
53
|
+
│ ├── page.tsx # Server component (no directive needed)
|
|
54
|
+
│ └── client.tsx # Client component ("use client" required)
|
|
55
|
+
```
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Mandu.island() with Setup Function
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: Proper Island structure
|
|
5
|
+
tags: hydration, island, setup
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Mandu.island() with Setup Function
|
|
9
|
+
|
|
10
|
+
For complex Islands, use `Mandu.island()` API to separate state logic from rendering.
|
|
11
|
+
|
|
12
|
+
**Incorrect (mixed concerns):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
"use client";
|
|
16
|
+
|
|
17
|
+
export default function TodoList({ initialTodos }) {
|
|
18
|
+
// State, handlers, and JSX all mixed together
|
|
19
|
+
const [todos, setTodos] = useState(initialTodos);
|
|
20
|
+
const [input, setInput] = useState("");
|
|
21
|
+
|
|
22
|
+
const add = () => {
|
|
23
|
+
setTodos([...todos, { id: Date.now(), text: input }]);
|
|
24
|
+
setInput("");
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div>
|
|
29
|
+
<input value={input} onChange={e => setInput(e.target.value)} />
|
|
30
|
+
<button onClick={add}>Add</button>
|
|
31
|
+
{todos.map(t => <li key={t.id}>{t.text}</li>)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Correct (Mandu.island pattern):**
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
// spec/slots/todos.client.ts
|
|
41
|
+
|
|
42
|
+
import { Mandu } from "@mandujs/core/client";
|
|
43
|
+
import { useState, useCallback } from "react";
|
|
44
|
+
|
|
45
|
+
interface TodosData {
|
|
46
|
+
todos: { id: number; text: string; done: boolean }[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default Mandu.island<TodosData>({
|
|
50
|
+
// Setup: Initialize client state from server data
|
|
51
|
+
setup: (serverData) => {
|
|
52
|
+
const [todos, setTodos] = useState(serverData.todos);
|
|
53
|
+
const [input, setInput] = useState("");
|
|
54
|
+
|
|
55
|
+
const addTodo = useCallback(() => {
|
|
56
|
+
if (!input.trim()) return;
|
|
57
|
+
setTodos(prev => [...prev, { id: Date.now(), text: input, done: false }]);
|
|
58
|
+
setInput("");
|
|
59
|
+
}, [input]);
|
|
60
|
+
|
|
61
|
+
const toggleTodo = useCallback((id: number) => {
|
|
62
|
+
setTodos(prev => prev.map(t =>
|
|
63
|
+
t.id === id ? { ...t, done: !t.done } : t
|
|
64
|
+
));
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return { todos, input, setInput, addTodo, toggleTodo };
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// Render: Pure rendering logic
|
|
71
|
+
render: ({ todos, input, setInput, addTodo, toggleTodo }) => (
|
|
72
|
+
<div>
|
|
73
|
+
<input
|
|
74
|
+
value={input}
|
|
75
|
+
onChange={e => setInput(e.target.value)}
|
|
76
|
+
placeholder="New todo..."
|
|
77
|
+
/>
|
|
78
|
+
<button onClick={addTodo}>Add</button>
|
|
79
|
+
<ul>
|
|
80
|
+
{todos.map(todo => (
|
|
81
|
+
<li
|
|
82
|
+
key={todo.id}
|
|
83
|
+
onClick={() => toggleTodo(todo.id)}
|
|
84
|
+
style={{ textDecoration: todo.done ? "line-through" : "none" }}
|
|
85
|
+
>
|
|
86
|
+
{todo.done ? "✅" : "⬜"} {todo.text}
|
|
87
|
+
</li>
|
|
88
|
+
))}
|
|
89
|
+
</ul>
|
|
90
|
+
</div>
|
|
91
|
+
),
|
|
92
|
+
|
|
93
|
+
// Optional: Error boundary
|
|
94
|
+
errorBoundary: (error, reset) => (
|
|
95
|
+
<div>
|
|
96
|
+
<p>Error: {error.message}</p>
|
|
97
|
+
<button onClick={reset}>Retry</button>
|
|
98
|
+
</div>
|
|
99
|
+
),
|
|
100
|
+
|
|
101
|
+
// Optional: Loading state
|
|
102
|
+
loading: () => <p>Loading todos...</p>,
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Mandu.island() Options
|
|
107
|
+
|
|
108
|
+
| Option | Required | Description |
|
|
109
|
+
|--------|----------|-------------|
|
|
110
|
+
| `setup` | Yes | Initialize state from server data |
|
|
111
|
+
| `render` | Yes | Pure render function |
|
|
112
|
+
| `errorBoundary` | No | Error UI component |
|
|
113
|
+
| `loading` | No | Loading UI component |
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Visible Priority for Below-Fold Content
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: Optimizes initial page load
|
|
5
|
+
tags: hydration, priority, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Visible Priority for Below-Fold Content
|
|
9
|
+
|
|
10
|
+
Set hydration priority based on when the component needs to be interactive.
|
|
11
|
+
|
|
12
|
+
## Hydration Priorities
|
|
13
|
+
|
|
14
|
+
| Priority | Load Time | Use Case |
|
|
15
|
+
|----------|-----------|----------|
|
|
16
|
+
| `immediate` | Page load | Critical interactions (header nav, auth forms) |
|
|
17
|
+
| `visible` | Viewport entry (default) | Below-fold content |
|
|
18
|
+
| `idle` | Browser idle | Non-critical features (analytics widgets) |
|
|
19
|
+
| `interaction` | User action | Click-to-activate components |
|
|
20
|
+
|
|
21
|
+
## Examples
|
|
22
|
+
|
|
23
|
+
### Immediate: Always-visible interactions
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
// Header with navigation - needs to work immediately
|
|
27
|
+
<Island priority="immediate">
|
|
28
|
+
<HeaderNav />
|
|
29
|
+
</Island>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Visible: Below-fold content (default)
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
// Comments section - load when scrolled into view
|
|
36
|
+
<Island priority="visible">
|
|
37
|
+
<CommentsSection postId={postId} />
|
|
38
|
+
</Island>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Idle: Background features
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// Chat widget - can wait until browser is idle
|
|
45
|
+
<Island priority="idle">
|
|
46
|
+
<ChatWidget />
|
|
47
|
+
</Island>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Interaction: On-demand activation
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
// Video player - only hydrate when user clicks play
|
|
54
|
+
<Island priority="interaction">
|
|
55
|
+
<VideoPlayer videoId={videoId} />
|
|
56
|
+
</Island>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Performance Impact
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
immediate: +JavaScript bundle at page load
|
|
63
|
+
visible: +JavaScript when component enters viewport
|
|
64
|
+
idle: +JavaScript during browser idle time
|
|
65
|
+
interaction: +JavaScript on first user interaction
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Rule of thumb**: Use `visible` (default) unless you have a specific reason to choose another priority.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mandu-performance
|
|
3
|
+
description: |
|
|
4
|
+
Performance optimization patterns for Mandu applications. Use when optimizing
|
|
5
|
+
slot handlers, Island components, bundle size, or Bun runtime. Triggers on
|
|
6
|
+
tasks involving async/await, Promise.all, lazy loading, caching, or performance.
|
|
7
|
+
license: MIT
|
|
8
|
+
metadata:
|
|
9
|
+
author: mandu
|
|
10
|
+
version: "1.0.0"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Mandu Performance
|
|
14
|
+
|
|
15
|
+
Mandu 애플리케이션의 성능 최적화 가이드. 워터폴 제거, 번들 최적화, 캐싱 패턴, Bun 런타임 활용법을 다룹니다. Vercel의 React Best Practices를 Mandu 컨텍스트로 변환하여 적용합니다.
|
|
16
|
+
|
|
17
|
+
## When to Apply
|
|
18
|
+
|
|
19
|
+
Reference these guidelines when:
|
|
20
|
+
- Optimizing slot handler response times
|
|
21
|
+
- Reducing Island component bundle size
|
|
22
|
+
- Implementing caching strategies
|
|
23
|
+
- Working with async/await patterns
|
|
24
|
+
- Leveraging Bun runtime features
|
|
25
|
+
|
|
26
|
+
## Rule Categories by Priority
|
|
27
|
+
|
|
28
|
+
| Priority | Category | Impact | Prefix |
|
|
29
|
+
|----------|----------|--------|--------|
|
|
30
|
+
| 1 | Async Optimization | CRITICAL | `perf-async-` |
|
|
31
|
+
| 2 | Bundle Optimization | CRITICAL | `perf-bundle-` |
|
|
32
|
+
| 3 | Caching Strategies | HIGH | `perf-cache-` |
|
|
33
|
+
| 4 | Bun Runtime | HIGH | `perf-bun-` |
|
|
34
|
+
| 5 | Rendering | MEDIUM | `perf-render-` |
|
|
35
|
+
|
|
36
|
+
## Quick Reference
|
|
37
|
+
|
|
38
|
+
### 1. Async Optimization (CRITICAL)
|
|
39
|
+
|
|
40
|
+
- `perf-async-parallel` - Use Promise.all() for independent operations
|
|
41
|
+
- `perf-async-defer-await` - Move await into branches where actually used
|
|
42
|
+
- `perf-async-early-start` - Start promises early, await late
|
|
43
|
+
|
|
44
|
+
### 2. Bundle Optimization (CRITICAL)
|
|
45
|
+
|
|
46
|
+
- `perf-bundle-imports` - Import directly, avoid barrel files
|
|
47
|
+
- `perf-bundle-island-lazy` - Lazy load Islands with dynamic import
|
|
48
|
+
- `perf-bundle-preload` - Preload on hover/focus for perceived speed
|
|
49
|
+
|
|
50
|
+
### 3. Caching Strategies (HIGH)
|
|
51
|
+
|
|
52
|
+
- `perf-cache-slot` - Cache slot responses with appropriate TTL
|
|
53
|
+
- `perf-cache-react` - Use React.cache() for request deduplication
|
|
54
|
+
- `perf-cache-lru` - Use LRU cache for cross-request caching
|
|
55
|
+
|
|
56
|
+
### 4. Bun Runtime (HIGH)
|
|
57
|
+
|
|
58
|
+
- `perf-bun-serve` - Optimize Bun.serve() configuration
|
|
59
|
+
- `perf-bun-file` - Use Bun.file() for efficient file operations
|
|
60
|
+
- `perf-bun-sqlite` - Leverage bun:sqlite for fast database access
|
|
61
|
+
|
|
62
|
+
### 5. Rendering (MEDIUM)
|
|
63
|
+
|
|
64
|
+
- `perf-render-island-priority` - Set appropriate hydration priority
|
|
65
|
+
- `perf-render-transitions` - Use startTransition for non-urgent updates
|
|
66
|
+
|
|
67
|
+
## Performance Impact Summary
|
|
68
|
+
|
|
69
|
+
| Optimization | Typical Improvement |
|
|
70
|
+
|--------------|---------------------|
|
|
71
|
+
| Promise.all() | 2-10× faster |
|
|
72
|
+
| Direct imports | 15-70% faster dev boot |
|
|
73
|
+
| Island lazy loading | 40-60% smaller initial bundle |
|
|
74
|
+
| React.cache() | Eliminates duplicate queries |
|
|
75
|
+
| Bun.file() | 10× faster than Node fs |
|
|
76
|
+
|
|
77
|
+
## How to Use
|
|
78
|
+
|
|
79
|
+
Read individual rule files for detailed explanations:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
rules/perf-async-parallel.md
|
|
83
|
+
rules/perf-bundle-imports.md
|
|
84
|
+
rules/perf-bun-serve.md
|
|
85
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"organization": "Mandu Framework",
|
|
4
|
+
"date": "February 2026",
|
|
5
|
+
"abstract": "Mandu 애플리케이션 성능 최적화 가이드. 워터폴 제거 (Promise.all), 번들 최적화 (직접 import, lazy loading), 캐싱 전략 (React.cache, LRU), Bun 런타임 활용 (Bun.serve, Bun.file)을 다룹니다. Vercel React Best Practices 기반으로 Mandu 컨텍스트에 맞게 변환되었습니다.",
|
|
6
|
+
"references": [
|
|
7
|
+
"https://vercel.com/blog/how-we-optimized-package-imports-in-next-js",
|
|
8
|
+
"https://vercel.com/blog/how-we-made-the-vercel-dashboard-twice-as-fast",
|
|
9
|
+
"https://bun.sh/docs/api/http",
|
|
10
|
+
"https://bun.sh/docs/api/file-io",
|
|
11
|
+
"https://react.dev/reference/react/cache"
|
|
12
|
+
],
|
|
13
|
+
"tags": ["performance", "async", "bundle", "cache", "bun", "mandu"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Sections
|
|
2
|
+
|
|
3
|
+
This file defines all sections, their ordering, impact levels, and descriptions.
|
|
4
|
+
The section ID (in parentheses) is the filename prefix used to group rules.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Async Optimization (perf-async)
|
|
9
|
+
|
|
10
|
+
**Impact:** CRITICAL
|
|
11
|
+
**Description:** 워터폴은 성능의 #1 킬러입니다. 순차적 await는 매번 전체 네트워크 지연을 추가합니다. 워터폴 제거가 가장 큰 성능 향상을 가져옵니다.
|
|
12
|
+
|
|
13
|
+
## 2. Bundle Optimization (perf-bundle)
|
|
14
|
+
|
|
15
|
+
**Impact:** CRITICAL
|
|
16
|
+
**Description:** 초기 번들 크기 감소는 Time to Interactive와 Largest Contentful Paint를 개선합니다. Island lazy loading과 직접 import가 핵심입니다.
|
|
17
|
+
|
|
18
|
+
## 3. Caching Strategies (perf-cache)
|
|
19
|
+
|
|
20
|
+
**Impact:** HIGH
|
|
21
|
+
**Description:** 적절한 캐싱은 불필요한 연산과 네트워크 요청을 제거합니다. React.cache()는 요청 내 중복 제거, LRU는 요청 간 캐싱에 사용합니다.
|
|
22
|
+
|
|
23
|
+
## 4. Bun Runtime (perf-bun)
|
|
24
|
+
|
|
25
|
+
**Impact:** HIGH
|
|
26
|
+
**Description:** Bun의 네이티브 API (Bun.serve, Bun.file, bun:sqlite)는 Node.js 대비 현저히 빠릅니다. Mandu는 Bun 기반이므로 이를 최대한 활용해야 합니다.
|
|
27
|
+
|
|
28
|
+
## 5. Rendering Performance (perf-render)
|
|
29
|
+
|
|
30
|
+
**Impact:** MEDIUM
|
|
31
|
+
**Description:** Island hydration 우선순위 설정과 startTransition 활용으로 사용자 체감 성능을 개선합니다.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Rule Template
|
|
2
|
+
|
|
3
|
+
Use this template when creating new rules for mandu-performance.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
```markdown
|
|
8
|
+
---
|
|
9
|
+
title: Rule Title Here
|
|
10
|
+
impact: CRITICAL | HIGH | MEDIUM | LOW
|
|
11
|
+
impactDescription: 개선 수치 (예: "2-10× improvement", "40% faster")
|
|
12
|
+
tags: performance, tag1, tag2
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Rule Title Here
|
|
16
|
+
|
|
17
|
+
**Impact: {LEVEL} ({impactDescription})**
|
|
18
|
+
|
|
19
|
+
규칙의 목적과 성능 영향을 설명합니다.
|
|
20
|
+
|
|
21
|
+
**Incorrect (문제점 - 성능 영향 명시):**
|
|
22
|
+
|
|
23
|
+
\`\`\`typescript
|
|
24
|
+
// ❌ 순차 실행: 3번의 네트워크 왕복
|
|
25
|
+
const user = await fetchUser();
|
|
26
|
+
const posts = await fetchPosts();
|
|
27
|
+
const comments = await fetchComments();
|
|
28
|
+
// 총 시간: 100ms + 100ms + 100ms = 300ms
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
**Correct (해결책 - 성능 개선 명시):**
|
|
32
|
+
|
|
33
|
+
\`\`\`typescript
|
|
34
|
+
// ✅ 병렬 실행: 1번의 네트워크 왕복
|
|
35
|
+
const [user, posts, comments] = await Promise.all([
|
|
36
|
+
fetchUser(),
|
|
37
|
+
fetchPosts(),
|
|
38
|
+
fetchComments(),
|
|
39
|
+
]);
|
|
40
|
+
// 총 시간: max(100ms, 100ms, 100ms) = 100ms
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Mandu Context
|
|
44
|
+
|
|
45
|
+
Mandu에서 이 규칙을 적용하는 구체적인 방법을 설명합니다.
|
|
46
|
+
|
|
47
|
+
Reference: [관련 문서 링크](https://example.com)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Naming Convention
|
|
53
|
+
|
|
54
|
+
- 파일명: `perf-{category}-{rule-name}.md`
|
|
55
|
+
- 예시: `perf-async-parallel.md`, `perf-bundle-imports.md`
|
|
56
|
+
|
|
57
|
+
## Impact Measurement
|
|
58
|
+
|
|
59
|
+
| Level | Typical Improvement |
|
|
60
|
+
|-------|---------------------|
|
|
61
|
+
| CRITICAL | 2-10× or 50%+ |
|
|
62
|
+
| HIGH | 20-50% |
|
|
63
|
+
| MEDIUM | 10-20% |
|
|
64
|
+
| LOW | < 10% |
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Defer await to Where Actually Used
|
|
3
|
+
impact: CRITICAL
|
|
4
|
+
impactDescription: Eliminates unnecessary blocking
|
|
5
|
+
tags: performance, async, await, slot
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Defer await to Where Actually Used
|
|
9
|
+
|
|
10
|
+
**Impact: CRITICAL (Eliminates unnecessary blocking)**
|
|
11
|
+
|
|
12
|
+
await는 실제로 값이 필요한 시점까지 지연하세요. 함수 시작에서 모든 것을 await하면 불필요한 블로킹이 발생합니다.
|
|
13
|
+
|
|
14
|
+
**Incorrect (너무 일찍 await):**
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// spec/slots/user.slot.ts
|
|
18
|
+
import { Mandu } from "@mandujs/core";
|
|
19
|
+
|
|
20
|
+
export default Mandu.filling()
|
|
21
|
+
.get(async (ctx) => {
|
|
22
|
+
const userId = ctx.params.id;
|
|
23
|
+
|
|
24
|
+
// ❌ 캐시 확인 전에 DB 쿼리 시작하고 대기
|
|
25
|
+
const user = await fetchUserFromDB(userId);
|
|
26
|
+
|
|
27
|
+
// 캐시에 있으면 DB 쿼리는 불필요했음
|
|
28
|
+
const cached = cache.get(`user:${userId}`);
|
|
29
|
+
if (cached) {
|
|
30
|
+
return ctx.ok(cached);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return ctx.ok(user);
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Correct (필요한 시점에 await):**
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// spec/slots/user.slot.ts
|
|
41
|
+
import { Mandu } from "@mandujs/core";
|
|
42
|
+
|
|
43
|
+
export default Mandu.filling()
|
|
44
|
+
.get(async (ctx) => {
|
|
45
|
+
const userId = ctx.params.id;
|
|
46
|
+
|
|
47
|
+
// 캐시 먼저 확인
|
|
48
|
+
const cached = cache.get(`user:${userId}`);
|
|
49
|
+
if (cached) {
|
|
50
|
+
return ctx.ok(cached); // DB 쿼리 안 함
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ✅ 캐시 미스일 때만 DB 쿼리
|
|
54
|
+
const user = await fetchUserFromDB(userId);
|
|
55
|
+
cache.set(`user:${userId}`, user);
|
|
56
|
+
|
|
57
|
+
return ctx.ok(user);
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Promise 시작은 일찍, await는 늦게
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export default Mandu.filling()
|
|
65
|
+
.get(async (ctx) => {
|
|
66
|
+
// ✅ Promise 시작 (블로킹 없음)
|
|
67
|
+
const userPromise = fetchUser(ctx.params.id);
|
|
68
|
+
const configPromise = fetchConfig();
|
|
69
|
+
|
|
70
|
+
// 동기 작업 수행
|
|
71
|
+
const requestId = generateRequestId();
|
|
72
|
+
const timestamp = Date.now();
|
|
73
|
+
logRequest(requestId, timestamp);
|
|
74
|
+
|
|
75
|
+
// ✅ 필요한 시점에 await
|
|
76
|
+
const [user, config] = await Promise.all([userPromise, configPromise]);
|
|
77
|
+
|
|
78
|
+
return ctx.ok({ user, config, requestId });
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 조건부 분기에서의 활용
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
export default Mandu.filling()
|
|
86
|
+
.get(async (ctx) => {
|
|
87
|
+
const { type } = ctx.query;
|
|
88
|
+
|
|
89
|
+
if (type === "summary") {
|
|
90
|
+
// 요약만 필요하면 상세 데이터 불필요
|
|
91
|
+
const summary = await fetchSummary(ctx.params.id);
|
|
92
|
+
return ctx.ok({ summary });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 상세 데이터가 필요한 경우에만 fetch
|
|
96
|
+
const [summary, details] = await Promise.all([
|
|
97
|
+
fetchSummary(ctx.params.id),
|
|
98
|
+
fetchDetails(ctx.params.id),
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
return ctx.ok({ summary, details });
|
|
102
|
+
});
|
|
103
|
+
```
|