diff --git a/ui/src/pages/Install/index.tsx b/ui/src/pages/Install/index.tsx index 3f531918..f3a9f85c 100644 --- a/ui/src/pages/Install/index.tsx +++ b/ui/src/pages/Install/index.tsx @@ -10,7 +10,7 @@ import { installBaseInfo, checkConfigFileExists, } from '@/services'; -import { Storage, handleFormError } from '@/utils'; +import { Storage, handleFormError, scrollToDocTop } from '@/utils'; import { CURRENT_LANG_STORAGE_KEY } from '@/common/constants'; import { @@ -109,7 +109,7 @@ const Index: FC = () => { }; const handleErr = (data) => { - window.scrollTo(0, 0); + scrollToDocTop(); setErrorData(data); }; diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsx index 0ccaca1d..c625b0ce 100644 --- a/ui/src/pages/Questions/Detail/index.tsx +++ b/ui/src/pages/Questions/Detail/index.tsx @@ -10,7 +10,7 @@ import { useTranslation } from 'react-i18next'; import { Pagination, CustomSidebar } from '@/components'; import { loggedUserInfoStore, toastStore } from '@/stores'; -import { scrollToElementTop } from '@/utils'; +import { scrollToElementTop, scrollToDocTop } from '@/utils'; import { usePageTags, usePageUsers } from '@/hooks'; import type { ListResult, @@ -158,7 +158,7 @@ const Index = () => { return; } if (type === 'default') { - window.scrollTo(0, 0); + scrollToDocTop(); getDetail(); return; } @@ -183,7 +183,7 @@ const Index = () => { if (!qid) { return; } - window.scrollTo(0, 0); + scrollToDocTop(); getDetail(); requestAnswers(); }, [qid]); diff --git a/ui/src/pages/Review/index.tsx b/ui/src/pages/Review/index.tsx index eafb32db..9ced13c1 100644 --- a/ui/src/pages/Review/index.tsx +++ b/ui/src/pages/Review/index.tsx @@ -7,6 +7,7 @@ import { usePageTags } from '@/hooks'; import { BaseUserCard, FormatTime, Empty, DiffContent } from '@/components'; import { getReviewList, revisionAudit } from '@/services'; import { pathFactory } from '@/router/pathFactory'; +import { scrollToDocTop } from '@/utils'; import type * as Type from '@/common/interface'; const Index: FC = () => { @@ -39,7 +40,7 @@ const Index: FC = () => { setNoTasks(true); } setTimeout(() => { - window.scrollTo({ top: 0 }); + scrollToDocTop(); }, 150); }; const queryNextOne = (pageNumber) => { diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsx index 5932f5c5..ce892495 100644 --- a/ui/src/pages/Tags/Detail/index.tsx +++ b/ui/src/pages/Tags/Detail/index.tsx @@ -19,7 +19,7 @@ import { } from '@/services'; import QuestionList, { QUESTION_ORDER_KEYS } from '@/components/QuestionList'; import HotQuestions from '@/components/HotQuestions'; -import { escapeRemove, guard, Storage } from '@/utils'; +import { escapeRemove, guard, Storage, scrollToDocTop } from '@/utils'; import { pathFactory } from '@/router/pathFactory'; import { QUESTIONS_ORDER_STORAGE_KEY } from '@/common/constants'; @@ -60,7 +60,7 @@ const Index: FC = () => { useEffect(() => { if (!listLoading) { - window.scrollTo(0, 0); + scrollToDocTop(); } }, [listLoading]); diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts index a163e181..7814a966 100644 --- a/ui/src/utils/common.ts +++ b/ui/src/utils/common.ts @@ -36,6 +36,7 @@ function scrollToElementTop(element) { window.scrollTo({ top: offsetPosition, + behavior: 'instant' as ScrollBehavior, }); } @@ -43,7 +44,8 @@ const scrollToDocTop = () => { setTimeout(() => { window.scrollTo({ top: 0, - behavior: 'smooth', + left: 0, + behavior: 'instant' as ScrollBehavior, }); }); };