Next.js Discord

Discord Forum

Route /dashboard used "revalidatePath /dashboard" during render which is unsupported

Unanswered
Gharial posted this in #help-forum
Open in Discord
GharialOP
Im using client function to force server revalidatePath. Randomly client gets error and in server console i have this error
Route /dashboard used "revalidatePath /dashboard" during render which is unsupported

Is there any other way to force data revalidation?

 async function changeCheck() {
    "use server";
    const newRevenueDay = await getRevenueDay();
    const encodedNewRevenueDay = Buffer.from(JSON.stringify(newRevenueDay)).toString("base64");
    const didChange = encodedNewRevenueDay !== encodedRevenueDay;
    if (didChange) {
      revalidatePath("/dashboard");
      console.log("didChange", didChange);
    } else {
      console.log("didnt change")
    }
  }

"use client";

import {useInterval} from "interval-hooks";
import {useEffect, useState} from "react";

export function RefreshCache({check}: {check: () => Promise<void>}) {
  const [shouldRun, setShouldRun] = useState(typeof document !== "undefined" && document.visibilityState === "visible");

  useEffect(() => {
    const onVisibilityChange = () => {
      if (document.visibilityState === "visible") {
        check();
        setShouldRun(true);
      } else {
        setShouldRun(false);
      }
    };

    document.addEventListener("visibilitychange", onVisibilityChange);

    return () => {
      document.removeEventListener("visibilitychange", onVisibilityChange);
    };
  }, [check]);

  useInterval(check, shouldRun ? 60000 : null);

  return null;
}

0 Replies