diff --git a/.dumi/theme/builtins/Previewer/CodePreviewer.tsx b/.dumi/theme/builtins/Previewer/CodePreviewer.tsx index 51c960a1f70b..6ddc80f67dc3 100644 --- a/.dumi/theme/builtins/Previewer/CodePreviewer.tsx +++ b/.dumi/theme/builtins/Previewer/CodePreviewer.tsx @@ -8,7 +8,7 @@ import classNames from 'classnames'; import { FormattedMessage, useSiteData } from 'dumi'; import LZString from 'lz-string'; -import type { AntdPreviewerProps } from '.'; +import type { AntdPreviewerProps } from './Previewer'; import useLocation from '../../../hooks/useLocation'; import BrowserFrame from '../../common/BrowserFrame'; import ClientOnly from '../../common/ClientOnly'; @@ -171,7 +171,6 @@ const CodePreviewer: React.FC = (props) => { }); const localizedTitle = title; - const introChildren =
; const highlightClass = classNames('highlight-wrapper', { 'highlight-wrapper-expand': codeExpand, }); @@ -205,7 +204,7 @@ const CodePreviewer: React.FC = (props) => { const suffix = codeType === 'tsx' ? 'tsx' : 'js'; - const dependencies: Record = jsx.split('\n').reduce( + const dependencies = (jsx as string).split('\n').reduce>( (acc, line) => { const matches = line.match(/import .+? from '(.+)';$/); if (matches?.[1]) { @@ -377,7 +376,9 @@ createRoot(document.getElementById('container')).render(); } filename={filename} />
-
{introChildren}
+ {description && ( +
+ )} {showOnlineUrl && ( }> diff --git a/.dumi/theme/layouts/DocLayout/index.tsx b/.dumi/theme/layouts/DocLayout/index.tsx index 50728d6e1bf8..8ddbf828c777 100644 --- a/.dumi/theme/layouts/DocLayout/index.tsx +++ b/.dumi/theme/layouts/DocLayout/index.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; -import { Helmet, useOutlet } from 'dumi'; +import { Helmet, useOutlet, useSiteData } from 'dumi'; import React, { useContext, useEffect, useLayoutEffect, useMemo, useRef } from 'react'; import zhCN from 'antd/es/locale/zh_CN'; import ConfigProvider from 'antd/es/config-provider'; @@ -30,10 +30,11 @@ const locales = { const DocLayout: React.FC = () => { const outlet = useOutlet(); const location = useLocation(); - const { pathname, search } = location; + const { pathname, search, hash } = location; const [locale, lang] = useLocale(locales); const timerRef = useRef | null>(null); const { direction } = useContext(SiteContext); + const { loading } = useSiteData(); useLayoutEffect(() => { if (lang === 'cn') { @@ -52,6 +53,13 @@ const DocLayout: React.FC = () => { } }, []); + // handle hash change or visit page hash from Link component, and jump after async chunk loaded + useEffect(() => { + const id = hash.replace('#', ''); + + if (id) document.getElementById(decodeURIComponent(id))?.scrollIntoView(); + }, [loading, hash]); + useEffect(() => { if (typeof (window as any).ga !== 'undefined') { (window as any).ga('send', 'pageview', pathname + search);