vercel-labs/agent-skills / skills/vercel-optimize
vercel-optimize
VerifiedUse for Vercel cost and performance optimization on deployed projects, especially Next.js, SvelteKit, Nuxt, and limited Astro apps. Collect Vercel metrics, usage, project config, and code scan results first; investigate only metric-backed candidates; produce ranked recommendations grounded in verified files and version-aware Vercel/framework docs. Trigger for Vercel bill reduction, slow or expensive routes, caching opportunities, Function Invocations, Build Minutes, Fast Data Transfer, Core Web Vitals, Bot Management, Fluid compute, or cost breakdown requests.
lib/scanners/cache-components-suspense-dedupe.mjs
View on GitHub// Detects the Cache Components anti-pattern where `'use cache'` doesn't dedupe across
// separate `<Suspense>` boundaries — each boundary triggers a separate evaluation of the
// "shared" cached function, multiplying invocations and ISR write pressure.
//
// Simplified single-file heuristic (cross-file segment analysis is out of scope):
// File contains `'use cache'` directive (or `use cache` keyword)
// AND file has 2+ `<Suspense ...>` boundaries
// AND a repeated fetch URL or function call appears in the body.
//
// False positives are tolerable: the support-topic body recommends a known-good remediation
// (hoist promise to page, or move to `'use cache: remote'`) whether or not the specific call
// site is the exact one paying the cost. The verifier abstains when the file structure
// doesn't match the pitfall.
import { lineOf } from '../util.mjs';
export const metadata = {
id: 'cache-components-suspense-dedupe',
title: "'use cache' with multiple Suspense boundaries on the same data",
severity: 'medium',
billingDimension: 'function-duration',
trafficIndependent: false,
description:
"Default `'use cache'` does not dedupe identical calls across separate `<Suspense>` boundaries on the same render. Each boundary re-invokes the cached function, multiplying function-duration cost and inflating ISR write churn when the output is large.",
fix:
"Hoist the promise to the page level (`const dataPromise = fetchData()` at the top, passed down to each Suspense child) OR move the shared fetch into a `'use cache: remote'` data-access layer so cross-request and cross-boundary dedupe applies.",
citations: [
'https://nextjs.org/docs/app/api-reference/directives/use-cache',
'https://nextjs.org/docs/app/api-reference/config/next-config-js/cacheComponents',
'https://nextjs.org/docs/app/guides/migrating-to-cache-components',
],
excludeGlobs: ['node_modules/**', '.next/**', 'dist/**', '__tests__/**', '**/*.test.*', '**/*.spec.*'],
includeGlobs: [
'**/page.{ts,tsx,js,jsx}',
'**/layout.{ts,tsx,js,jsx}',
'**/components/**/*.{tsx,jsx}',
],
};
const USE_CACHE_RE = /^[\t ]*['"]use cache['"]/m;
const SUSPENSE_TAG_RE = /<Suspense\b/g;
const FETCH_LITERAL_RE = /fetch\s*\(\s*(['"`])([^'"`]{6,200})\1/g;
// Helper function calls that look like data-fetchers (lowercase camel, no JSX/HTML noise).
const HELPER_CALL_RE = /\b(get|fetch|load|find|query|read)[A-Z][A-Za-z0-9_]+\s*\(/g;
export function scan({ files }) {
const out = [];
for (const { path, content } of files) {
if (!USE_CACHE_RE.test(content)) continue;
const suspenseCount = countMatches(content, SUSPENSE_TAG_RE);
if (suspenseCount < 2) continue;
const repeated = findRepeated(content);
if (repeated.length === 0) continue;
// Anchor the finding to the first repeated call site so the customer
// can locate the duplicate quickly.
const first = repeated[0];
out.push({
pattern: metadata.id,
file: path,
line: lineOf(content, first.firstIdx),
evidence: first.kind === 'fetch'
? `fetch("${truncate(first.token, 60)}") called ${first.count}× across Suspense boundaries`
: `${first.token}() called ${first.count}× across Suspense boundaries`,
trafficIndependent: metadata.trafficIndependent,
subtype: first.kind === 'fetch' ? 'fetch-literal' : 'helper-call',
});
}
return out;
}
function countMatches(content, re) {
re.lastIndex = 0;
let n = 0;
while (re.exec(content) !== null) n++;
return n;
}
function findRepeated(content) {
const tokens = new Map(); // token -> { kind, count, firstIdx }
let m;
FETCH_LITERAL_RE.lastIndex = 0;
while ((m = FETCH_LITERAL_RE.exec(content)) !== null) {
record(tokens, m[2], 'fetch', m.index);
}
HELPER_CALL_RE.lastIndex = 0;
while ((m = HELPER_CALL_RE.exec(content)) !== null) {
const name = m[0].replace(/\s*\($/, '').trim();
record(tokens, name, 'helper', m.index);
}
return [...tokens.values()]
.filter((t) => t.count >= 2)
.sort((a, b) => b.count - a.count);
}
function record(map, token, kind, idx) {
if (!token) return;
if (!map.has(token)) {
map.set(token, { token, kind, count: 0, firstIdx: idx });
}
map.get(token).count++;
}
function truncate(s, n) {
if (s.length <= n) return s;
return s.slice(0, n - 1) + '…';
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |