diff --git a/.dumi/pages/index/components/MainBanner.tsx b/.dumi/pages/index/components/MainBanner.tsx index 8eaa6a8c..ea11533e 100644 --- a/.dumi/pages/index/components/MainBanner.tsx +++ b/.dumi/pages/index/components/MainBanner.tsx @@ -1,11 +1,12 @@ import { createStyles } from 'antd-style'; import classnames from 'classnames'; -import { Link, useLocation } from 'dumi'; +import { useLocation } from 'dumi'; import React from 'react'; import { Button } from 'antd'; import useLocale from '../../../hooks/useLocale'; import useLottie from '../../../hooks/useLottie'; +import Link from '../../../theme/common/Link'; import { getLocalizedPathname, isZhCN } from '../../../theme/utils'; import Container from '../common/Container'; import SiteContext from './SiteContext'; diff --git a/.dumi/theme/builtins/ComponentOverview/index.tsx b/.dumi/theme/builtins/ComponentOverview/index.tsx index e62a43b5..b730f9c5 100644 --- a/.dumi/theme/builtins/ComponentOverview/index.tsx +++ b/.dumi/theme/builtins/ComponentOverview/index.tsx @@ -243,7 +243,7 @@ const Overview: React.FC = () => { {cardContent} ) : ( - + {cardContent} ); diff --git a/.dumi/theme/builtins/DemoWrapper/index.tsx b/.dumi/theme/builtins/DemoWrapper/index.tsx index 15816017..92f19f18 100644 --- a/.dumi/theme/builtins/DemoWrapper/index.tsx +++ b/.dumi/theme/builtins/DemoWrapper/index.tsx @@ -1,9 +1,9 @@ -import React, { useContext } from 'react'; import { BugOutlined, CodeOutlined, ExperimentOutlined } from '@ant-design/icons'; import { XProvider } from '@ant-design/x'; -import { Tooltip, Button } from 'antd'; +import { Button, Tooltip } from 'antd'; import classNames from 'classnames'; import { DumiDemoGrid, FormattedMessage } from 'dumi'; +import React, { Suspense, useContext } from 'react'; import useLayoutState from '../../../hooks/useLayoutState'; import useLocale from '../../../hooks/useLocale'; @@ -106,7 +106,9 @@ const DemoWrapper: typeof DumiDemoGrid = ({ items }) => { - + + + ); diff --git a/.dumi/theme/builtins/LocaleLink/index.tsx b/.dumi/theme/builtins/LocaleLink/index.tsx index 3086392d..692e2539 100644 --- a/.dumi/theme/builtins/LocaleLink/index.tsx +++ b/.dumi/theme/builtins/LocaleLink/index.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; -import { Link } from 'dumi'; import useLocale from '../../../hooks/useLocale'; +import Link from '../../../theme/common/Link'; type LinkProps = Parameters[0]; diff --git a/.dumi/theme/common/Link.tsx b/.dumi/theme/common/Link.tsx index 7d84c205..dd855110 100644 --- a/.dumi/theme/common/Link.tsx +++ b/.dumi/theme/common/Link.tsx @@ -1,7 +1,6 @@ -import { Link as DumiLink, useLocation, useNavigate } from 'dumi'; -import nprogress from 'nprogress'; +import { Link as DumiLink, useAppData, useLocation, useNavigate } from 'dumi'; import type { MouseEvent, MouseEventHandler } from 'react'; -import React, { forwardRef, useLayoutEffect, useTransition } from 'react'; +import React, { useMemo, forwardRef } from 'react'; export interface LinkProps { to: string | { pathname?: string; search?: string; hash?: string }; @@ -9,64 +8,49 @@ export interface LinkProps { className?: string; onClick?: MouseEventHandler; component?: React.ComponentType; + children?: React.ReactNode; } -nprogress.configure({ showSpinner: false }); - -const Link = forwardRef>((props, ref) => { - const { to, children, component, ...rest } = props; - const [isPending, startTransition] = useTransition(); - const navigate = useNavigate(); - const { pathname } = useLocation(); - - const href = React.useMemo(() => { - if (typeof to === 'object') { - return `${to.pathname || pathname}${to.search || ''}${to.hash || ''}`; - } - return to; - }, [to]); - - const handleClick = (e: MouseEvent) => { - props.onClick?.(e); - if (!href?.startsWith('http')) { - // Should support open in new tab - if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { - e.preventDefault(); - startTransition(() => { - if (href) { - navigate(href); - } - }); +const Link = forwardRef>( + ({ component, children, to, ...rest }, ref) => { + const { pathname } = useLocation(); + const { preloadRoute } = useAppData(); + const navigate = useNavigate(); + const href = useMemo(() => { + if (typeof to === 'object') { + return `${to.pathname || pathname}${to.search || ''}${to.hash || ''}`; } + return to; + }, [to]); + const onClick = (e: MouseEvent) => { + rest.onClick?.(e); + if (!href?.startsWith('http')) { + // Should support open in new tab + if (!e.metaKey && !e.ctrlKey && !e.shiftKey) { + e.preventDefault(); + navigate(href); + } + } + }; + if (component) { + return React.createElement( + component, + { + ...rest, + ref, + href, + onClick, + onMouseEnter: () => preloadRoute?.(href), + }, + children, + ); } - }; - - useLayoutEffect(() => { - if (isPending) { - nprogress.start(); - } else { - nprogress.done(); - } - }, [isPending]); - - if (component) { - return React.createElement( - component, - { - ...rest, - ref, - onClick: handleClick, - href, - }, - children, + return ( + + {children} + ); - } - - return ( - - {children} - - ); -}); + }, +); export default Link; diff --git a/.dumi/theme/slots/Footer/index.tsx b/.dumi/theme/slots/Footer/index.tsx index fef42b1c..7d6c3418 100644 --- a/.dumi/theme/slots/Footer/index.tsx +++ b/.dumi/theme/slots/Footer/index.tsx @@ -15,13 +15,14 @@ import { import { TinyColor } from '@ctrl/tinycolor'; import { createStyles } from 'antd-style'; import getAlphaColor from 'antd/es/theme/util/getAlphaColor'; -import { FormattedMessage, Link } from 'dumi'; +import { FormattedMessage } from 'dumi'; import RcFooter from 'rc-footer'; import type { FooterColumn } from 'rc-footer/lib/column'; import React, { useContext } from 'react'; import useLocale from '../../../hooks/useLocale'; import useLocation from '../../../hooks/useLocation'; +import Link from '../../../theme/common/Link'; import SiteContext from '../SiteContext'; import AdditionalInfo from './AdditionalInfo'; diff --git a/.dumirc.ts b/.dumirc.ts index 5c2e244f..a3cdd5b8 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -8,7 +8,11 @@ import { version } from './package.json'; export default defineConfig({ plugins: ['dumi-plugin-color-chunk'], + + // For + routePrefetch: {}, manifest: {}, + conventionRoutes: { // to avoid generate routes for .dumi/pages/index/components/xx exclude: [/index\/components\//], diff --git a/bun.lockb b/bun.lockb index 96a35dd4..0707bedf 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 6ab2b423..54a693bb 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,6 @@ "@types/markdown-it": "^14.1.2", "@types/minimist": "^1.2.5", "@types/node": "^22.5.5", - "@types/nprogress": "^0.2.3", "@types/ora": "^3.2.0", "@types/pixelmatch": "^5.2.6", "@types/pngjs": "^6.0.5", @@ -211,7 +210,6 @@ "mockdate": "^3.0.5", "node-fetch": "^3.3.2", "node-notifier": "^10.0.1", - "nprogress": "^0.2.0", "open": "^10.1.0", "ora": "^8.1.0", "pixelmatch": "^6.0.0",