Skip to content

Commit 84fe3c5

Browse files
authored
Merge pull request #10572 from growilabs/fix/175021-editor-cursor-returns-to-the-beginning-when-saving-page-3
fix: Editor cursor returns to the beginning when saving page
2 parents bf4d54f + a7630f2 commit 84fe3c5

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

apps/app/src/client/components/Page/DisplaySwitcher.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import type { JSX } from 'react';
33
import dynamic from 'next/dynamic';
44

55
import { useHashChangedEffect } from '~/client/services/side-effects/hash-changed';
6-
import { useIsEditable } from '~/states/page';
6+
import { useIsEditable, useRevisionIdFromUrl } from '~/states/page';
77
import { EditorMode, useEditorMode, useReservedNextCaretLine } from '~/states/ui/editor';
8-
import { useSWRxIsLatestRevision } from '~/stores/page';
98

109
import { LazyRenderer } from '../Common/LazyRenderer';
1110

@@ -18,14 +17,15 @@ export const DisplaySwitcher = (): JSX.Element => {
1817

1918
const { editorMode } = useEditorMode();
2019
const isEditable = useIsEditable();
21-
const { data: isLatestRevision } = useSWRxIsLatestRevision();
20+
const revisionIdFromUrl = useRevisionIdFromUrl();
2221

2322
useHashChangedEffect();
2423
useReservedNextCaretLine();
2524

2625
return (
2726
<LazyRenderer shouldRender={isEditable === true && editorMode === EditorMode.Editor}>
28-
{ isLatestRevision !== false
27+
{/* Display <PageEditorReadOnly /> when the user is intentionally viewing a specific (past) revision. */}
28+
{ revisionIdFromUrl == null
2929
? <PageEditor />
3030
: <PageEditorReadOnly />
3131
}

apps/app/src/client/services/side-effects/page-updated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const usePageUpdatedEffect = (): void => {
4545

4646
// !!CAUTION!! Timing of calling openPageStatusAlert may clash with components/PageEditor/conflict.tsx
4747
if (isRevisionOutdated && editorMode === EditorMode.View) {
48-
openPageStatusAlert({ hideEditorMode: EditorMode.Editor, onRefleshPage: fetchCurrentPage });
48+
openPageStatusAlert({ hideEditorMode: EditorMode.Editor, onRefleshPage: () => fetchCurrentPage({ force: true }) });
4949
}
5050

5151
// Clear cache

apps/app/src/components/PageView/PageAlerts/OldRevisionAlert.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { useRouter } from 'next/router';
33
import { returnPathForURL } from '@growi/core/dist/utils/path-utils';
44
import { useTranslation } from 'react-i18next';
55

6-
import { useCurrentPageData, useFetchCurrentPage } from '~/states/page';
7-
import { useSWRxIsLatestRevision } from '~/stores/page';
6+
import {
7+
useCurrentPageData,
8+
useFetchCurrentPage,
9+
useRevisionIdFromUrl,
10+
} from '~/states/page';
811

912
export const OldRevisionAlert = (): JSX.Element => {
1013
const router = useRouter();
1114
const { t } = useTranslation();
1215

13-
const { data: isLatestRevision } = useSWRxIsLatestRevision();
16+
const revisionIdFromUrl = useRevisionIdFromUrl();
1417
const page = useCurrentPageData();
1518
const { fetchCurrentPage } = useFetchCurrentPage();
1619

@@ -24,8 +27,8 @@ export const OldRevisionAlert = (): JSX.Element => {
2427
fetchCurrentPage({ force: true });
2528
}, [fetchCurrentPage, page, router]);
2629

27-
// Show alert only when viewing an old revision (isLatestRevision === false)
28-
if (isLatestRevision !== false) {
30+
// Show alert only when intentionally viewing a specific (past) revision (revisionIdFromUrl != null)
31+
if (revisionIdFromUrl == null) {
2932
// biome-ignore lint/complexity/noUselessFragments: ignore
3033
return <></>;
3134
}

0 commit comments

Comments
 (0)