diff --git a/frontend/starters/development/app/api/revalidate/route.ts b/frontend/starters/development/app/api/revalidate/route.ts index b06a2de..391416d 100644 --- a/frontend/starters/development/app/api/revalidate/route.ts +++ b/frontend/starters/development/app/api/revalidate/route.ts @@ -17,7 +17,7 @@ async function handler(request: NextRequest) { } try { - revalidatePath(path, "layout") + revalidatePath(path) return new Response("Revalidated.") } catch (error) { diff --git a/frontend/starters/development/app/edit/[...puckPath]/client.tsx b/frontend/starters/development/app/edit/[...puckPath]/client.tsx index bd00a1c..a9b337a 100644 --- a/frontend/starters/development/app/edit/[...puckPath]/client.tsx +++ b/frontend/starters/development/app/edit/[...puckPath]/client.tsx @@ -5,11 +5,9 @@ import config from "../../../puck.config" import { drupal } from "@/lib/drupal" import { drupalFieldPrefix } from "@powerstack/utils" import { toast } from "sonner" -import { useRouter } from "next/navigation" import { triggerRevalidation } from "@/lib/trigger-revalidation" export function Client({ path, data }: { path: string; data: Data }) { - const router = useRouter() return ( router.push(path), + onClick: () => window.location.href = path, }, - duration: 5000, + duration: 10000, }) } catch (error) { console.error("Error processing page:", error) diff --git a/frontend/starters/development/lib/trigger-revalidation.ts b/frontend/starters/development/lib/trigger-revalidation.ts index ff8fcde..1f0a4ab 100644 --- a/frontend/starters/development/lib/trigger-revalidation.ts +++ b/frontend/starters/development/lib/trigger-revalidation.ts @@ -1,35 +1,21 @@ "use server" +import { revalidatePath } from 'next/cache'; + export const triggerRevalidation = async (path) => { - const secret = process.env.NEXT_REVALIDATE_SECRET - const baseUrl = process.env.NEXT_HOST // This should ideally be kept secure - const revalidateUrl = `${baseUrl}/api/revalidate?path=${path}&secret=${secret}` + const revalidateUrl = `/${path}`; + const revalidateEditUrl = `/edit/[...puckPath]`; try { - const response = await fetch(revalidateUrl, { - method: "GET", - }) - const result = await response - if (result.ok) { - console.log("Page revalidated successfully") - } else { - console.error("Failed to revalidate") - } - } catch (error) { - console.error("Error triggering revalidation:", error) - } - const revalidateEditUrl = `${baseUrl}/api/revalidate?path=/edit/[...puckPath]/page&secret=${secret}` - try { - const response = await fetch(revalidateEditUrl, { - method: "GET", - }) - const result = await response - if (result.ok) { - console.log("Edit page revalidated successfully") - } else { - console.error("Failed to revalidate") - } + await revalidatePath(revalidateUrl, 'page'); // Assuming revalidatePath is an async operation + console.log("Page revalidated"); + + await revalidatePath(revalidateEditUrl, 'page'); + console.log("Edit page revalidated"); + + return "Both pages revalidated successfully"; // Resolving the promise with a success message } catch (error) { - console.error("Error triggering revalidation:", error) + console.error("Error triggering revalidation:", error); + throw error; // Rejecting the promise with the caught error } -} +}; \ No newline at end of file