Skip to content

Commit cd063b0

Browse files
committed
perf: optimize route transitions using React startTransition
1 parent c4a2544 commit cd063b0

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

  • packages
    • core/src/theme/components/DocContent/docComponents
    • shared/src/types
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { Link } from '@rspress/core/theme';
2-
import type { ComponentProps } from 'react';
2+
import { startTransition, type ComponentProps } from 'react';
3+
import { useSite } from '@rspress/core/runtime';
34

45
export const A = (props: ComponentProps<'a'>) => {
5-
return <Link {...props} />;
6+
const siteData = useSite();
7+
const concurrentRoute = siteData?.site?.route?.concurrentRoute;
8+
return (
9+
<Link
10+
startTransition={concurrentRoute ? startTransition : undefined}
11+
{...props}
12+
/>
13+
);
614
};

packages/shared/src/types/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ export interface RouteOptions {
503503
* @default false
504504
*/
505505
cleanUrls?: boolean;
506+
/**
507+
* Enable concurrent, optimized routing for markdown links.
508+
* Only applies to links located inside `.md` and `.mdx` files.
509+
* @default false
510+
* @unstable
511+
*/
512+
concurrentRoute?: boolean;
506513
}
507514

508515
export interface SearchHooks {

0 commit comments

Comments
 (0)