#Error: Route /[lang] used "revalidateTag global:home-page" during render which is unsupported.

6 messages · Page 1 of 1 (latest)

honest solstice
#

I have a seed script that creates a bunch of data on init. Most of my globals/collections have hooks that use revalidateTag() from Next.js. Doing this in seeding causes Error: Route /[lang] used "revalidateTag global:home-page" during render which is unsupported.

Is there a nice way to solve this / don't revalidate if the hook was fired because of a seed script?
I'd rather avoid adding an API route.

Apparently this might also happen with scheduled publish?

honest solstice
#

Seed script can likely be solved like this, but I'd still like scheduled publish to revalidate

// In my seed script:
const req: Partial<PayloadRequest> = {
    transactionID,
    context: {
        source: 'seed-script',
    },
};

// In my afterChange hooks:
// if (source === 'seed-script') do not revalidate
honest solstice
#

I ended up with a mix of the two, calling the API route at the end of my seed script and in my schedueld publish tesk

export async function GET(req: NextRequest): Promise<Response> {
    ...

    const tagsToRevalidate = req.nextUrl.searchParams.get('tags');
    if (tagsToRevalidate) {
        const tags = tagsToRevalidate.split(',');
        tags.forEach(revalidateTag);
        return new Response(`Revalidation triggered for tags: "${tags.join('", "')}"`);
    }

    revalidatePath('/', 'layout');
    return new Response('Total revalidation triggered');
}
sour bladeBOT
mellow lava
#

Hello @honest solstice !
That's a big paint point for me because I'm developing a plugin for automating tags revalidation (payload-revalidate)

There are multiple cases where payload triggers hooks during a page rendering process, for example when creating a new document with draft+livePreview features activated.

The best solution I could find for now was to wrap the revalidateTag call in a after function. That will handle it oustide the page rendering process, but you won't be able to wait for the result (if you're doing something else after revalidateTag)

Hope that helps