From 6d918ca7b8788be41f3ba92f0315a04eca54a861 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Fri, 4 Oct 2024 11:13:36 +0800 Subject: [PATCH] perf(theme): improve scroll behavior (#253) --- theme/src/client/composables/scroll-behavior.ts | 10 ++++++---- theme/src/node/plugins/getPlugins.ts | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/theme/src/client/composables/scroll-behavior.ts b/theme/src/client/composables/scroll-behavior.ts index da7c3974..cfaa3f1b 100644 --- a/theme/src/client/composables/scroll-behavior.ts +++ b/theme/src/client/composables/scroll-behavior.ts @@ -4,11 +4,13 @@ import { inBrowser } from '../utils/index.js' import { useScrollPromise } from './scroll-promise.js' export function enhanceScrollBehavior(router: Router) { - // handle scrollBehavior with transition - const scrollBehavior = router.options.scrollBehavior! - router.options.scrollBehavior = async (...args) => { + router.options.scrollBehavior = async (to, from, savedPosition) => { await useScrollPromise().wait() - return scrollBehavior(...args) + if (savedPosition) + return savedPosition + if (to.hash) + return { el: to.hash, top: 64 } + return { top: 0 } } router.beforeEach(() => { diff --git a/theme/src/node/plugins/getPlugins.ts b/theme/src/node/plugins/getPlugins.ts index 0c224ddd..62592caa 100644 --- a/theme/src/node/plugins/getPlugins.ts +++ b/theme/src/node/plugins/getPlugins.ts @@ -47,8 +47,6 @@ export function getPlugins({ activeHeaderLinksPlugin({ headerLinkSelector: 'a.outline-link', headerAnchorSelector: '.header-anchor', - delay: 200, - offset: 5, }), markdownHintPlugin({ hint: true, alert: true, injectStyles: false }),