Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong search scroll position of 1-level heading in current page #1978

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/client/theme-default/layouts/DocLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const DocLayout: FC = () => {
});
}
}, 1);
} else {
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉在 DocLayout 里处理不太合适,两个原因:

  1. 既然解决的问题场景是搜索,在搜索逻辑里处理更纯粹
  2. DocLayout 覆盖的场景太多容易误伤,比如在浏览到一半刷新页面的场景就会被强制 scroll 回顶部

建议的方案:在单击搜索结果时做判断,如果目标链接是本页且不带 hash,再主动滚动到顶部

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

animateScrollTo(0, {
maxDuration: 300,
});
}, 1);
}
}, [loading, hash]);

Expand Down
Loading