Skip to content

Commit f9da965

Browse files
authored
improve verify strategy (#33)
1 parent f2227b5 commit f9da965

File tree

1 file changed

+126
-11
lines changed

1 file changed

+126
-11
lines changed

src/mcp-prompts/enable-cache-components-prompt.md

Lines changed: 126 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,18 @@ This prompt automates the complete Cache Components enablement workflow:
137137
- ✅ Verify MCP server is active and responding
138138
- ✅ Capture base URL and MCP endpoint for error detection
139139

140-
**Error Detection (Phase 4):**
140+
**Error Detection (Phase 4 - Optional):**
141141
- ✅ Start Playwright browser and load every route using playwright tool
142142
- ✅ Collect errors from browser session using Next.js MCP `get_errors` tool
143143
- ✅ Categorize all Cache Components errors by type
144144
- ✅ Build comprehensive error list before fixing
145+
- ℹ️ Phase 4 can be skipped if proceeding directly to Phase 5 build-first approach
145146

146-
**Automated Fixing (Phase 5):**
147+
**Automated Fixing (Phase 5 - Build-First Strategy):**
148+
- ✅ Run `<pkg-manager> run build` to identify all failing routes at once
149+
- ✅ Get explicit error messages for every issue in build output
150+
- ✅ Fix errors directly based on clear error messages from build
151+
- ✅ Or verify in dev server with `next dev` for interactive fixing with Fast Refresh
147152
- ✅ Fix blocking route errors (add Suspense boundaries or "use cache")
148153
- ✅ Fix dynamic value errors (add `await connection()`)
149154
- ✅ Fix route params errors (add `generateStaticParams`)
@@ -663,6 +668,11 @@ These options will cause build errors and MUST be migrated:
663668
- `revalidate: 3600` → Use `cacheLife({ revalidate: 3600 })`
664669
- `fetchCache: 'force-cache'` → Use `"use cache"`
665670

671+
**Important:** When removing `export const dynamic`, replace it with a comment documenting the original static/dynamic mode:
672+
- `export const dynamic = 'force-static'` → Replace with: `// MIGRATED: Was force-static mode - now using "use cache"`
673+
- `export const dynamic = 'force-dynamic'` → Replace with: `// MIGRATED: Was force-dynamic mode - now using <Suspense>`
674+
- This preserves the original mode information for later verification
675+
666676
Document all Route Segment Config locations now - you'll migrate them in Phase 5.
667677

668678
**Step 6: Verify configuration changes**
@@ -679,10 +689,12 @@ After making changes, verify by reading the config file:
679689
**What's Next:**
680690
With configuration updated, Phase 3 will start the dev server and Phase 4 will detect any runtime errors that need fixing.
681691

682-
## PHASE 3: Start Dev Server with MCP
692+
## PHASE 3: Start Dev Server with MCP (Optional)
683693
────────────────────────────────────────
684694

685-
**IMPORTANT: Only start the dev server ONCE. Do NOT restart it during this process.**
695+
**IMPORTANT: This phase is optional.** You can skip directly to Phase 5 (build-first approach) if you prefer to identify all errors upfront from the build output.
696+
697+
**If using Phase 3/Phase 4 workflow:** Only start the dev server ONCE. Do NOT restart it during this process.
686698

687699
### Step 1: Start Dev Server (ONE TIME ONLY)
688700

@@ -962,10 +974,38 @@ Systematically verify each route and collect errors:
962974
────────────────────────────────────────
963975

964976
**Prerequisites:**
965-
- ✅ Dev server is still running from Phase 3 (do NOT restart it)
966977
- ✅ Comprehensive error list collected from Phase 4
967978
- ✅ Fast Refresh will apply changes automatically (no restart needed)
968979

980+
**NEW STRATEGY: Build-First Approach**
981+
982+
This phase uses an optimized two-step verification strategy:
983+
984+
**Step 1: Run Full Build to Identify All Failing Routes**
985+
```bash
986+
<pkg-manager> run build
987+
```
988+
989+
This build identifies all routes with Cache Components errors at once, giving you a comprehensive view of what needs to be fixed:
990+
- Build output shows all failing routes
991+
- Error messages are explicit and clear
992+
- All missing Suspense boundaries/cache directives are identified
993+
- Stack traces point to exact locations needing fixes
994+
995+
**Step 2: Use Dev Server for Interactive Verification & Fixing**
996+
```bash
997+
# Dev server may already be running from Phase 3
998+
# If not, start it:
999+
__NEXT_EXPERIMENTAL_MCP_SERVER=true <pkg-manager> dev
1000+
```
1001+
1002+
For each failing route:
1003+
1. **If error is explicit from build logs:** Fix directly based on the error message
1004+
2. **If error needs verification:** Start dev server, test the route, and fix interactively with Fast Refresh
1005+
3. **Re-verify:** After fixing, either:
1006+
- Run build again to check that route
1007+
- Test in dev to verify with Fast Refresh
1008+
9691009
**⚠️ MANDATORY: Load error-specific resources BEFORE fixing any errors**
9701010

9711011
You MUST load these resources to fix errors correctly:
@@ -1032,7 +1072,11 @@ For detailed code examples and patterns for each error type, refer to the knowle
10321072
- B. Dynamic values → Use connection() or extract to separate component
10331073
- C. Route params → Add generateStaticParams
10341074
- D. Unavailable APIs in cache → Move outside cache scope or use "use cache: private"
1035-
- E. Route Segment Config → Migrate to "use cache" + cacheLife
1075+
- E. Route Segment Config → Migrate to "use cache" + cacheLife with documentation
1076+
- **When removing `export const dynamic`:** Replace with a comment documenting the original mode for later verification
1077+
- Example: If removing `export const dynamic = 'force-static'`, add comment: `// MIGRATED: Was force-static mode - now using "use cache"`
1078+
- Example: If removing `export const dynamic = 'force-dynamic'`, add comment: `// MIGRATED: Was force-dynamic mode - now using <Suspense>`
1079+
- This helps track what the original static/dynamic mode was for verification purposes
10361080
- F. Caching strategies → Configure cacheLife() and cacheTag()
10371081

10381082
**After Each Fix:**
@@ -1068,14 +1112,72 @@ For detailed code examples and patterns for each error type, refer to the knowle
10681112
- ✅ Content displays correctly
10691113
- ✅ Performance is acceptable
10701114

1115+
**Handling Unclear Cases That Can't Be Resolved:**
1116+
1117+
If after multiple attempts a fix continues to fail or the issue is unclear, leave a comment documenting the problem:
1118+
1119+
```typescript
1120+
// ⚠️ UNRESOLVED: Unable to determine caching strategy for this component
1121+
// Issue: Third-party component [ComponentName] from [package] - internal implementation unclear
1122+
// Error: [specific error that persists]
1123+
// Recommendation: Review third-party documentation or consider alternative approach
1124+
// TODO: Revisit this when [condition - e.g., package updates, documentation available]
1125+
```
1126+
1127+
**Common Unclear Cases:**
1128+
- Third-party components with unknown/complex internal state management
1129+
- Components using undocumented async patterns
1130+
- External library integrations with unclear rendering behavior
1131+
- Timing-dependent code that behaves differently in cache vs runtime
1132+
1133+
**When to Leave This Comment:**
1134+
1. You've tried multiple caching strategies (cache, Suspense, private cache)
1135+
2. All attempts result in the same error or unexpected behavior
1136+
3. The root cause is unclear (third-party code, complex state, etc.)
1137+
4. You've verified the error isn't due to missing Suspense/cache directives
1138+
5. The component works but you can't determine the appropriate caching mode
1139+
1140+
**Example Scenarios:**
1141+
```typescript
1142+
// ⚠️ UNRESOLVED: Cannot determine caching strategy for PaymentGateway
1143+
// Issue: Third-party payment component uses internal async provider pattern
1144+
// Error: Blocks route regardless of Suspense boundary placement
1145+
// Recommendation: Check payment provider's Cache Components compatibility docs
1146+
// TODO: Revisit after upgrading to payment SDK v3.0+
1147+
1148+
// ⚠️ UNRESOLVED: Analytics dashboard component timing issue
1149+
// Issue: Component works in dev but different behavior in build prerender
1150+
// Error: Cached value inconsistent between prerender and runtime
1151+
// Recommendation: Investigate hydration mismatch, may need "use cache: private"
1152+
// TODO: Profile in production build to understand timing behavior
1153+
```
1154+
1155+
This allows the codebase to be functional while clearly marking areas needing future investigation.
1156+
10711157
**Continue until:**
10721158
- All routes return 200 OK
10731159
- `get_errors` returns no errors
10741160
- No console warnings related to Cache Components
10751161
- All fixes have explanatory comments
10761162

1163+
**Verification Strategy After All Fixes:**
1164+
1165+
Once all errors are fixed, choose the verification approach based on total route count:
1166+
1167+
**If total routes < 8 (Small Project):**
1168+
- ✅ Use `<pkg-manager> run build` to verify all fixes
1169+
- Build verification is comprehensive and efficient for small projects
1170+
- Provides detailed error output if any issues remain
1171+
- Skips dev server verification (faster, no Fast Refresh needed)
1172+
1173+
**If total routes >= 8 (Larger Project):**
1174+
- ✅ Use dev server with `next dev` and Fast Refresh for interactive verification
1175+
- Faster feedback during fixing iterations
1176+
- Better for testing dynamic content behavior
1177+
- Can verify routes progressively without full build
1178+
10771179
**Important:**
1078-
- The dev server should REMAIN RUNNING throughout all fixes
1180+
- The dev server should REMAIN RUNNING throughout all fixes (if using dev verification)
10791181
- Fast Refresh automatically applies your changes
10801182
- Do NOT restart the server unless it crashes
10811183
- Every fix should include comments explaining the decision
@@ -1113,14 +1215,24 @@ Run comprehensive checks:
11131215
# (You can now safely stop it)
11141216
```
11151217

1116-
3. **Build Test**
1218+
3. **Build Test with Debug Prerender**
11171219
```bash
1220+
# First, attempt with debug-prerender flag if available
1221+
<pkg-manager> run build -- --debug-prerender
1222+
```
1223+
1224+
If `--debug-prerender` is not supported:
1225+
```bash
1226+
# Fallback to standard build
11181227
<pkg-manager> run build
11191228
```
1229+
11201230
Expected:
11211231
- Build succeeds without errors
11221232
- Build output shows cache status for each route
1233+
- With `--debug-prerender`: Detailed prerender diagnostics and cache analysis
11231234
- Check for any build-time errors that didn't appear in dev
1235+
- All routes prerendered or marked as dynamic correctly
11241236

11251237
4. **Dev Mode Test**
11261238
```bash
@@ -1349,9 +1461,12 @@ Cache Components is now fully enabled with:
13491461
Begin Cache Components enablement:
13501462
1. Start with Phase 1 pre-flight checks
13511463
2. Enable Cache Components in config (Phase 2)
1352-
3. Start dev server with MCP (Phase 3) - **START ONLY ONCE, DO NOT RESTART**
1353-
4. Systematically verify each route and collect errors (Phase 4)
1354-
5. Fix all errors automatically (Phase 5)
1464+
3. Start dev server with MCP (Phase 3) - **START ONLY ONCE, DO NOT RESTART** (optional - may not be needed for Phase 5)
1465+
4. Verify routes and collect errors (Phase 4) - **OPTIONAL, can skip and go directly to Phase 5**
1466+
5. Fix all errors using build-first approach (Phase 5):
1467+
- Run `<pkg-manager> run build` to see all errors
1468+
- Fix based on explicit error messages
1469+
- Verify in dev with Fast Refresh if needed
13551470
6. Run final verification (Phase 6)
13561471

13571472
**Critical Rules:**

0 commit comments

Comments
 (0)