#Why does `revalidateTag` work on local build but not in Digital Ocean App Platform?

12 messages · Page 1 of 1 (latest)

plucky lintel
#

Code: Link

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}
GitHub

Contribute to JGallardo4/jose-website development by creating an account on GitHub.

true roverBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
plucky lintel
#

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',
    });
true roverBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer
wooden yoke
#

Same here. For me, it works in local build but not in vercel.

wooden yoke
charred parrot
#

but there's no point in revalidating if you set no-store there

plucky lintel
#

That's right. I wanted to avoid fetching data from the client, but couldn't get incremental regeneration to work...

wooden yoke
plucky lintel
plucky lintel
#

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' }
});
charred parrot