import { useRouter, useSearchParams } from "next/navigation"; import { useEffect } from "react"; import uuid from "react-uuid"; declare global { interface Window { requestRefresh?: (newUri?: string) => boolean; } } const useExposeRefreshFunction = () => { const router = useRouter(); const searchParams = useSearchParams(); useEffect(() => { // Expose the refresh function to the parent window window.requestRefresh = (newUri?: string) => { if (!newUri) { const uri = new URL(window.location.href); uri.searchParams.set("edit_rev", uuid().toString()); newUri = uri.toString(); } router.replace(newUri, { scroll: false }); return true; // Indicate the function executed successfully }; // Optionally clean up when the component unmounts return () => { delete window.requestRefresh; }; }, [router]); useEffect(() => { // Refresh tracking logic (debug logging removed) }, [searchParams]); return null; // This hook doesn't render anything }; export default useExposeRefreshFunction;