@kood/claude-code 0.3.11 → 0.3.14
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/dist/index.js +30 -8
- package/package.json +4 -4
- package/templates/.claude/skills/nextjs-react-best-practices/AGENTS.md +663 -0
- package/templates/.claude/skills/nextjs-react-best-practices/SKILL.md +269 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/advanced-use-latest.md +49 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/async-api-routes.md +38 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/async-defer-await.md +80 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/async-dependencies.md +36 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/async-parallel.md +28 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-conditional.md +31 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/bundle-preload.md +50 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/client-event-listeners.md +74 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-batch-dom-css.md +82 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-cache-storage.md +70 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-early-exit.md +50 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-index-maps.md +37 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-length-check-first.md +49 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-activity.md +26 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-memo.md +44 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/rerender-transitions.md +40 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/server-cache-lru.md +41 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/server-cache-react.md +26 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/server-parallel-fetching.md +79 -0
- package/templates/.claude/skills/nextjs-react-best-practices/rules/server-serialization.md +38 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/AGENTS.md +751 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/SKILL.md +431 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-defer-await.md +80 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-dependencies.md +36 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-loader.md +44 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/async-parallel.md +28 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-conditional.md +31 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-lazy-routes.md +67 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/bundle-preload.md +50 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-event-listeners.md +74 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/client-tanstack-query.md +77 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-batch-dom-css.md +82 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-cache-storage.md +70 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-early-exit.md +50 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-index-maps.md +37 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-length-check-first.md +49 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-memo.md +44 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-transitions.md +40 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-cache-lru.md +41 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-deferred-data.md +67 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-parallel-fetching.md +60 -0
- package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-serialization.md +38 -0
- package/templates/.claude/skills/vs-design-diverge/SKILL.md +307 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Lazy State Initialization
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: wasted computation on every render
|
|
5
|
+
tags: react, hooks, useState, performance, initialization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Lazy State Initialization
|
|
9
|
+
|
|
10
|
+
Pass a function to `useState` for expensive initial values. Without the function form, the initializer runs on every render even though the value is only used once.
|
|
11
|
+
|
|
12
|
+
**Incorrect (runs on every render):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function FilteredList({ items }: { items: Item[] }) {
|
|
16
|
+
// buildSearchIndex() runs on EVERY render, even after initialization
|
|
17
|
+
const [searchIndex, setSearchIndex] = useState(buildSearchIndex(items))
|
|
18
|
+
const [query, setQuery] = useState('')
|
|
19
|
+
|
|
20
|
+
// When query changes, buildSearchIndex runs again unnecessarily
|
|
21
|
+
return <SearchResults index={searchIndex} query={query} />
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function UserProfile() {
|
|
25
|
+
// JSON.parse runs on every render
|
|
26
|
+
const [settings, setSettings] = useState(
|
|
27
|
+
JSON.parse(localStorage.getItem('settings') || '{}')
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return <SettingsForm settings={settings} onChange={setSettings} />
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Correct (runs only once):**
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
function FilteredList({ items }: { items: Item[] }) {
|
|
38
|
+
// buildSearchIndex() runs ONLY on initial render
|
|
39
|
+
const [searchIndex, setSearchIndex] = useState(() => buildSearchIndex(items))
|
|
40
|
+
const [query, setQuery] = useState('')
|
|
41
|
+
|
|
42
|
+
return <SearchResults index={searchIndex} query={query} />
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function UserProfile() {
|
|
46
|
+
// JSON.parse runs only on initial render
|
|
47
|
+
const [settings, setSettings] = useState(() => {
|
|
48
|
+
const stored = localStorage.getItem('settings')
|
|
49
|
+
return stored ? JSON.parse(stored) : {}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return <SettingsForm settings={settings} onChange={setSettings} />
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Use lazy initialization when computing initial values from localStorage/sessionStorage, building data structures (indexes, maps), reading from the DOM, or performing heavy transformations.
|
|
57
|
+
|
|
58
|
+
For simple primitives (`useState(0)`), direct references (`useState(props.value)`), or cheap literals (`useState({})`), the function form is unnecessary.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Extract to Memoized Components
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: enables early returns
|
|
5
|
+
tags: rerender, memo, useMemo, optimization
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Extract to Memoized Components
|
|
9
|
+
|
|
10
|
+
Extract expensive work into memoized components to enable early returns before computation.
|
|
11
|
+
|
|
12
|
+
**Incorrect (computes avatar even when loading):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function Profile({ user, loading }: Props) {
|
|
16
|
+
const avatar = useMemo(() => {
|
|
17
|
+
const id = computeAvatarId(user)
|
|
18
|
+
return <Avatar id={id} />
|
|
19
|
+
}, [user])
|
|
20
|
+
|
|
21
|
+
if (loading) return <Skeleton />
|
|
22
|
+
return <div>{avatar}</div>
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Correct (skips computation when loading):**
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
const UserAvatar = memo(function UserAvatar({ user }: { user: User }) {
|
|
30
|
+
const id = useMemo(() => computeAvatarId(user), [user])
|
|
31
|
+
return <Avatar id={id} />
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
function Profile({ user, loading }: Props) {
|
|
35
|
+
if (loading) return <Skeleton />
|
|
36
|
+
return (
|
|
37
|
+
<div>
|
|
38
|
+
<UserAvatar user={user} />
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Note:** If your project has [React Compiler](https://react.dev/learn/react-compiler) enabled, manual memoization with `memo()` and `useMemo()` is not necessary. The compiler automatically optimizes re-renders.
|
package/templates/.claude/skills/tanstack-start-react-best-practices/rules/rerender-transitions.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Transitions for Non-Urgent Updates
|
|
3
|
+
impact: MEDIUM
|
|
4
|
+
impactDescription: maintains UI responsiveness
|
|
5
|
+
tags: rerender, transitions, startTransition, performance
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Transitions for Non-Urgent Updates
|
|
9
|
+
|
|
10
|
+
Mark frequent, non-urgent state updates as transitions to maintain UI responsiveness.
|
|
11
|
+
|
|
12
|
+
**Incorrect (blocks UI on every scroll):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
function ScrollTracker() {
|
|
16
|
+
const [scrollY, setScrollY] = useState(0)
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const handler = () => setScrollY(window.scrollY)
|
|
19
|
+
window.addEventListener('scroll', handler, { passive: true })
|
|
20
|
+
return () => window.removeEventListener('scroll', handler)
|
|
21
|
+
}, [])
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct (non-blocking updates):**
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { startTransition } from 'react'
|
|
29
|
+
|
|
30
|
+
function ScrollTracker() {
|
|
31
|
+
const [scrollY, setScrollY] = useState(0)
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const handler = () => {
|
|
34
|
+
startTransition(() => setScrollY(window.scrollY))
|
|
35
|
+
}
|
|
36
|
+
window.addEventListener('scroll', handler, { passive: true })
|
|
37
|
+
return () => window.removeEventListener('scroll', handler)
|
|
38
|
+
}, [])
|
|
39
|
+
}
|
|
40
|
+
```
|
package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-cache-lru.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Cross-Request LRU Caching
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: caches across requests
|
|
5
|
+
tags: server, cache, lru, cross-request
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Cross-Request LRU Caching
|
|
9
|
+
|
|
10
|
+
`React.cache()` only works within one request. For data shared across sequential requests (user clicks button A then button B), use an LRU cache.
|
|
11
|
+
|
|
12
|
+
**Implementation:**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { LRUCache } from 'lru-cache'
|
|
16
|
+
|
|
17
|
+
const cache = new LRUCache<string, any>({
|
|
18
|
+
max: 1000,
|
|
19
|
+
ttl: 5 * 60 * 1000 // 5 minutes
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
export async function getUser(id: string) {
|
|
23
|
+
const cached = cache.get(id)
|
|
24
|
+
if (cached) return cached
|
|
25
|
+
|
|
26
|
+
const user = await db.user.findUnique({ where: { id } })
|
|
27
|
+
cache.set(id, user)
|
|
28
|
+
return user
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Request 1: DB query, result cached
|
|
32
|
+
// Request 2: cache hit, no DB query
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use when sequential user actions hit multiple endpoints needing the same data within seconds.
|
|
36
|
+
|
|
37
|
+
**With Vercel's [Fluid Compute](https://vercel.com/docs/fluid-compute):** LRU caching is especially effective because multiple concurrent requests can share the same function instance and cache. This means the cache persists across requests without needing external storage like Redis.
|
|
38
|
+
|
|
39
|
+
**In traditional serverless:** Each invocation runs in isolation, so consider Redis for cross-process caching.
|
|
40
|
+
|
|
41
|
+
Reference: [https://github.com/isaacs/node-lru-cache](https://github.com/isaacs/node-lru-cache)
|
package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-deferred-data.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Use Deferred Data for Non-Critical Content
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: faster initial page render
|
|
5
|
+
tags: server, streaming, suspense, deferred-data, ux
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Use Deferred Data for Non-Critical Content
|
|
9
|
+
|
|
10
|
+
Load critical data with `await`, but return non-critical data as Promises for streaming. This allows the page to render immediately while slow queries complete in the background.
|
|
11
|
+
|
|
12
|
+
**Incorrect (blocks on slow query):**
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { createFileRoute } from '@tanstack/react-router'
|
|
16
|
+
import { getPost, getComments } from '@/functions/data'
|
|
17
|
+
|
|
18
|
+
export const Route = createFileRoute('/posts/$postId')({
|
|
19
|
+
loader: async ({ params }) => {
|
|
20
|
+
const post = await getPost(params.postId) // Fast: 50ms
|
|
21
|
+
const comments = await getComments(params.postId) // Slow: 3s
|
|
22
|
+
return { post, comments }
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
// Total wait: 3.05s before page renders
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Correct (stream slow data):**
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { createFileRoute, Await } from '@tanstack/react-router'
|
|
32
|
+
import { getPost, getComments } from '@/functions/data'
|
|
33
|
+
import { Suspense } from 'react'
|
|
34
|
+
|
|
35
|
+
export const Route = createFileRoute('/posts/$postId')({
|
|
36
|
+
loader: async ({ params }) => {
|
|
37
|
+
// Critical: await immediately
|
|
38
|
+
const post = await getPost(params.postId)
|
|
39
|
+
|
|
40
|
+
// Non-critical: return Promise (don't await)
|
|
41
|
+
const deferredComments = getComments(params.postId)
|
|
42
|
+
|
|
43
|
+
return { post, deferredComments }
|
|
44
|
+
},
|
|
45
|
+
component: PostPage
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
function PostPage() {
|
|
49
|
+
const { post, deferredComments } = Route.useLoaderData()
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div>
|
|
53
|
+
<PostContent post={post} /> {/* Renders immediately */}
|
|
54
|
+
|
|
55
|
+
<Suspense fallback={<CommentsSkeleton />}>
|
|
56
|
+
<Await promise={deferredComments}>
|
|
57
|
+
{(comments) => <Comments comments={comments} />}
|
|
58
|
+
</Await>
|
|
59
|
+
</Suspense>
|
|
60
|
+
</div>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Page renders in 50ms instead of 3s. Comments stream in when ready. Use for: analytics, recommendations, user activity, social features.
|
|
66
|
+
|
|
67
|
+
Reference: [TanStack Router Deferred Data Loading](https://tanstack.com/router/v1/docs/framework/react/guide/deferred-data-loading)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Restructure Components for Parallel Server Function Calls
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: eliminates component-level waterfalls
|
|
5
|
+
tags: server, parallelization, architecture, server-functions
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Restructure Components for Parallel Server Function Calls
|
|
9
|
+
|
|
10
|
+
Avoid nested component structures that force sequential server function calls. Move data fetching to parent loader when possible.
|
|
11
|
+
|
|
12
|
+
**Incorrect (sequential: User → Posts → Comments):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
// routes/dashboard.tsx
|
|
16
|
+
export const Route = createFileRoute('/dashboard')({
|
|
17
|
+
loader: async () => ({ user: await getUser() }),
|
|
18
|
+
component: Dashboard
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
function Dashboard() {
|
|
22
|
+
const { user } = Route.useLoaderData()
|
|
23
|
+
return <UserPosts userId={user.id} />
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// components/UserPosts.tsx
|
|
27
|
+
function UserPosts({ userId }) {
|
|
28
|
+
const posts = await getPosts(userId) // Blocks until loaded
|
|
29
|
+
return posts.map(p => <PostComments postId={p.id} />)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function PostComments({ postId }) {
|
|
33
|
+
const comments = await getComments(postId) // Sequential waterfall
|
|
34
|
+
return <CommentList comments={comments} />
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Correct (parallel fetching in loader):**
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
// routes/dashboard.tsx
|
|
42
|
+
export const Route = createFileRoute('/dashboard')({
|
|
43
|
+
loader: async () => {
|
|
44
|
+
const user = await getUser()
|
|
45
|
+
const [posts, comments] = await Promise.all([
|
|
46
|
+
getPosts(user.id),
|
|
47
|
+
getComments(user.id)
|
|
48
|
+
])
|
|
49
|
+
return { user, posts, comments }
|
|
50
|
+
},
|
|
51
|
+
component: Dashboard
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
function Dashboard() {
|
|
55
|
+
const { user, posts, comments } = Route.useLoaderData()
|
|
56
|
+
return <PostList posts={posts} comments={comments} />
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Centralizing data fetching in the loader reduces waterfalls and enables parallel execution.
|
package/templates/.claude/skills/tanstack-start-react-best-practices/rules/server-serialization.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Minimize Serialization at RSC Boundaries
|
|
3
|
+
impact: HIGH
|
|
4
|
+
impactDescription: reduces data transfer size
|
|
5
|
+
tags: server, rsc, serialization, props
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Minimize Serialization at RSC Boundaries
|
|
9
|
+
|
|
10
|
+
The React Server/Client boundary serializes all object properties into strings and embeds them in the HTML response and subsequent RSC requests. This serialized data directly impacts page weight and load time, so **size matters a lot**. Only pass fields that the client actually uses.
|
|
11
|
+
|
|
12
|
+
**Incorrect (serializes all 50 fields):**
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
async function Page() {
|
|
16
|
+
const user = await fetchUser() // 50 fields
|
|
17
|
+
return <Profile user={user} />
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
'use client'
|
|
21
|
+
function Profile({ user }: { user: User }) {
|
|
22
|
+
return <div>{user.name}</div> // uses 1 field
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Correct (serializes only 1 field):**
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
async function Page() {
|
|
30
|
+
const user = await fetchUser()
|
|
31
|
+
return <Profile name={user.name} />
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
'use client'
|
|
35
|
+
function Profile({ name }: { name: string }) {
|
|
36
|
+
return <div>{name}</div>
|
|
37
|
+
}
|
|
38
|
+
```
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vs-design-diverge
|
|
3
|
+
description: Create high-entropy frontend interfaces using Verbalized Sampling (VS). Break mode collapse, avoid AI-slop aesthetics. Use for distinctive design work.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<context>
|
|
7
|
+
|
|
8
|
+
**Purpose:** Mitigate Mode Collapse (tendency to produce generic AI output) and create production-grade frontend interfaces
|
|
9
|
+
|
|
10
|
+
**Principle:** Verbalized Sampling (VS) - Verbalize typical design (P ≈ 0.95), then deliberately select Low-T (low typicality) alternatives
|
|
11
|
+
|
|
12
|
+
</context>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<workflow>
|
|
17
|
+
|
|
18
|
+
## Execution Flow
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
Phase 0: Context Discovery
|
|
22
|
+
↓ (AskUserQuestion - probe 4 dimensions)
|
|
23
|
+
Phase 1: Identify the Mode
|
|
24
|
+
↓ (verbalize P ≈ 0.95 baseline, avoid it)
|
|
25
|
+
Phase 2: Sample the Long-Tail
|
|
26
|
+
↓ (3 directions + T-Score justification)
|
|
27
|
+
Phase 3: Commit to Low-Typicality
|
|
28
|
+
↓ (lowest T-Score + pass Guardrails)
|
|
29
|
+
Phase 4: Implementation
|
|
30
|
+
↓ (production-grade code)
|
|
31
|
+
Phase 5: Surprise Validation
|
|
32
|
+
↓ (AI-typical? → refactor)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Phase 0: Context Discovery
|
|
36
|
+
|
|
37
|
+
**Probe these dimensions using AskUserQuestion tool:**
|
|
38
|
+
|
|
39
|
+
| Dimension | Question Examples |
|
|
40
|
+
|-----------|-------------------|
|
|
41
|
+
| **Emotional Tone** | "Trustworthy", "edgy", "playful", "luxurious" - which atmosphere? |
|
|
42
|
+
| **Target Audience** | Who will see this? Technical sophistication? Expectations? |
|
|
43
|
+
| **Reference Points / Anti-References** | Benchmark examples? Styles to explicitly avoid? |
|
|
44
|
+
| **Business Context** | Problem this UI solves? Usage scenario? |
|
|
45
|
+
|
|
46
|
+
**Additional signals:**
|
|
47
|
+
- Existing code: Extract style patterns, color schemes, component conventions
|
|
48
|
+
- User prompt: Parse keywords (landing page, dashboard, portfolio, SaaS, etc.)
|
|
49
|
+
- Follow-up questions: Surface full vision even for simple prompts
|
|
50
|
+
|
|
51
|
+
Gather sufficient context before proceeding to Phase 1.
|
|
52
|
+
|
|
53
|
+
### Phase 1: Identify the Mode
|
|
54
|
+
|
|
55
|
+
**Verbalize the highest-probability (P ≈ 0.95) design:**
|
|
56
|
+
|
|
57
|
+
AI-slop markers:
|
|
58
|
+
- Inter/Roboto/System fonts
|
|
59
|
+
- Rounded blue/purple buttons
|
|
60
|
+
- Standard F-pattern layouts
|
|
61
|
+
- White backgrounds with gradient accents
|
|
62
|
+
- Generic hero sections with stock imagery
|
|
63
|
+
|
|
64
|
+
**Avoid this baseline.**
|
|
65
|
+
|
|
66
|
+
### Phase 2: Sample the Long-Tail
|
|
67
|
+
|
|
68
|
+
**Generate 3 directions with T-Score (Typicality Score, 0~1.0):**
|
|
69
|
+
|
|
70
|
+
| Direction | T-Score | Characteristics |
|
|
71
|
+
|-----------|---------|-----------------|
|
|
72
|
+
| **A** | ≈ 0.7 | Modern/Clean, safe |
|
|
73
|
+
| **B** | ≈ 0.4 | Distinctive/Characterful (specific niche style) |
|
|
74
|
+
| **C** | < 0.2 | Experimental/Bold (high-entropy, unexpected) |
|
|
75
|
+
|
|
76
|
+
**T-Score justification required:** Explain WHY each direction has that score. Reference specific design choices.
|
|
77
|
+
|
|
78
|
+
### Phase 3: Commit to Low-Typicality
|
|
79
|
+
|
|
80
|
+
**Select lowest T-Score that meets:**
|
|
81
|
+
1. Functional requirements from Phase 0
|
|
82
|
+
2. All Quality Guardrails
|
|
83
|
+
|
|
84
|
+
Deliberate and intentional choice, not accidental.
|
|
85
|
+
|
|
86
|
+
</workflow>
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
<guardrails>
|
|
91
|
+
|
|
92
|
+
## Quality Principles
|
|
93
|
+
|
|
94
|
+
Experimental designs must satisfy these principles. If violated, increase T-Score until compliance.
|
|
95
|
+
|
|
96
|
+
| Principle | Description |
|
|
97
|
+
|-----------|-------------|
|
|
98
|
+
| **Visual Hierarchy** | Clear priority ordering (1st → 2nd → 3rd) |
|
|
99
|
+
| **Contrast & Legibility** | Text readable against background (WCAG AA minimum) |
|
|
100
|
+
| **Internal Consistency** | Design follows its own logic (not random) |
|
|
101
|
+
| **Functional Clarity** | Interactive elements recognizable, affordances clear |
|
|
102
|
+
|
|
103
|
+
</guardrails>
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
<anti_patterns>
|
|
108
|
+
|
|
109
|
+
## Failure Patterns
|
|
110
|
+
|
|
111
|
+
| Pattern | Symptoms | Validation |
|
|
112
|
+
|---------|----------|------------|
|
|
113
|
+
| **Accidental Design** | Differentiation without intent, randomness | "Why this color/font/layout?" → must have coherent answer |
|
|
114
|
+
| **Frankenstein Style** | Incompatible aesthetics mixed, no unity | "Describe this design's personality in one sentence?" → must be possible |
|
|
115
|
+
|
|
116
|
+
</anti_patterns>
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
<aesthetics>
|
|
121
|
+
|
|
122
|
+
## Frontend Aesthetics Guidelines (VS-Enhanced)
|
|
123
|
+
|
|
124
|
+
**Inversion Principle:** If a choice feels "obvious," it has too much probability mass → consider lower-probability, higher-impact alternatives (when context-appropriate).
|
|
125
|
+
|
|
126
|
+
### Typography
|
|
127
|
+
|
|
128
|
+
| Category | Content |
|
|
129
|
+
|----------|---------|
|
|
130
|
+
| ❌ **AI-slop** | Inter, Roboto, Arial, System fonts, Space Grotesk (default usage) |
|
|
131
|
+
| ✅ **Low-T** | High-character display faces + refined, unexpected body typefaces. Variable fonts, unusual weights. |
|
|
132
|
+
| **Context-dependent** | Brutalist portfolio → industrial sans-serifs / Luxury brand → refined serifs |
|
|
133
|
+
|
|
134
|
+
### Color & Theme
|
|
135
|
+
|
|
136
|
+
| Principle | Description |
|
|
137
|
+
|-----------|-------------|
|
|
138
|
+
| ✅ **Uneven distribution** | Cohesive but "dissonant-yet-beautiful" palette |
|
|
139
|
+
| ✅ **CSS Variables** | Systematic theming |
|
|
140
|
+
| ✅ **Texture-first** | Sophisticated noise/lighting over flat fills (when context-appropriate) |
|
|
141
|
+
|
|
142
|
+
### Spatial Composition
|
|
143
|
+
|
|
144
|
+
| Condition | Approach |
|
|
145
|
+
|-----------|----------|
|
|
146
|
+
| **Standard grid (P=0.9)** | Consider asymmetry, overlapping elements, diagonal flows, editorial whitespace (P=0.1) |
|
|
147
|
+
| **Data-heavy UIs** | Dashboards, tables → conventional grids may be needed (usability priority) |
|
|
148
|
+
|
|
149
|
+
### Motion
|
|
150
|
+
|
|
151
|
+
| Principle | Description |
|
|
152
|
+
|-----------|-------------|
|
|
153
|
+
| ✅ **Micro-delights** | Staggered reveals, scroll-bound transformations, custom easing |
|
|
154
|
+
| ❌ **Purposeless motion** | Every animation must have purpose |
|
|
155
|
+
|
|
156
|
+
</aesthetics>
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
<frameworks>
|
|
161
|
+
|
|
162
|
+
## AIDA Framework (Conditional)
|
|
163
|
+
|
|
164
|
+
**Apply only for persuasion/conversion goals (landing pages, marketing sites, product showcases):**
|
|
165
|
+
|
|
166
|
+
| Stage | Goal | Design Application |
|
|
167
|
+
|-------|------|-------------------|
|
|
168
|
+
| **A**ttention | Stop scroll, create immediate visual impact | Bold typography, unexpected imagery, striking color contrast |
|
|
169
|
+
| **I**nterest | Build curiosity, encourage exploration | Progressive information reveal, visual storytelling, highlight unique value |
|
|
170
|
+
| **D**esire | Create emotional connection, make them want it | Social proof, benefits visualization, aspirational imagery, micro-interactions |
|
|
171
|
+
| **A**ction | Drive conversion with clear next steps | High-contrast CTAs, reduced friction, urgency cues (when appropriate) |
|
|
172
|
+
|
|
173
|
+
### Application Conditions
|
|
174
|
+
|
|
175
|
+
| Apply ✅ | Don't Apply ❌ |
|
|
176
|
+
|---------|----------------|
|
|
177
|
+
| Landing/marketing pages | Dashboards, data-heavy UIs (usability priority) |
|
|
178
|
+
| Product launch pages | Documentation/content-focused sites (readability priority) |
|
|
179
|
+
| Client-attracting portfolios | Internal tools (efficiency priority) |
|
|
180
|
+
|
|
181
|
+
**VS + AIDA Integration:** Apply Low-T aesthetics to EACH AIDA stage. Generic hero → Attention failure / Predictable CTA → Action failure. AIDA = "what", VS = "how".
|
|
182
|
+
|
|
183
|
+
</frameworks>
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
<implementation>
|
|
188
|
+
|
|
189
|
+
## Implementation Standards
|
|
190
|
+
|
|
191
|
+
| Standard | Description |
|
|
192
|
+
|----------|-------------|
|
|
193
|
+
| **Production-Grade** | Functional, accessible (A11y), performant |
|
|
194
|
+
| **Complexity-Typicality Balance** | Low-T design → implementation complexity increases proportionally (maintain quality) |
|
|
195
|
+
| **No Complexity Refusal** | Pursue extraordinary work, don't simplify vision |
|
|
196
|
+
|
|
197
|
+
</implementation>
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
<validation>
|
|
202
|
+
|
|
203
|
+
## Final Validation
|
|
204
|
+
|
|
205
|
+
Pre-delivery checklist:
|
|
206
|
+
|
|
207
|
+
1. **Intentionality**: Can you justify every major design decision?
|
|
208
|
+
2. **Consistency**: Does the design follow its own internal logic?
|
|
209
|
+
3. **Guardrails**: Are hierarchy, legibility, consistency, and clarity preserved?
|
|
210
|
+
4. **Surprise**: Would this stand out in a lineup of AI-generated designs?
|
|
211
|
+
|
|
212
|
+
**Goal:** Maximize "Surprise Score" while maintaining "Production Quality." Deliberate disruption.
|
|
213
|
+
|
|
214
|
+
</validation>
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
<examples>
|
|
219
|
+
|
|
220
|
+
## Practical Examples
|
|
221
|
+
|
|
222
|
+
### Phase 2: T-Score Justification
|
|
223
|
+
|
|
224
|
+
```markdown
|
|
225
|
+
**Direction A (T ≈ 0.7): Modern Minimal**
|
|
226
|
+
- Inter font, white background, blue buttons
|
|
227
|
+
- High typicality: 2020s SaaS standard pattern
|
|
228
|
+
|
|
229
|
+
**Direction B (T ≈ 0.4): Brutalist Style**
|
|
230
|
+
- Space Mono font, grid background, angular black buttons
|
|
231
|
+
- Lower typicality: Specific niche, non-mainstream choice
|
|
232
|
+
|
|
233
|
+
**Direction C (T < 0.2): Neo-Baroque**
|
|
234
|
+
- Fraunces Display font, irregular layout, animated gradients
|
|
235
|
+
- Very low probability: Rarely seen on web
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Typography Code
|
|
239
|
+
|
|
240
|
+
```css
|
|
241
|
+
/* ❌ AI-slop */
|
|
242
|
+
font-family: 'Inter', system-ui, sans-serif;
|
|
243
|
+
|
|
244
|
+
/* ✅ Low-T (Brutalist portfolio) */
|
|
245
|
+
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');
|
|
246
|
+
font-family: 'Space Mono', monospace;
|
|
247
|
+
font-variation-settings: 'wght' 650;
|
|
248
|
+
|
|
249
|
+
/* ✅ Low-T (Luxury brand) */
|
|
250
|
+
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;500&display=swap');
|
|
251
|
+
font-family: 'Cormorant Garamond', serif;
|
|
252
|
+
letter-spacing: 0.05em;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Color System
|
|
256
|
+
|
|
257
|
+
```css
|
|
258
|
+
/* ❌ AI-slop (even distribution) */
|
|
259
|
+
:root {
|
|
260
|
+
--primary: #3b82f6; /* blue */
|
|
261
|
+
--secondary: #a855f7; /* purple */
|
|
262
|
+
--accent: #10b981; /* green */
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* ✅ Low-T (uneven, cohesive) */
|
|
266
|
+
:root {
|
|
267
|
+
--dominant: #0a0908; /* near-black (60%) */
|
|
268
|
+
--support: #8d99ae; /* neutral blue (30%) */
|
|
269
|
+
--punch: #ef233c; /* intense red (10%) */
|
|
270
|
+
--texture: url('data:image/svg+xml,...'); /* noise overlay */
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### AIDA + Low-T Integration
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
// Hero Section (Attention stage + Low-T)
|
|
278
|
+
<section className="hero">
|
|
279
|
+
<h1 style={{
|
|
280
|
+
fontFamily: 'Fraunces',
|
|
281
|
+
fontSize: 'clamp(3rem, 10vw, 8rem)',
|
|
282
|
+
fontVariationSettings: '"SOFT" 100, "WONK" 1',
|
|
283
|
+
background: 'linear-gradient(135deg, #0a0908, #ef233c)',
|
|
284
|
+
backgroundClip: 'text',
|
|
285
|
+
WebkitTextFillColor: 'transparent',
|
|
286
|
+
}}>
|
|
287
|
+
Disruptive Product Name
|
|
288
|
+
</h1>
|
|
289
|
+
{/* Unexpected imagery treatment */}
|
|
290
|
+
</section>
|
|
291
|
+
|
|
292
|
+
// CTA (Action stage + Low-T)
|
|
293
|
+
<button style={{
|
|
294
|
+
background: '#ef233c',
|
|
295
|
+
color: '#0a0908',
|
|
296
|
+
border: '2px solid #0a0908',
|
|
297
|
+
padding: '1.5rem 3rem',
|
|
298
|
+
fontSize: '1.25rem',
|
|
299
|
+
fontWeight: 700,
|
|
300
|
+
clipPath: 'polygon(5% 0, 100% 0, 95% 100%, 0 100%)', // asymmetric
|
|
301
|
+
transition: 'clip-path 0.3s cubic-bezier(0.4, 0, 0.2, 1)',
|
|
302
|
+
}}>
|
|
303
|
+
Get Started →
|
|
304
|
+
</button>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
</examples>
|