Skip to content

codemod: cache-components-instant-false + next-cache-components-adoption skill#94941

Merged
aurorascharff merged 53 commits into
canaryfrom
codex/cache-components-instant-false-codemod
Jun 22, 2026
Merged

codemod: cache-components-instant-false + next-cache-components-adoption skill#94941
aurorascharff merged 53 commits into
canaryfrom
codex/cache-components-instant-false-codemod

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Why?

Turning on cacheComponents makes every blocking route a build error at once. On a large app that's a wall of failures with no clear order to fix them in, which is a rough first experience.

What?

An opt-in adoption path so enabling Cache Components doesn't have to be all-or-nothing:

  • cache-components-instant-false codemod (@next/codemod) — blanket-inserts export const instant = false (with a // TODO: Cache Components adoption comment) into every app/**/{page,layout} file, so the build goes green immediately. Idempotent: skips files that already export instant (including aliased export { x as instant }). Skips Client Components ("use client") and route handlers.
  • next-cache-components-adoption skill (skills/) — sequences the full migration in five steps across four milestones: green build (codemod or direct), remove the opt-outs top-down one group at a time, make navigations instant via the dev-overlay Insights, then adopt Partial Prefetching. It defers individual fixes to the dev overlay fix cards, stack traces, and the /docs/messages/blocking-prerender-* pages, and points at the migration / instant-navigation / Partial Prefetching guides rather than re-teaching them. Verifies each change at runtime via next-dev-loop (with a manual dev-overlay fallback). The next-cache-components-optimizer skill is referenced only as optional shell-growing polish after adoption is complete.

How?

  • Transform registered in TRANSFORMER_INQUIRER_CHOICES at version: '16.3.0'.
  • 8 fixtures cover insert-into-page / -layout, JSDoc placement, and no-op on existing / aliased / multi-declarator / local-binding instant and on "use client" pages. pnpm jest cache-components-instant-false passes.
  • Docs: a cache-components-instant-false entry in the codemods reference, and a pointer to the skill + codemod from the migration guide.
@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: 5616f68
View workflow run

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 5616f68

Comment thread packages/next-codemod/transforms/cache-components-instant-false.ts Outdated
Comment thread skills/next-cache-components-adoption/SKILL.md Outdated
@aurorascharff aurorascharff changed the title codemod: cache-components-instant-false + adoption skill Jun 20, 2026
@CreativeCodingSolutions

Copy link
Copy Markdown

PR Quality Score: A (81%) 🎉

I ran this PR through the PR Quality Analyzer — a free tool that checks description quality, labels, size, title, and more. Nice work on this codemod!

PR Quality: A (81%)

Pro tip: You can add a badge like this to your README to show PR quality at a glance.

Comment thread docs/01-app/02-guides/upgrading/codemods.mdx Outdated
Comment thread docs/01-app/02-guides/migrating-to-cache-components.mdx Outdated
Comment thread packages/next-codemod/transforms/cache-components-instant-false.ts Outdated
The previous version used raw text insertion with manual byte-offset math, which mishandled three fixtures on the Windows CI runners. Rewrite using the same shape as other codemods: build the export declaration as an AST node, attach the TODO + See: leading comments, splice it into program.body after the last import, and return root.toSource(). Recast handles the printing details (blank lines, comment placement, line endings) so we no longer need the CRLF normalization layer.
When the target file has no imports and body[0] carries a leading comment block (like `// @ts-nocheck` or a JSDoc banner), inserting the new export at index 0 would let recast steal those comments onto our node. Move the leading comments off body[0] onto the inserted export before its TODO/See: lines so they print in their original position. Also avoid an `alex` lint warning by replacing 'not just' with 'not only'.
@aurorascharff aurorascharff merged commit ae62a6f into canary Jun 22, 2026
128 of 129 checks passed
@aurorascharff aurorascharff deleted the codex/cache-components-instant-false-codemod branch June 22, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants