N

Next/15/Update-Route-Handlers

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

Update Route Handlers to Handle Caching

This codemod refactors Route Handlers to manage caching behavior for GET functions. By default, GET methods are no longer cached. This codemod updates your Route Handler files to use the dynamic configuration option to opt specific routes into caching.

  • Find Route Handlers: Identifies GET functions in the Route Handler files.

  • Property Check: Ensures the presence of GET functions and adds the dynamic configuration option if necessary.

  • Add Caching Configuration: Adds export const dynamic = 'force-static' to enable caching for GET methods.

  • Clean Up: Removes the experimental object if it becomes empty after the migration.

Before

js

After

js

Ready to contribute?

Build your own codemod and share it with the community.