|
@@ -54,11 +54,11 @@ export const useTemplateBodyData = (initialData?: string): SWRResponse<string, E
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/** "useSWRxCurrentPage" is intended for initial data retrieval only. Use "useSWRMUTxCurrentPage" for revalidation */
|
|
/** "useSWRxCurrentPage" is intended for initial data retrieval only. Use "useSWRMUTxCurrentPage" for revalidation */
|
|
|
-export const useSWRxCurrentPage = (
|
|
|
|
|
- initialData?: IPagePopulatedToShowRevision|null, isPastRevisionSelected = false,
|
|
|
|
|
-): SWRResponse<IPagePopulatedToShowRevision|null> => {
|
|
|
|
|
|
|
+export const useSWRxCurrentPage = (initialData?: IPagePopulatedToShowRevision|null): SWRResponse<IPagePopulatedToShowRevision|null> => {
|
|
|
const key = 'currentPage';
|
|
const key = 'currentPage';
|
|
|
|
|
|
|
|
|
|
+ const { data: isLatestRevision } = useIsLatestRevision();
|
|
|
|
|
+
|
|
|
const { cache } = useSWRConfig();
|
|
const { cache } = useSWRConfig();
|
|
|
|
|
|
|
|
// Problem 1: https://github.com/weseek/growi/pull/7772/files#diff-4c1708c4f959974166c15435c6b35950ba01bbf35e7e4b8e99efeb125a8000a7
|
|
// Problem 1: https://github.com/weseek/growi/pull/7772/files#diff-4c1708c4f959974166c15435c6b35950ba01bbf35e7e4b8e99efeb125a8000a7
|
|
@@ -83,24 +83,26 @@ export const useSWRxCurrentPage = (
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // // mutate When a different revision is opened
|
|
|
|
|
- // if (cachedData.revision?._id != null && initialData.revision?._id != null && cachedData.revision._id !== initialData.revision._id) {
|
|
|
|
|
- // console.log('initialData', initialData);
|
|
|
|
|
- // return true;
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ // mutate When a different revision is opened
|
|
|
|
|
+ if (!isLatestRevision
|
|
|
|
|
+ && cachedData.revision?._id != null && initialData.revision?._id != null
|
|
|
|
|
+ && cachedData.revision._id !== initialData.revision._id
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return false;
|
|
return false;
|
|
|
})();
|
|
})();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- if (shouldMutate || isPastRevisionSelected) {
|
|
|
|
|
|
|
+ if (shouldMutate) {
|
|
|
mutate(key, initialData, {
|
|
mutate(key, initialData, {
|
|
|
optimisticData: initialData,
|
|
optimisticData: initialData,
|
|
|
populateCache: true,
|
|
populateCache: true,
|
|
|
revalidate: false,
|
|
revalidate: false,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- }, [initialData, isPastRevisionSelected, key, shouldMutate]);
|
|
|
|
|
|
|
+ }, [initialData, key, shouldMutate]);
|
|
|
|
|
|
|
|
return useSWR(key, null, {
|
|
return useSWR(key, null, {
|
|
|
keepPreviousData: true,
|
|
keepPreviousData: true,
|