@0xsown/vibe-code-fe 1.0.0
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/bin/index.js +181 -0
- package/package.json +32 -0
- package/skills/claude-md-improver/SKILL.md +179 -0
- package/skills/claude-md-improver/references/quality-criteria.md +109 -0
- package/skills/claude-md-improver/references/templates.md +253 -0
- package/skills/claude-md-improver/references/update-guidelines.md +150 -0
- package/skills/find-skills/SKILL.md +133 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +42 -0
- package/skills/next-best-practices/SKILL.md +153 -0
- package/skills/next-best-practices/async-patterns.md +87 -0
- package/skills/next-best-practices/bundling.md +180 -0
- package/skills/next-best-practices/data-patterns.md +297 -0
- package/skills/next-best-practices/debug-tricks.md +105 -0
- package/skills/next-best-practices/directives.md +73 -0
- package/skills/next-best-practices/error-handling.md +227 -0
- package/skills/next-best-practices/file-conventions.md +140 -0
- package/skills/next-best-practices/font.md +245 -0
- package/skills/next-best-practices/functions.md +108 -0
- package/skills/next-best-practices/hydration-error.md +91 -0
- package/skills/next-best-practices/image.md +173 -0
- package/skills/next-best-practices/metadata.md +301 -0
- package/skills/next-best-practices/parallel-routes.md +287 -0
- package/skills/next-best-practices/route-handlers.md +146 -0
- package/skills/next-best-practices/rsc-boundaries.md +159 -0
- package/skills/next-best-practices/runtime-selection.md +39 -0
- package/skills/next-best-practices/scripts.md +141 -0
- package/skills/next-best-practices/self-hosting.md +371 -0
- package/skills/next-best-practices/suspense-boundaries.md +67 -0
- package/skills/next-cache-components/SKILL.md +411 -0
- package/skills/shadcn-ui/README.md +248 -0
- package/skills/shadcn-ui/SKILL.md +326 -0
- package/skills/shadcn-ui/examples/auth-layout.tsx +177 -0
- package/skills/shadcn-ui/examples/data-table.tsx +313 -0
- package/skills/shadcn-ui/examples/form-pattern.tsx +177 -0
- package/skills/shadcn-ui/resources/component-catalog.md +481 -0
- package/skills/shadcn-ui/resources/customization-guide.md +516 -0
- package/skills/shadcn-ui/resources/migration-guide.md +463 -0
- package/skills/shadcn-ui/resources/setup-guide.md +412 -0
- package/skills/shadcn-ui/scripts/verify-setup.sh +134 -0
- package/skills/supabase-postgres-best-practices/AGENTS.md +68 -0
- package/skills/supabase-postgres-best-practices/CLAUDE.md +68 -0
- package/skills/supabase-postgres-best-practices/README.md +116 -0
- package/skills/supabase-postgres-best-practices/SKILL.md +64 -0
- package/skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
- package/skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
- package/skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
- package/skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
- package/skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
- package/skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
- package/skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
- package/skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
- package/skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
- package/skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
- package/skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
- package/skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
- package/skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
- package/skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
- package/skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
- package/skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
- package/skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
- package/skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
- package/skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
- package/skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
- package/skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
- package/skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
- package/skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
- package/skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
- package/skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
- package/skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
- package/skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
- package/skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
- package/skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
- package/skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
- package/skills/supabase-postgres-best-practices/references/security-rls-performance.md +57 -0
- package/skills/tailwind-design-system/SKILL.md +874 -0
- package/skills/vercel-composition-patterns/AGENTS.md +946 -0
- package/skills/vercel-composition-patterns/README.md +60 -0
- package/skills/vercel-composition-patterns/SKILL.md +89 -0
- package/skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
- package/skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
- package/skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
- package/skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
- package/skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
- package/skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
- package/skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
- package/skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
- package/skills/vercel-react-best-practices/AGENTS.md +2934 -0
- package/skills/vercel-react-best-practices/README.md +123 -0
- package/skills/vercel-react-best-practices/SKILL.md +136 -0
- package/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
- package/skills/vercel-react-best-practices/rules/async-defer-await.md +80 -0
- package/skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
- package/skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
- package/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
- package/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
- package/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
- package/skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
- package/skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
- package/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
- package/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
- package/skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
- package/skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
- package/skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
- package/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
- package/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
- package/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
- package/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
- package/skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
- package/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
- package/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
- package/skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
- package/skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
- package/skills/vercel-react-native-skills/AGENTS.md +2897 -0
- package/skills/vercel-react-native-skills/README.md +165 -0
- package/skills/vercel-react-native-skills/SKILL.md +121 -0
- package/skills/vercel-react-native-skills/rules/animation-derived-value.md +53 -0
- package/skills/vercel-react-native-skills/rules/animation-gesture-detector-press.md +95 -0
- package/skills/vercel-react-native-skills/rules/animation-gpu-properties.md +65 -0
- package/skills/vercel-react-native-skills/rules/design-system-compound-components.md +66 -0
- package/skills/vercel-react-native-skills/rules/fonts-config-plugin.md +71 -0
- package/skills/vercel-react-native-skills/rules/imports-design-system-folder.md +68 -0
- package/skills/vercel-react-native-skills/rules/js-hoist-intl.md +61 -0
- package/skills/vercel-react-native-skills/rules/list-performance-callbacks.md +44 -0
- package/skills/vercel-react-native-skills/rules/list-performance-function-references.md +132 -0
- package/skills/vercel-react-native-skills/rules/list-performance-images.md +53 -0
- package/skills/vercel-react-native-skills/rules/list-performance-inline-objects.md +97 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-expensive.md +94 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-memo.md +82 -0
- package/skills/vercel-react-native-skills/rules/list-performance-item-types.md +104 -0
- package/skills/vercel-react-native-skills/rules/list-performance-virtualize.md +67 -0
- package/skills/vercel-react-native-skills/rules/monorepo-native-deps-in-app.md +46 -0
- package/skills/vercel-react-native-skills/rules/monorepo-single-dependency-versions.md +63 -0
- package/skills/vercel-react-native-skills/rules/navigation-native-navigators.md +188 -0
- package/skills/vercel-react-native-skills/rules/react-compiler-destructure-functions.md +50 -0
- package/skills/vercel-react-native-skills/rules/react-compiler-reanimated-shared-values.md +48 -0
- package/skills/vercel-react-native-skills/rules/react-state-dispatcher.md +91 -0
- package/skills/vercel-react-native-skills/rules/react-state-fallback.md +56 -0
- package/skills/vercel-react-native-skills/rules/react-state-minimize.md +65 -0
- package/skills/vercel-react-native-skills/rules/rendering-no-falsy-and.md +74 -0
- package/skills/vercel-react-native-skills/rules/rendering-text-in-text-component.md +36 -0
- package/skills/vercel-react-native-skills/rules/scroll-position-no-state.md +82 -0
- package/skills/vercel-react-native-skills/rules/state-ground-truth.md +80 -0
- package/skills/vercel-react-native-skills/rules/ui-expo-image.md +66 -0
- package/skills/vercel-react-native-skills/rules/ui-image-gallery.md +104 -0
- package/skills/vercel-react-native-skills/rules/ui-measure-views.md +78 -0
- package/skills/vercel-react-native-skills/rules/ui-menus.md +174 -0
- package/skills/vercel-react-native-skills/rules/ui-native-modals.md +77 -0
- package/skills/vercel-react-native-skills/rules/ui-pressable.md +61 -0
- package/skills/vercel-react-native-skills/rules/ui-safe-area-scroll.md +65 -0
- package/skills/vercel-react-native-skills/rules/ui-scrollview-content-inset.md +45 -0
- package/skills/vercel-react-native-skills/rules/ui-styling.md +87 -0
- package/skills/web-design-guidelines/SKILL.md +39 -0
- package/templates/AGENTS.md +31 -0
- package/templates/CLAUDE.md +31 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: next-cache-components
|
|
3
|
+
description: Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cache Components (Next.js 16+)
|
|
7
|
+
|
|
8
|
+
Cache Components enable Partial Prerendering (PPR) - mix static, cached, and dynamic content in a single route.
|
|
9
|
+
|
|
10
|
+
## Enable Cache Components
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
// next.config.ts
|
|
14
|
+
import type { NextConfig } from 'next'
|
|
15
|
+
|
|
16
|
+
const nextConfig: NextConfig = {
|
|
17
|
+
cacheComponents: true,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default nextConfig
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This replaces the old `experimental.ppr` flag.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Three Content Types
|
|
28
|
+
|
|
29
|
+
With Cache Components enabled, content falls into three categories:
|
|
30
|
+
|
|
31
|
+
### 1. Static (Auto-Prerendered)
|
|
32
|
+
|
|
33
|
+
Synchronous code, imports, pure computations - prerendered at build time:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
export default function Page() {
|
|
37
|
+
return (
|
|
38
|
+
<header>
|
|
39
|
+
<h1>Our Blog</h1> {/* Static - instant */}
|
|
40
|
+
<nav>...</nav>
|
|
41
|
+
</header>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Cached (`use cache`)
|
|
47
|
+
|
|
48
|
+
Async data that doesn't need fresh fetches every request:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
async function BlogPosts() {
|
|
52
|
+
'use cache'
|
|
53
|
+
cacheLife('hours')
|
|
54
|
+
|
|
55
|
+
const posts = await db.posts.findMany()
|
|
56
|
+
return <PostList posts={posts} />
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 3. Dynamic (Suspense)
|
|
61
|
+
|
|
62
|
+
Runtime data that must be fresh - wrap in Suspense:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { Suspense } from 'react'
|
|
66
|
+
|
|
67
|
+
export default function Page() {
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<BlogPosts /> {/* Cached */}
|
|
71
|
+
|
|
72
|
+
<Suspense fallback={<p>Loading...</p>}>
|
|
73
|
+
<UserPreferences /> {/* Dynamic - streams in */}
|
|
74
|
+
</Suspense>
|
|
75
|
+
</>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function UserPreferences() {
|
|
80
|
+
const theme = (await cookies()).get('theme')?.value
|
|
81
|
+
return <p>Theme: {theme}</p>
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## `use cache` Directive
|
|
88
|
+
|
|
89
|
+
### File Level
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
'use cache'
|
|
93
|
+
|
|
94
|
+
export default async function Page() {
|
|
95
|
+
// Entire page is cached
|
|
96
|
+
const data = await fetchData()
|
|
97
|
+
return <div>{data}</div>
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Component Level
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
export async function CachedComponent() {
|
|
105
|
+
'use cache'
|
|
106
|
+
const data = await fetchData()
|
|
107
|
+
return <div>{data}</div>
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Function Level
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
export async function getData() {
|
|
115
|
+
'use cache'
|
|
116
|
+
return db.query('SELECT * FROM posts')
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Cache Profiles
|
|
123
|
+
|
|
124
|
+
### Built-in Profiles
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
'use cache' // Default: 5m stale, 15m revalidate
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
'use cache: remote' // Platform-provided cache (Redis, KV)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
'use cache: private' // For compliance, allows runtime APIs
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `cacheLife()` - Custom Lifetime
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import { cacheLife } from 'next/cache'
|
|
142
|
+
|
|
143
|
+
async function getData() {
|
|
144
|
+
'use cache'
|
|
145
|
+
cacheLife('hours') // Built-in profile
|
|
146
|
+
return fetch('/api/data')
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Built-in profiles: `'default'`, `'minutes'`, `'hours'`, `'days'`, `'weeks'`, `'max'`
|
|
151
|
+
|
|
152
|
+
### Inline Configuration
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
async function getData() {
|
|
156
|
+
'use cache'
|
|
157
|
+
cacheLife({
|
|
158
|
+
stale: 3600, // 1 hour - serve stale while revalidating
|
|
159
|
+
revalidate: 7200, // 2 hours - background revalidation interval
|
|
160
|
+
expire: 86400, // 1 day - hard expiration
|
|
161
|
+
})
|
|
162
|
+
return fetch('/api/data')
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Cache Invalidation
|
|
169
|
+
|
|
170
|
+
### `cacheTag()` - Tag Cached Content
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
import { cacheTag } from 'next/cache'
|
|
174
|
+
|
|
175
|
+
async function getProducts() {
|
|
176
|
+
'use cache'
|
|
177
|
+
cacheTag('products')
|
|
178
|
+
return db.products.findMany()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function getProduct(id: string) {
|
|
182
|
+
'use cache'
|
|
183
|
+
cacheTag('products', `product-${id}`)
|
|
184
|
+
return db.products.findUnique({ where: { id } })
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `updateTag()` - Immediate Invalidation
|
|
189
|
+
|
|
190
|
+
Use when you need the cache refreshed within the same request:
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
'use server'
|
|
194
|
+
|
|
195
|
+
import { updateTag } from 'next/cache'
|
|
196
|
+
|
|
197
|
+
export async function updateProduct(id: string, data: FormData) {
|
|
198
|
+
await db.products.update({ where: { id }, data })
|
|
199
|
+
updateTag(`product-${id}`) // Immediate - same request sees fresh data
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### `revalidateTag()` - Background Revalidation
|
|
204
|
+
|
|
205
|
+
Use for stale-while-revalidate behavior:
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
'use server'
|
|
209
|
+
|
|
210
|
+
import { revalidateTag } from 'next/cache'
|
|
211
|
+
|
|
212
|
+
export async function createPost(data: FormData) {
|
|
213
|
+
await db.posts.create({ data })
|
|
214
|
+
revalidateTag('posts') // Background - next request sees fresh data
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Runtime Data Constraint
|
|
221
|
+
|
|
222
|
+
**Cannot** access `cookies()`, `headers()`, or `searchParams` inside `use cache`.
|
|
223
|
+
|
|
224
|
+
### Solution: Pass as Arguments
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
// Wrong - runtime API inside use cache
|
|
228
|
+
async function CachedProfile() {
|
|
229
|
+
'use cache'
|
|
230
|
+
const session = (await cookies()).get('session')?.value // Error!
|
|
231
|
+
return <div>{session}</div>
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Correct - extract outside, pass as argument
|
|
235
|
+
async function ProfilePage() {
|
|
236
|
+
const session = (await cookies()).get('session')?.value
|
|
237
|
+
return <CachedProfile sessionId={session} />
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function CachedProfile({ sessionId }: { sessionId: string }) {
|
|
241
|
+
'use cache'
|
|
242
|
+
// sessionId becomes part of cache key automatically
|
|
243
|
+
const data = await fetchUserData(sessionId)
|
|
244
|
+
return <div>{data.name}</div>
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Exception: `use cache: private`
|
|
249
|
+
|
|
250
|
+
For compliance requirements when you can't refactor:
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
async function getData() {
|
|
254
|
+
'use cache: private'
|
|
255
|
+
const session = (await cookies()).get('session')?.value // Allowed
|
|
256
|
+
return fetchData(session)
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Cache Key Generation
|
|
263
|
+
|
|
264
|
+
Cache keys are automatic based on:
|
|
265
|
+
- **Build ID** - invalidates all caches on deploy
|
|
266
|
+
- **Function ID** - hash of function location
|
|
267
|
+
- **Serializable arguments** - props become part of key
|
|
268
|
+
- **Closure variables** - outer scope values included
|
|
269
|
+
|
|
270
|
+
```tsx
|
|
271
|
+
async function Component({ userId }: { userId: string }) {
|
|
272
|
+
const getData = async (filter: string) => {
|
|
273
|
+
'use cache'
|
|
274
|
+
// Cache key = userId (closure) + filter (argument)
|
|
275
|
+
return fetch(`/api/users/${userId}?filter=${filter}`)
|
|
276
|
+
}
|
|
277
|
+
return getData('active')
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Complete Example
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
import { Suspense } from 'react'
|
|
287
|
+
import { cookies } from 'next/headers'
|
|
288
|
+
import { cacheLife, cacheTag } from 'next/cache'
|
|
289
|
+
|
|
290
|
+
export default function DashboardPage() {
|
|
291
|
+
return (
|
|
292
|
+
<>
|
|
293
|
+
{/* Static shell - instant from CDN */}
|
|
294
|
+
<header><h1>Dashboard</h1></header>
|
|
295
|
+
<nav>...</nav>
|
|
296
|
+
|
|
297
|
+
{/* Cached - fast, revalidates hourly */}
|
|
298
|
+
<Stats />
|
|
299
|
+
|
|
300
|
+
{/* Dynamic - streams in with fresh data */}
|
|
301
|
+
<Suspense fallback={<NotificationsSkeleton />}>
|
|
302
|
+
<Notifications />
|
|
303
|
+
</Suspense>
|
|
304
|
+
</>
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function Stats() {
|
|
309
|
+
'use cache'
|
|
310
|
+
cacheLife('hours')
|
|
311
|
+
cacheTag('dashboard-stats')
|
|
312
|
+
|
|
313
|
+
const stats = await db.stats.aggregate()
|
|
314
|
+
return <StatsDisplay stats={stats} />
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function Notifications() {
|
|
318
|
+
const userId = (await cookies()).get('userId')?.value
|
|
319
|
+
const notifications = await db.notifications.findMany({
|
|
320
|
+
where: { userId, read: false }
|
|
321
|
+
})
|
|
322
|
+
return <NotificationList items={notifications} />
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Migration from Previous Versions
|
|
329
|
+
|
|
330
|
+
| Old Config | Replacement |
|
|
331
|
+
|-----------|-------------|
|
|
332
|
+
| `experimental.ppr` | `cacheComponents: true` |
|
|
333
|
+
| `dynamic = 'force-dynamic'` | Remove (default behavior) |
|
|
334
|
+
| `dynamic = 'force-static'` | `'use cache'` + `cacheLife('max')` |
|
|
335
|
+
| `revalidate = N` | `cacheLife({ revalidate: N })` |
|
|
336
|
+
| `unstable_cache()` | `'use cache'` directive |
|
|
337
|
+
|
|
338
|
+
### Migrating `unstable_cache` to `use cache`
|
|
339
|
+
|
|
340
|
+
`unstable_cache` has been replaced by the `use cache` directive in Next.js 16. When `cacheComponents` is enabled, convert `unstable_cache` calls to `use cache` functions:
|
|
341
|
+
|
|
342
|
+
**Before (`unstable_cache`):**
|
|
343
|
+
|
|
344
|
+
```tsx
|
|
345
|
+
import { unstable_cache } from 'next/cache'
|
|
346
|
+
|
|
347
|
+
const getCachedUser = unstable_cache(
|
|
348
|
+
async (id) => getUser(id),
|
|
349
|
+
['my-app-user'],
|
|
350
|
+
{
|
|
351
|
+
tags: ['users'],
|
|
352
|
+
revalidate: 60,
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
|
|
357
|
+
const { id } = await params
|
|
358
|
+
const user = await getCachedUser(id)
|
|
359
|
+
return <div>{user.name}</div>
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**After (`use cache`):**
|
|
364
|
+
|
|
365
|
+
```tsx
|
|
366
|
+
import { cacheLife, cacheTag } from 'next/cache'
|
|
367
|
+
|
|
368
|
+
async function getCachedUser(id: string) {
|
|
369
|
+
'use cache'
|
|
370
|
+
cacheTag('users')
|
|
371
|
+
cacheLife({ revalidate: 60 })
|
|
372
|
+
return getUser(id)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export default async function Page({ params }: { params: Promise<{ id: string }> }) {
|
|
376
|
+
const { id } = await params
|
|
377
|
+
const user = await getCachedUser(id)
|
|
378
|
+
return <div>{user.name}</div>
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Key differences:
|
|
383
|
+
- **No manual cache keys** - `use cache` generates keys automatically from function arguments and closures. The `keyParts` array from `unstable_cache` is no longer needed.
|
|
384
|
+
- **Tags** - Replace `options.tags` with `cacheTag()` calls inside the function.
|
|
385
|
+
- **Revalidation** - Replace `options.revalidate` with `cacheLife({ revalidate: N })` or a built-in profile like `cacheLife('minutes')`.
|
|
386
|
+
- **Dynamic data** - `unstable_cache` did not support `cookies()` or `headers()` inside the callback. The same restriction applies to `use cache`, but you can use `'use cache: private'` if needed.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Limitations
|
|
391
|
+
|
|
392
|
+
- **Edge runtime not supported** - requires Node.js
|
|
393
|
+
- **Static export not supported** - needs server
|
|
394
|
+
- **Non-deterministic values** (`Math.random()`, `Date.now()`) execute once at build time inside `use cache`
|
|
395
|
+
|
|
396
|
+
For request-time randomness outside cache:
|
|
397
|
+
|
|
398
|
+
```tsx
|
|
399
|
+
import { connection } from 'next/server'
|
|
400
|
+
|
|
401
|
+
async function DynamicContent() {
|
|
402
|
+
await connection() // Defer to request time
|
|
403
|
+
const id = crypto.randomUUID() // Different per request
|
|
404
|
+
return <div>{id}</div>
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Sources:
|
|
409
|
+
- [Cache Components Guide](https://nextjs.org/docs/app/getting-started/cache-components)
|
|
410
|
+
- [use cache Directive](https://nextjs.org/docs/app/api-reference/directives/use-cache)
|
|
411
|
+
- [unstable_cache (legacy)](https://nextjs.org/docs/app/api-reference/functions/unstable_cache)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# shadcn/ui Integration Skill
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx skills add google-labs-code/stitch-skills --skill shadcn-ui --global
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## What It Does
|
|
10
|
+
|
|
11
|
+
This skill provides expert guidance for integrating shadcn/ui components into your React applications. It helps you discover, install, customize, and optimize shadcn/ui components while following best practices.
|
|
12
|
+
|
|
13
|
+
## Example Prompts
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
Help me set up shadcn/ui in my Next.js project
|
|
17
|
+
|
|
18
|
+
Add a data table component with sorting and filtering to my app
|
|
19
|
+
|
|
20
|
+
Show me how to customize the button component with a new variant
|
|
21
|
+
|
|
22
|
+
Create a login form using shadcn/ui components with validation
|
|
23
|
+
|
|
24
|
+
Build a dashboard layout with sidebar navigation using shadcn/ui blocks
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## What is shadcn/ui?
|
|
28
|
+
|
|
29
|
+
shadcn/ui is a collection of beautifully designed, accessible, and customizable components built with:
|
|
30
|
+
- **Radix UI or Base UI**: Unstyled, accessible component primitives
|
|
31
|
+
- **Tailwind CSS**: Utility-first styling framework
|
|
32
|
+
- **TypeScript**: Full type safety
|
|
33
|
+
|
|
34
|
+
**Key Difference**: Unlike traditional component libraries, shadcn/ui copies components directly into your project. This gives you:
|
|
35
|
+
- Full control over the code
|
|
36
|
+
- No version lock-in
|
|
37
|
+
- Complete customization freedom
|
|
38
|
+
- Zero runtime overhead
|
|
39
|
+
|
|
40
|
+
## Skill Structure
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
skills/shadcn-ui/
|
|
44
|
+
├── SKILL.md — Core instructions & workflow
|
|
45
|
+
├── README.md — This file
|
|
46
|
+
├── examples/ — Example implementations
|
|
47
|
+
│ ├── form-pattern.tsx — Form with validation
|
|
48
|
+
│ ├── data-table.tsx — Advanced table with sorting
|
|
49
|
+
│ └── auth-layout.tsx — Authentication flow
|
|
50
|
+
├── resources/ — Reference documentation
|
|
51
|
+
│ ├── setup-guide.md — Project initialization
|
|
52
|
+
│ ├── component-catalog.md — Component reference
|
|
53
|
+
│ ├── customization-guide.md — Theming patterns
|
|
54
|
+
│ └── migration-guide.md — Migration from other libraries
|
|
55
|
+
└── scripts/ — Utility scripts
|
|
56
|
+
└── verify-setup.sh — Validate project configuration
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## How It Works
|
|
60
|
+
|
|
61
|
+
When activated, the agent follows this workflow:
|
|
62
|
+
|
|
63
|
+
### 1. **Discovery & Planning**
|
|
64
|
+
- Lists available components using shadcn MCP tools
|
|
65
|
+
- Identifies required dependencies
|
|
66
|
+
- Plans component composition strategy
|
|
67
|
+
|
|
68
|
+
### 2. **Setup & Configuration**
|
|
69
|
+
- Verifies or initializes `components.json`
|
|
70
|
+
- Checks Tailwind CSS configuration
|
|
71
|
+
- Validates import aliases and paths
|
|
72
|
+
|
|
73
|
+
### 3. **Component Integration**
|
|
74
|
+
- Retrieves component source code
|
|
75
|
+
- Installs via CLI or manual integration
|
|
76
|
+
- Handles dependency installation
|
|
77
|
+
|
|
78
|
+
### 4. **Customization**
|
|
79
|
+
- Applies theme customization
|
|
80
|
+
- Creates component variants
|
|
81
|
+
- Extends components with custom logic
|
|
82
|
+
|
|
83
|
+
### 5. **Quality Assurance**
|
|
84
|
+
- Validates TypeScript types
|
|
85
|
+
- Checks accessibility compliance
|
|
86
|
+
- Verifies responsive behavior
|
|
87
|
+
|
|
88
|
+
## Prerequisites
|
|
89
|
+
|
|
90
|
+
Your project should have:
|
|
91
|
+
- **React 18+**
|
|
92
|
+
- **Tailwind CSS 3.0+**
|
|
93
|
+
- **TypeScript** (recommended)
|
|
94
|
+
- **Node.js 18+**
|
|
95
|
+
|
|
96
|
+
## Quick Start
|
|
97
|
+
|
|
98
|
+
### For New Projects
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Create Next.js project with shadcn/ui
|
|
102
|
+
npx create-next-app@latest my-app
|
|
103
|
+
cd my-app
|
|
104
|
+
npx shadcn@latest init
|
|
105
|
+
|
|
106
|
+
# Add components
|
|
107
|
+
npx shadcn@latest add button
|
|
108
|
+
npx shadcn@latest add card
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### For Existing Projects
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# Initialize shadcn/ui
|
|
115
|
+
npx shadcn@latest init
|
|
116
|
+
|
|
117
|
+
# Configure when prompted:
|
|
118
|
+
# - Choose style (default/new-york)
|
|
119
|
+
# - Select base color
|
|
120
|
+
# - Configure CSS variables
|
|
121
|
+
# - Set import aliases
|
|
122
|
+
|
|
123
|
+
# Add your first component
|
|
124
|
+
npx shadcn@latest add button
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Available Components
|
|
128
|
+
|
|
129
|
+
shadcn/ui provides 50+ components including:
|
|
130
|
+
|
|
131
|
+
**Layout**: Accordion, Card, Separator, Tabs, Collapsible
|
|
132
|
+
**Forms**: Button, Input, Label, Checkbox, Radio Group, Select, Textarea
|
|
133
|
+
**Data Display**: Table, Badge, Avatar, Progress, Skeleton
|
|
134
|
+
**Overlays**: Dialog, Sheet, Popover, Tooltip, Dropdown Menu
|
|
135
|
+
**Navigation**: Navigation Menu, Tabs, Breadcrumb, Pagination
|
|
136
|
+
**Feedback**: Alert, Alert Dialog, Toast, Command
|
|
137
|
+
|
|
138
|
+
Plus complete **Blocks** like:
|
|
139
|
+
- Authentication forms
|
|
140
|
+
- Dashboard layouts
|
|
141
|
+
- Calendar interfaces
|
|
142
|
+
- Sidebar navigation
|
|
143
|
+
- E-commerce components
|
|
144
|
+
|
|
145
|
+
## Customization Approach
|
|
146
|
+
|
|
147
|
+
### Theme-Level Customization
|
|
148
|
+
Modify CSS variables in `globals.css`:
|
|
149
|
+
```css
|
|
150
|
+
:root {
|
|
151
|
+
--primary: 221.2 83.2% 53.3%;
|
|
152
|
+
--secondary: 210 40% 96.1%;
|
|
153
|
+
/* ... */
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Component-Level Customization
|
|
158
|
+
Components use `class-variance-authority` for variants:
|
|
159
|
+
```typescript
|
|
160
|
+
const buttonVariants = cva(
|
|
161
|
+
"base-classes",
|
|
162
|
+
{
|
|
163
|
+
variants: {
|
|
164
|
+
variant: { default: "...", destructive: "..." },
|
|
165
|
+
size: { default: "...", sm: "..." },
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Composition
|
|
172
|
+
Create higher-level components:
|
|
173
|
+
```typescript
|
|
174
|
+
// Compose existing components
|
|
175
|
+
export function FeatureCard({ title, description, icon }) {
|
|
176
|
+
return (
|
|
177
|
+
<Card>
|
|
178
|
+
<CardHeader>
|
|
179
|
+
{icon}
|
|
180
|
+
<CardTitle>{title}</CardTitle>
|
|
181
|
+
</CardHeader>
|
|
182
|
+
<CardContent>
|
|
183
|
+
<p>{description}</p>
|
|
184
|
+
</CardContent>
|
|
185
|
+
</Card>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Integration with MCP Tools
|
|
191
|
+
|
|
192
|
+
This skill leverages shadcn MCP server capabilities:
|
|
193
|
+
|
|
194
|
+
- `list_components` - Browse component catalog
|
|
195
|
+
- `get_component` - Retrieve component source
|
|
196
|
+
- `get_component_metadata` - View props and dependencies
|
|
197
|
+
- `get_component_demo` - See usage examples
|
|
198
|
+
- `list_blocks` - Browse UI blocks
|
|
199
|
+
- `get_block` - Retrieve block source with all files
|
|
200
|
+
- `search_items_in_registries` - Find components in custom registries
|
|
201
|
+
|
|
202
|
+
## Best Practices
|
|
203
|
+
|
|
204
|
+
1. **Keep `ui/` pure**: Don't modify components in `components/ui/` directly
|
|
205
|
+
2. **Compose, don't fork**: Create wrapper components instead of editing originals
|
|
206
|
+
3. **Use the CLI**: Let `shadcn add` handle dependencies and updates
|
|
207
|
+
4. **Maintain consistency**: Use the `cn()` utility for all class merging
|
|
208
|
+
5. **Respect accessibility**: Preserve ARIA attributes and keyboard handlers
|
|
209
|
+
6. **Test responsiveness**: shadcn components are responsive by default—keep it that way
|
|
210
|
+
|
|
211
|
+
## Troubleshooting
|
|
212
|
+
|
|
213
|
+
### "Module not found" errors
|
|
214
|
+
Check your `tsconfig.json` includes path aliases:
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"compilerOptions": {
|
|
218
|
+
"paths": {
|
|
219
|
+
"@/*": ["./src/*"]
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Styles not applying
|
|
226
|
+
- Import `globals.css` in your root layout
|
|
227
|
+
- Verify Tailwind config includes component paths
|
|
228
|
+
- Check CSS variable definitions match component expectations
|
|
229
|
+
|
|
230
|
+
### TypeScript errors
|
|
231
|
+
- Ensure all Radix UI peer dependencies are installed
|
|
232
|
+
- Run `npm install` after adding components via CLI
|
|
233
|
+
- Check that React types are up to date
|
|
234
|
+
|
|
235
|
+
## Further Reading
|
|
236
|
+
|
|
237
|
+
- [Official Documentation](https://ui.shadcn.com)
|
|
238
|
+
- [Component Source](https://github.com/shadcn-ui/ui)
|
|
239
|
+
- [Radix UI Docs](https://www.radix-ui.com)
|
|
240
|
+
- [Tailwind CSS Docs](https://tailwindcss.com)
|
|
241
|
+
|
|
242
|
+
## Contributing
|
|
243
|
+
|
|
244
|
+
Contributions to improve this skill are welcome! See the root [CONTRIBUTING.md](../../CONTRIBUTING.md) for guidelines.
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
See [LICENSE](../../LICENSE) in the repository root.
|