next-sanity
Version:
Sanity.io toolkit for Next.js
25 lines (24 loc) • 1.12 kB
JavaScript
"use server";
import { t as parseTags } from "../../parseTags.js";
import { draftMode } from "next/headers";
import { revalidateTag, updateTag } from "next/cache";
/**
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
*/
async function revalidateSyncTagsAction(unsafeTags) {
if ((await draftMode()).isEnabled) {
console.warn(`<SanityLive /> action called in draft mode, cache is bypassed in draft mode so the router.refresh() function is called instead of revalidating tags`);
return "refresh";
}
const { tags } = parseTags(unsafeTags);
if (process.env.NODE_ENV === "development") {
for (const tag of tags) updateTag(tag);
console.log(`<SanityLive /> action called in dev mode, updated tags: ${tags.join(", ")}. In production revalidateTag(tag, 'max') will be used instead of updateTag(tag)`);
return;
}
for (const tag of tags) revalidateTag(tag, "max");
console.log(`<SanityLive /> revalidated tags: ${tags.join(", ")} with cache profile "max" `);
return "refresh";
}
export { revalidateSyncTagsAction };
//# sourceMappingURL=index.js.map