Configure staleTimes in next.config.js for next15 #1301
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 the next.config.js file to introduce the staleTimes configuration option, allowing you to control cache durations for different types of page segments. By specifying cache durations for dynamic and static pages, this codemod enhances caching behavior and improves application performance.
1.Find Configuration Object: Identifies the nextConfig object within the next.config.js file.
2.Add staleTimes Property: Adds the staleTimes property to the experimental object to define cache durations.
3. Specify Cache Durations: Sets cache durations for dynamic and static pages in seconds.
4. Clean Up: Removes the experimental object if it becomes empty after adding the staleTimes property.
To run this codemod, run the following command in the project directory:
codemod Next/15/Add-Experimental-Stale-Times
🧪 Test Plan
Test the codemod by applying it to a specified repository to ensure that the next.config.js file is correctly updated with the staleTimes configuration. Verify that the cache durations for dynamic and static pages are properly set and that the application behaves as expected with the new caching settings.
Apply the codemod to the repository available at (https://github.com/OlegJytnik/JSSNextJSDemo).
Confirm that the staleTimes property is correctly added to the experimental object in next.config.js
Test the application to ensure it functions correctly with the updated cache duration settings.
All other test cases are run in the codemod studio and are present in /codemod/packages/codemods/next/15/configure-staletimes/textfix
📄 Documentation to Update