Skip to content

feat: generate cache-life types during next build#90146

Draft
bgub wants to merge 1 commit intovercel:canaryfrom
bgub:feat/cache-life-types-build
Draft

feat: generate cache-life types during next build#90146
bgub wants to merge 1 commit intovercel:canaryfrom
bgub:feat/cache-life-types-build

Conversation

@bgub
Copy link
Contributor

@bgub bgub commented Feb 18, 2026

Summary

  • Calls writeCacheLifeTypesFile from build/index.ts so production builds emit .next/types/cache-life.d.ts when custom cacheLife profiles are configured
  • Previously this file was only generated during dev (setup-dev-bundler) and via next typegen, leaving a gap for production builds
  • Replaces the magic number 0xfffffffe in cache-life-type-utils.ts with the INFINITE_CACHE constant for consistency

Test plan

  • Unit tests: pnpm test-unit packages/next/src/server/lib/router-utils/cache-life-type-utils.test.ts
  • Verify .next/types/cache-life.d.ts is generated after next build when cacheLife profiles are defined in next.config.js

Previously, custom cacheLife profile types were generated during dev
(setup-dev-bundler) and via `next typegen`, but not during `next build`.
This adds the missing call so production builds also emit
`.next/types/cache-life.d.ts` when cacheLife profiles are configured.

Also replaces the magic number 0xfffffffe with the INFINITE_CACHE constant
in cache-life-type-utils.ts for consistency with the rest of the codebase.
Copilot AI review requested due to automatic review settings February 18, 2026 16:55
@nextjs-bot
Copy link
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: db39542

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a gap in type generation by ensuring that cache-life type definitions are generated during production builds, not just in development mode and via the next typegen command. It also improves code maintainability by replacing a magic number with a named constant.

Changes:

  • Added cache-life type generation to production builds in build/index.ts
  • Replaced magic number 0xfffffffe with INFINITE_CACHE constant across multiple comparisons in cache-life-type-utils.ts
  • Added cacheLifeConfig field to RouteTypesManifest interface and a wrapper function writeCacheLifeTypesFile in route-types-utils.ts

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/next/src/build/index.ts Generates cache-life.d.ts during production builds when cacheLife profiles are configured
packages/next/src/server/lib/router-utils/route-types-utils.ts Adds cacheLifeConfig field to manifest interface and wrapper function for writing cache-life types
packages/next/src/server/lib/router-utils/cache-life-type-utils.ts Replaces magic number with INFINITE_CACHE constant for better code clarity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +453 to +458
export async function writeCacheLifeTypesFile(
manifest: RouteTypesManifest,
filePath: string
) {
writeCacheLifeTypes(manifest.cacheLifeConfig, filePath)
}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The writeCacheLifeTypesFile function is declared as async but does not await anything. The underlying writeCacheLifeTypes function uses synchronous file operations (fs.writeFileSync). This creates an inconsistency with other similar functions in this file like writeRouteTypesManifest and writeValidatorFile which use fs.promises.writeFile and are truly async.

Either:

  1. Remove the async keyword from writeCacheLifeTypesFile (and remove await when calling it in build/index.ts), OR
  2. Update writeCacheLifeTypes in cache-life-type-utils.ts to use async file operations and await it here

Option 2 would be more consistent with the other write functions in this file.

Copilot uses AI. Check for mistakes.
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't that going through the same codepaths as next typegen

@bgub bgub marked this pull request as draft February 18, 2026 18:38
@bgub
Copy link
Contributor Author

bgub commented Feb 18, 2026

@eps1lon sorry, will address that. I meant but forgot to switch the PR to a draft -- it's not quite ready for review yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments