Update Fetch Requests to Handle Caching in Next 15 #1300
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📚 Description
This codemod refactors fetch requests in your code to handle caching according to the new default behaviors in Next.js. By default, fetch requests are no longer cached. This codemod updates fetch requests to include the cache option for specific requests or adds fetchCache to layouts or pages for global caching control.
1.Find Fetch Requests: Identifies fetch requests in the code that require caching adjustments.
2. Property Check: Ensures fetch requests are updated with the appropriate cache option where necessary and adds the fetchCache option for global caching control.
3.Add Caching Configuration: Inserts export const fetchCache = 'default-cache'; in layouts or pages to apply default caching for all fetch requests unless overridden.
4. Clean Up: Removes the experimental object if it is empty after the migration.
To run this codemod, run the following command in the project directory:
codemod Next/15/Update-Fetch-Requests-to-Handle-Caching
🧪 Test Plan
Test the codemod by applying it to a specified repository to ensure fetch requests and layout files are correctly updated for caching behavior. Verify that fetch requests are correctly modified to include the cache option and that global caching settings are applied correctly with export const fetchCache = 'default-cache';.
Apply the codemod to the repository available at (https://github.com/imbhargav5/nextbase-nextjs-supabase-starter) and (https://github.com/nisabmohd/ChatGPT).
Confirm that all fetch requests are updated with appropriate caching options (cache or fetchCache).
Test the application to ensure that it functions correctly with the updated fetch caching settings.
All other test cases are run in the codemod studio and are present in
/codemod/packages/codemods/next/15/fetch-request-caching/textfixtures/
.📄 Documentation to Update