To answer your question about why the component is making an API call on every visit instead of caching the result after a single fetch, we need to look at the data fetching behavior in Next.js 13 and later versions.
According to the Next.js documentation on Data Fetching (https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#fetch), the default behavior of fetch in Next.js 13 and later has changed:
"Data returned from fetch is not automatically cached in the Data Cache. The default caching behavior of fetch (e.g., when the cache option is not specified) is equal to setting the cache option to no-store"
This means that unless you explicitly set caching options, your fetchCollectionSingleItemByQuery function (which likely uses fetch under the hood) will make a new API call on every request.
To cache the result, you would need to add caching options to your fetch call. For example:
const pagesYear = await fetchCollectionSingleItemByQuery({
collectionSlug: "years",
itemQuery: { year: { equals: year } },
cache: 'force-cache'
});
However, it's important to note that even with caching, the dynamic nature of the route (using [year]) means that the page will still be dynamically rendered unless you use generateStaticParams to prerender specific years.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: