Why does `revalidateTag` work on local build but not in Digital Ocean App Platform?
Answered
Manx posted this in #help-forum
ManxOP
Code: [Link](https://github.com/JGallardo4/jose-website/)
Output is as expected but the page only actually updates after two refreshes on the local build on my PC, and never on the hosted site.
src > app > api > revalidate > route.tsx
src > app > lib > cms.tsx
Console:
Output is as expected but the page only actually updates after two refreshes on the local build on my PC, and never on the hosted site.
src > app > api > revalidate > route.tsx
import { NextRequest, NextResponse } from 'next/server'
import { revalidateTag } from 'next/cache'
export async function GET(request: NextRequest) {
const tag = request.nextUrl.searchParams.get('tag')
revalidateTag(tag ?? "revalidate")
return NextResponse.json({ revalidated: true, now: Date.now() })
}src > app > lib > cms.tsx
import type { PortfolioItem, SocialMediaLink } from '@/lib/types.d'
import 'server-only'
const baseUrl = process.env.CMS_API_URL
export const getAllPortfolioEntries = async () => {
try {
const response = await fetch(baseUrl + 'portfolio-entries?populate=*', { next: { tags: ['revalidate'] } });
if (!response.ok) {
throw new Error(response.statusText)
}
const entries = await response.json()
if (entries === null) {
throw new Error('No entries found')
}
return entries.data as PortfolioItem[]
} catch (error) {
console.error(error)
}
}Console:
$ curl https://domain/api/revalidate?tag=revalidate
> {"revalidated":true,"now":16867717638}$ curl https://localhost:30000/api/revalidate?tag=revalidate
> {"revalidated":true,"now":16867717638}Answered by Manx
I got it working by adding
cache: no-store to the fetch requests:const response = await fetch(baseUrl + 'portfolio-entries?populate=*', {
next: { tags: ['revalidate'] },
cache: 'no-store',
});9 Replies
ManxOP
I got it working by adding
cache: no-store to the fetch requests:const response = await fetch(baseUrl + 'portfolio-entries?populate=*', {
next: { tags: ['revalidate'] },
cache: 'no-store',
});Answer
Carolina Dog
Same here. For me, it works in local build but not in vercel.
@Manx I got it working by adding `cache: no-store` to the fetch requests:
const response = await fetch(baseUrl + 'portfolio-entries?populate=*', {
next: { tags: ['revalidate'] },
cache: 'no-store',
});
Carolina Dog
But doing this is bad, isn't it? It will disable the deduplicate caching and trigger multiple fetch on multiple components/pages?
but there's no point in revalidating if you set no-store there
ManxOP
That's right. I wanted to avoid fetching data from the client, but couldn't get incremental regeneration to work...
Original message was deleted
ManxOP
This is what I meant to say too, my bad
ManxOP
I got the answer from the Digital Ocean help forum:
const response = await fetch(baseUrl + 'portfolio-entries?populate=*', {
next: { tags: ['revalidate'] },
headers: { 'Cache-Control': 'no-store' }
});@Manx I got the answer from the Digital Ocean help forum:
const response = await fetch(baseUrl + 'portfolio-entries?populate=*', {
next: { tags: ['revalidate'] },
headers: { 'Cache-Control': 'no-store' }
});
It will probably work that for each user request, the server will send a query to the api.