Skip to content

Commit c00b2fc

Browse files
committed
fix identical path handling
1 parent 94a6b55 commit c00b2fc

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

apps/app/src/pages/[[...path]]/index.page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
111111
const pageMeta = isInitialProps(props) ? props.pageWithMeta?.meta : undefined;
112112

113113
useHydratePageAtoms(pageData, pageMeta, {
114-
redirectFrom: props.redirectFrom ?? undefined,
114+
redirectFrom: props.redirectFrom,
115+
isIdenticalPath: props.isIdenticalPathPage,
115116
templateTags: props.templateTagData,
116117
templateBody: props.templateBodyData,
117118
});

apps/app/src/pages/[[...path]]/use-same-route-navigation.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react';
22
import { useRouter } from 'next/router';
33

4-
import { useFetchCurrentPage } from '~/states/page';
4+
import { useFetchCurrentPage, useIsIdenticalPath } from '~/states/page';
55
import { useSetEditingMarkdown } from '~/states/ui/editor';
66

77
/**
@@ -12,17 +12,22 @@ import { useSetEditingMarkdown } from '~/states/ui/editor';
1212
*/
1313
export const useSameRouteNavigation = (): void => {
1414
const router = useRouter();
15+
16+
const isIdenticalPath = useIsIdenticalPath();
1517
const { fetchCurrentPage } = useFetchCurrentPage();
1618
const setEditingMarkdown = useSetEditingMarkdown();
1719

1820
// useEffect to trigger data fetching when the path changes
1921
useEffect(() => {
22+
// If the path is identical, do not fetch
23+
if (isIdenticalPath) return;
24+
2025
const fetch = async () => {
2126
const pageData = await fetchCurrentPage({ path: router.asPath });
2227
if (pageData?.revision?.body != null) {
2328
setEditingMarkdown(pageData.revision.body);
2429
}
2530
};
2631
fetch();
27-
}, [router.asPath, fetchCurrentPage, setEditingMarkdown]);
32+
}, [router.asPath, isIdenticalPath, fetchCurrentPage, setEditingMarkdown]);
2833
};

apps/app/src/states/page/hydrate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
currentPageDataAtom,
1212
currentPageIdAtom,
1313
isForbiddenAtom,
14+
isIdenticalPathAtom,
1415
pageNotFoundAtom,
1516
redirectFromAtom,
1617
remoteRevisionBodyAtom,
@@ -50,6 +51,7 @@ export const useHydratePageAtoms = (
5051
redirectFrom?: string;
5152
templateTags?: string[];
5253
templateBody?: string;
54+
isIdenticalPath?: boolean;
5355
},
5456
): void => {
5557
useHydrateAtoms([
@@ -78,6 +80,7 @@ export const useHydratePageAtoms = (
7880
[shareLinkIdAtom, options?.shareLinkId],
7981

8082
[redirectFromAtom, options?.redirectFrom ?? undefined],
83+
[isIdenticalPathAtom, options?.isIdenticalPath ?? false],
8184

8285
// Template data - from options (not auto-extracted from page)
8386
[templateTagsAtom, options?.templateTags ?? []],

0 commit comments

Comments
 (0)