@rspress/core 2.0.23 → 2.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/cli/index.js +2 -2
  2. package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
  3. package/dist/config/loadConfigFile.js +1 -1
  4. package/dist/eject-theme/components/CdnTabs/index.test.tsx +71 -0
  5. package/dist/eject-theme/components/CdnTabs/index.tsx +175 -0
  6. package/dist/eject-theme/components/DocContent/index.tsx +0 -3
  7. package/dist/eject-theme/components/FallbackHeading/index.tsx +6 -1
  8. package/dist/eject-theme/components/Link/getHref.ts +1 -0
  9. package/dist/eject-theme/components/Link/index.tsx +9 -21
  10. package/dist/eject-theme/components/Link/useLinkNavigate.ts +43 -54
  11. package/dist/eject-theme/components/NavTitle/index.test.tsx +78 -0
  12. package/dist/eject-theme/components/NavTitle/index.tsx +9 -5
  13. package/dist/eject-theme/components/PackageManagerTabs/index.test.tsx +79 -1
  14. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +25 -12
  15. package/dist/eject-theme/components/Search/NoSearchResult.scss +1 -2
  16. package/dist/eject-theme/components/Search/SearchPanel.scss +75 -63
  17. package/dist/eject-theme/components/Search/SuggestItem.scss +28 -41
  18. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
  19. package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
  20. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +8 -0
  21. package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +3 -0
  22. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
  23. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
  24. package/dist/entry/worker.js +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/node/PluginDriver.d.ts +5 -0
  27. package/dist/node/PluginDriver.js +17 -2
  28. package/dist/node/auto-nav-sidebar/index.js +1 -1
  29. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  30. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  31. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  32. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  33. package/dist/node/constants.js +1 -1
  34. package/dist/node/eject.js +1 -1
  35. package/dist/node/initRsbuild.js +19 -7
  36. package/dist/node/llms.d.ts +1 -1
  37. package/dist/node/llms.js +2 -2
  38. package/dist/node/logger/hint.d.ts +1 -0
  39. package/dist/node/logger/hint.js +8 -2
  40. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -0
  41. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  42. package/dist/node/route/RoutePage.js +1 -1
  43. package/dist/node/route/RouteService.js +1 -1
  44. package/dist/node/route/extractPageData.js +1 -1
  45. package/dist/node/route/normalizeRoutePath.js +1 -1
  46. package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.d.ts → i18n/DEFAULT_I18N_TEXT.d.ts} +28 -0
  47. package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.js → i18n/DEFAULT_I18N_TEXT.js} +28 -0
  48. package/dist/node/runtimeModule/i18n/getI18nData.d.ts +11 -0
  49. package/dist/node/runtimeModule/{i18n.js → i18n/getI18nData.js} +35 -22
  50. package/dist/node/runtimeModule/i18n/rsbuildPlugin.d.ts +5 -0
  51. package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +21 -0
  52. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  53. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  54. package/dist/node/runtimeModule/searchHooks.js +2 -2
  55. package/dist/node/runtimeModule/siteData/createSiteData.d.ts +2 -1
  56. package/dist/node/runtimeModule/siteData/createSiteData.js +3 -3
  57. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.d.ts +2 -1
  58. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +3 -4
  59. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +2 -2
  60. package/dist/node/serve.js +1 -1
  61. package/dist/node/sitemap.d.ts +7 -0
  62. package/dist/node/sitemap.js +86 -0
  63. package/dist/node/ssg/alternateLinks.js +1 -1
  64. package/dist/node/ssg/htmlFile.js +1 -1
  65. package/dist/node/ssg/renderHtmlTemplate.js +1 -1
  66. package/dist/node/ssg/renderPage.js +1 -1
  67. package/dist/node/ssg/renderPageWorker.js +1 -1
  68. package/dist/node/ssg/renderPages.js +2 -2
  69. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  70. package/dist/node/ssg/ssgEnv.js +1 -1
  71. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  72. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  73. package/dist/node/ssg-md/renderPage.js +5 -4
  74. package/dist/node/ssg-md/renderPages.js +2 -2
  75. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  76. package/dist/node/utils/checkLanguageParity.js +1 -1
  77. package/dist/node/utils/createHash.js +1 -1
  78. package/dist/node/utils/flattenMdxContent.js +1 -1
  79. package/dist/node/utils/getPageKey.js +1 -1
  80. package/dist/node/utils/reactAlias.js +6 -3
  81. package/dist/{a~0.js → p~0.js} +23 -18
  82. package/dist/runtime/App.js +20 -29
  83. package/dist/runtime/BrowserOnly.d.ts +1 -1
  84. package/dist/runtime/BrowserOnly.js +53 -20
  85. package/dist/runtime/ClientApp.d.ts +3 -2
  86. package/dist/runtime/ClientApp.js +31 -21
  87. package/dist/runtime/ErrorRoute.d.ts +1 -0
  88. package/dist/runtime/ErrorRoute.js +30 -0
  89. package/dist/runtime/NoSSR.d.ts +7 -3
  90. package/dist/runtime/NoSSR.js +30 -9
  91. package/dist/runtime/PageRoute.d.ts +2 -0
  92. package/dist/runtime/PageRoute.js +70 -0
  93. package/dist/runtime/createServerRouter.d.ts +4 -0
  94. package/dist/runtime/createServerRouter.js +17 -0
  95. package/dist/runtime/csrClientEntry.js +5 -2
  96. package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
  97. package/dist/runtime/hooks/useWebMcp.js +80 -0
  98. package/dist/runtime/index.d.ts +6 -3
  99. package/dist/runtime/index.js +6 -5
  100. package/dist/runtime/initPageData.d.ts +0 -3
  101. package/dist/runtime/initPageData.js +9 -45
  102. package/dist/runtime/pageDataLoader.d.ts +11 -0
  103. package/dist/runtime/pageDataLoader.js +7 -0
  104. package/dist/runtime/react.d.ts +5 -0
  105. package/dist/runtime/react.js +4 -0
  106. package/dist/runtime/reactDom.d.ts +6 -0
  107. package/dist/runtime/reactDom.js +2 -1
  108. package/dist/runtime/socialLinks.d.ts +1 -0
  109. package/dist/runtime/socialLinks.js +3 -0
  110. package/dist/runtime/ssrClientEntry.js +14 -6
  111. package/dist/runtime/ssrMdServerEntry.js +10 -21
  112. package/dist/runtime/ssrServerEntry.js +10 -21
  113. package/dist/static/assets/package.json +58 -0
  114. package/dist/theme/assets/bun.js +101 -0
  115. package/dist/theme/assets/deno.js +15 -0
  116. package/dist/theme/assets/jsdelivr.js +53 -0
  117. package/dist/theme/{components/PackageManagerTabs/icons/Npm.js → assets/npm.js} +4 -4
  118. package/dist/theme/{components/PackageManagerTabs/icons/Pnpm.js → assets/pnpm.js} +4 -4
  119. package/dist/theme/assets/unpkg.js +15 -0
  120. package/dist/theme/assets/yarn.js +22 -0
  121. package/dist/theme/components/CdnTabs/index.d.ts +10 -0
  122. package/dist/theme/components/CdnTabs/index.js +146 -0
  123. package/dist/theme/components/DocContent/index.js +1 -2
  124. package/dist/theme/components/FallbackHeading/index.js +1 -0
  125. package/dist/theme/components/Link/index.js +4 -17
  126. package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
  127. package/dist/theme/components/Link/useLinkNavigate.js +22 -36
  128. package/dist/theme/components/NavTitle/index.js +10 -5
  129. package/dist/theme/components/PackageManagerTabs/index.d.ts +2 -0
  130. package/dist/theme/components/PackageManagerTabs/index.js +22 -12
  131. package/dist/theme/components/Search/NoSearchResult.css +1 -2
  132. package/dist/theme/components/Search/SearchPanel.css +72 -51
  133. package/dist/theme/components/Search/SuggestItem.css +21 -34
  134. package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
  135. package/dist/theme/components/Search/useSearchPanel.js +74 -26
  136. package/dist/theme/components/Sidebar/SidebarItem.css +5 -0
  137. package/dist/theme/components/Sidebar/SidebarSectionHeader.css +1 -0
  138. package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
  139. package/dist/theme/hooks/useDynamicToc.js +27 -34
  140. package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
  141. package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
  142. package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
  143. package/dist/theme/hooks/useWebMcpPageList.js +25 -0
  144. package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
  145. package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
  146. package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
  147. package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
  148. package/dist/theme/icons.d.ts +7 -0
  149. package/dist/theme/icons.js +15 -1
  150. package/dist/theme/index.d.ts +6 -2
  151. package/dist/theme/index.js +6 -2
  152. package/dist/theme/layout/ErrorLayout/index.css +52 -0
  153. package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
  154. package/dist/theme/layout/ErrorLayout/index.js +76 -0
  155. package/dist/theme/layout/Layout/index.js +1 -2
  156. package/dist/theme/webMcp/tools.d.ts +56 -0
  157. package/dist/theme/webMcp/tools.js +122 -0
  158. package/dist/theme/webMcp/types.d.ts +35 -0
  159. package/dist/theme/webMcp/types.js +0 -0
  160. package/dist/tinypool~0.js +19 -49
  161. package/dist/y~0.js +166 -0
  162. package/package.json +18 -18
  163. package/dist/b~0.js +0 -106
  164. package/dist/eject-theme/components/PackageManagerTabs/icons/Bun.tsx +0 -101
  165. package/dist/eject-theme/components/PackageManagerTabs/icons/Deno.tsx +0 -18
  166. package/dist/eject-theme/components/PackageManagerTabs/icons/Npm.tsx +0 -16
  167. package/dist/eject-theme/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
  168. package/dist/eject-theme/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
  169. package/dist/node/runtimeModule/i18n.d.ts +0 -8
  170. package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +0 -2
  171. package/dist/theme/components/PackageManagerTabs/icons/Bun.js +0 -137
  172. package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +0 -2
  173. package/dist/theme/components/PackageManagerTabs/icons/Deno.js +0 -15
  174. package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +0 -2
  175. package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +0 -2
  176. package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +0 -2
  177. package/dist/theme/components/PackageManagerTabs/icons/Yarn.js +0 -22
  178. package/dist/theme/logic/useScrollAfterNav.d.ts +0 -5
  179. package/dist/theme/logic/useScrollAfterNav.js +0 -35
  180. package/dist/theme/logic/useScrollReset.d.ts +0 -5
  181. package/dist/theme/logic/useScrollReset.js +0 -12
@@ -1,39 +1,72 @@
1
- import { useEffect, useState } from "react";
2
- function BrowserOnly(props) {
3
- const { children, fallback = null } = props;
4
- const [state, setState] = useState({
5
- status: 'pending',
6
- children
7
- });
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { Suspense, useEffect, useMemo, useState } from "react";
3
+ import { safeUse } from "./react.js";
4
+ import { safeBrowserOnly } from "./reactDom.js";
5
+ function DeferredBrowserOnly({ source, fallback = null }) {
6
+ const [state, setState] = useState();
8
7
  useEffect(()=>{
9
8
  let isMounted = true;
10
- setState({
11
- status: 'pending',
12
- children
13
- });
14
- Promise.resolve().then(()=>children()).then((content)=>{
9
+ setState(void 0);
10
+ Promise.resolve().then(()=>'function' == typeof source ? source() : source).then((content)=>{
15
11
  if (isMounted) setState({
16
- status: 'resolved',
17
- children,
12
+ source,
18
13
  content
19
14
  });
20
15
  }, (error)=>{
21
16
  if (isMounted) setState({
22
- status: 'rejected',
23
- children,
17
+ source,
24
18
  error
25
19
  });
26
20
  });
27
21
  return ()=>{
28
22
  isMounted = false;
29
23
  };
24
+ }, [
25
+ source
26
+ ]);
27
+ if (!state || state.source !== source) return fallback;
28
+ if ('error' in state) throw state.error;
29
+ return state.content;
30
+ }
31
+ function ModernBrowserOnly({ children, fallback }) {
32
+ safeUse(safeBrowserOnly('This content is only rendered in the browser.'));
33
+ const result = useMemo(()=>{
34
+ const content = children();
35
+ if (null !== content && 'object' == typeof content && 'then' in content && 'function' == typeof content.then) {
36
+ const promise = Promise.resolve(content);
37
+ promise.catch(()=>{});
38
+ return {
39
+ promise
40
+ };
41
+ }
42
+ return {
43
+ content
44
+ };
30
45
  }, [
31
46
  children
32
47
  ]);
33
- if (state.children !== children) return fallback;
34
- if ('rejected' === state.status) throw state.error;
35
- if ('resolved' === state.status) return state.content;
36
- return fallback;
48
+ if (result.promise) return /*#__PURE__*/ jsx(DeferredBrowserOnly, {
49
+ source: result.promise,
50
+ fallback: fallback
51
+ });
52
+ return /*#__PURE__*/ jsx(Fragment, {
53
+ children: result.content
54
+ });
55
+ }
56
+ function BrowserOnly(props) {
57
+ const { fallback = null } = props;
58
+ if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
59
+ children: fallback
60
+ });
61
+ return /*#__PURE__*/ jsx(Suspense, {
62
+ fallback: fallback,
63
+ children: 'function' == typeof safeBrowserOnly ? /*#__PURE__*/ jsx(ModernBrowserOnly, {
64
+ ...props
65
+ }) : /*#__PURE__*/ jsx(DeferredBrowserOnly, {
66
+ source: props.children,
67
+ fallback: fallback
68
+ })
69
+ });
37
70
  }
38
71
  const runtime_BrowserOnly = BrowserOnly;
39
72
  export default runtime_BrowserOnly;
@@ -1,4 +1,5 @@
1
1
  import type { Page } from './initPageData.js';
2
- export declare function ClientApp({ initialPageData, }: {
3
- initialPageData?: Page;
2
+ export declare function createClientRouter(initialPageData?: Page): import("react-router-dom").DataRouter;
3
+ export declare function ClientApp({ router, }: {
4
+ router: ReturnType<typeof createClientRouter>;
4
5
  }): import("react").JSX.Element;
@@ -1,14 +1,34 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { BrowserRouter, PageContext, ThemeContext, removeTrailingSlash, useSite, withBase } from "@rspress/core/runtime";
2
+ import { RouterProvider, ThemeContext, createBrowserRouter, removeTrailingSlash, useSite, withBase } from "@rspress/core/runtime";
3
3
  import { useThemeState } from "@rspress/core/theme";
4
4
  import { UnheadProvider, createHead } from "@unhead/react/client";
5
- import { useMemo, useState } from "react";
6
- import { App } from "./App.js";
5
+ import { useMemo } from "react";
6
+ import { PAGE_ROUTE_ID } from "./pageDataLoader.js";
7
+ import { createPageRoutes } from "./PageRoute.js";
7
8
  const head = createHead();
8
- function ClientApp({ initialPageData = null }) {
9
- const [data, setData] = useState(initialPageData);
9
+ function createClientRouter(initialPageData) {
10
+ if (!window.history.state?.key) window.history.replaceState({
11
+ ...window.history.state,
12
+ key: Math.random().toString(36).slice(2, 10)
13
+ }, '');
14
+ return createBrowserRouter(createPageRoutes(), {
15
+ basename: removeTrailingSlash(withBase('/')),
16
+ hydrationData: initialPageData ? {
17
+ loaderData: {
18
+ [PAGE_ROUTE_ID]: initialPageData
19
+ }
20
+ } : void 0
21
+ });
22
+ }
23
+ function ClientApp({ router }) {
10
24
  const [theme, setTheme] = useThemeState();
11
25
  const { site } = useSite();
26
+ const transitionOptions = {
27
+ useTransitions: site.route.useTransitions,
28
+ future: {
29
+ v7_startTransition: site.route.useTransitions
30
+ }
31
+ };
12
32
  return /*#__PURE__*/ jsx(ThemeContext.Provider, {
13
33
  value: useMemo(()=>({
14
34
  theme,
@@ -17,23 +37,13 @@ function ClientApp({ initialPageData = null }) {
17
37
  theme,
18
38
  setTheme
19
39
  ]),
20
- children: /*#__PURE__*/ jsx(PageContext.Provider, {
21
- value: useMemo(()=>({
22
- data,
23
- setData
24
- }), [
25
- data,
26
- setData
27
- ]),
28
- children: /*#__PURE__*/ jsx(BrowserRouter, {
29
- basename: removeTrailingSlash(withBase('/')),
30
- useTransitions: site.route.useTransitions,
31
- children: /*#__PURE__*/ jsx(UnheadProvider, {
32
- head: head,
33
- children: /*#__PURE__*/ jsx(App, {})
34
- })
40
+ children: /*#__PURE__*/ jsx(UnheadProvider, {
41
+ head: head,
42
+ children: /*#__PURE__*/ jsx(RouterProvider, {
43
+ router: router,
44
+ ...transitionOptions
35
45
  })
36
46
  })
37
47
  });
38
48
  }
39
- export { ClientApp };
49
+ export { ClientApp, createClientRouter };
@@ -0,0 +1 @@
1
+ export declare function ErrorRoute(): import("react").JSX.Element;
@@ -0,0 +1,30 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { ErrorLayout } from "@rspress/core/theme";
3
+ import { useEffect } from "react";
4
+ import { useLocation, useRouteError } from "react-router-dom";
5
+ import { useSite } from "./hooks/useSite.js";
6
+ import { withBase } from "./utils.js";
7
+ function ErrorRoute() {
8
+ const error = useRouteError();
9
+ const { pathname } = useLocation();
10
+ const { site } = useSite();
11
+ const segments = pathname.split('/').filter(Boolean);
12
+ const version = site.multiVersion.versions.find((v)=>v === segments[0]);
13
+ const lang = site.locales.find((locale)=>locale.lang === segments[version ? 1 : 0])?.lang || site.lang;
14
+ const prefix = [
15
+ version !== site.multiVersion.default ? version : void 0,
16
+ lang !== site.lang ? lang : void 0
17
+ ].filter(Boolean);
18
+ const homeHref = withBase(prefix.length ? `/${prefix.join('/')}/` : '/');
19
+ useEffect(()=>{
20
+ console.error('[rspress] Failed to render page:', error);
21
+ }, [
22
+ error
23
+ ]);
24
+ return /*#__PURE__*/ jsx(ErrorLayout, {
25
+ error: error,
26
+ lang: lang,
27
+ homeHref: homeHref
28
+ });
29
+ }
30
+ export { ErrorRoute };
@@ -1,3 +1,7 @@
1
- export declare function NoSSR(props: {
2
- children: React.ReactNode;
3
- }): import("react").JSX.Element | null;
1
+ import { type ReactNode } from 'react';
2
+ export interface NoSSRProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ }
6
+ export declare function LegacyNoSSR({ children, fallback }: NoSSRProps): import("react").JSX.Element;
7
+ export declare function NoSSR(props: NoSSRProps): import("react").JSX.Element;
@@ -1,14 +1,35 @@
1
1
  import { Fragment, jsx } from "react/jsx-runtime";
2
- import { useEffect, useState } from "react";
3
- function NoSSR(props) {
4
- const { children } = props;
5
- const [isMounted, setIsMounted] = useState(false);
6
- useEffect(()=>{
7
- setIsMounted(true);
8
- }, []);
9
- if (!isMounted) return null;
2
+ import { Suspense, useSyncExternalStore } from "react";
3
+ import { safeBrowserOnly } from "./reactDom.js";
4
+ import { safeUse } from "./react.js";
5
+ function ModernNoSSR({ children }) {
6
+ safeUse(safeBrowserOnly('This content is only rendered in the browser.'));
10
7
  return /*#__PURE__*/ jsx(Fragment, {
11
8
  children: children
12
9
  });
13
10
  }
14
- export { NoSSR };
11
+ const emptySubscribe = ()=>()=>{};
12
+ const getSnapshot = ()=>true;
13
+ const getServerSnapshot = ()=>false;
14
+ function LegacyNoSSR({ children, fallback = null }) {
15
+ const isMounted = useSyncExternalStore(emptySubscribe, getSnapshot, getServerSnapshot);
16
+ return /*#__PURE__*/ jsx(Fragment, {
17
+ children: isMounted ? children : fallback
18
+ });
19
+ }
20
+ function NoSSR(props) {
21
+ const { fallback = null } = props;
22
+ if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
23
+ children: fallback
24
+ });
25
+ if ('function' == typeof safeBrowserOnly) return /*#__PURE__*/ jsx(Suspense, {
26
+ fallback: fallback,
27
+ children: /*#__PURE__*/ jsx(ModernNoSSR, {
28
+ ...props
29
+ })
30
+ });
31
+ return /*#__PURE__*/ jsx(LegacyNoSSR, {
32
+ ...props
33
+ });
34
+ }
35
+ export { LegacyNoSSR, NoSSR };
@@ -0,0 +1,2 @@
1
+ import { type RouteObject } from 'react-router-dom';
2
+ export declare function createPageRoutes(): RouteObject[];
@@ -0,0 +1,70 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import nprogress from "nprogress";
3
+ import { useCallback, useEffect, useMemo, useState } from "react";
4
+ import { Outlet, ScrollRestoration, useLoaderData, useNavigation } from "react-router-dom";
5
+ import { App } from "./App.js";
6
+ import { ErrorRoute } from "./ErrorRoute.js";
7
+ import { PageContext } from "./hooks/usePage.js";
8
+ import { PAGE_ROUTE_ID, pageDataLoader } from "./pageDataLoader.js";
9
+ nprogress.configure({
10
+ showSpinner: false
11
+ });
12
+ function PageRoute() {
13
+ const page = useLoaderData();
14
+ const { state } = useNavigation();
15
+ const [override, setOverride] = useState();
16
+ const data = override?.source === page ? override.data : page;
17
+ const setData = useCallback((data)=>{
18
+ setOverride({
19
+ source: page,
20
+ data
21
+ });
22
+ }, [
23
+ page
24
+ ]);
25
+ useEffect(()=>{
26
+ if ('idle' === state) return;
27
+ const timer = setTimeout(()=>nprogress.start(), 200);
28
+ return ()=>{
29
+ clearTimeout(timer);
30
+ nprogress.done();
31
+ };
32
+ }, [
33
+ state
34
+ ]);
35
+ return /*#__PURE__*/ jsx(PageContext.Provider, {
36
+ value: useMemo(()=>({
37
+ data,
38
+ setData
39
+ }), [
40
+ data,
41
+ setData
42
+ ]),
43
+ children: /*#__PURE__*/ jsx(App, {})
44
+ });
45
+ }
46
+ function createPageRoutes() {
47
+ return [
48
+ {
49
+ hydrateFallbackElement: /*#__PURE__*/ jsx(Fragment, {}),
50
+ element: /*#__PURE__*/ jsxs(Fragment, {
51
+ children: [
52
+ /*#__PURE__*/ jsx(Outlet, {}),
53
+ /*#__PURE__*/ jsx(ScrollRestoration, {
54
+ storageKey: "rspress-scroll-positions"
55
+ })
56
+ ]
57
+ }),
58
+ children: [
59
+ {
60
+ id: PAGE_ROUTE_ID,
61
+ path: '*',
62
+ loader: pageDataLoader,
63
+ element: /*#__PURE__*/ jsx(PageRoute, {}),
64
+ errorElement: /*#__PURE__*/ jsx(ErrorRoute, {})
65
+ }
66
+ ]
67
+ }
68
+ ];
69
+ }
70
+ export { createPageRoutes };
@@ -0,0 +1,4 @@
1
+ export declare function createServerRouter(routePath: string): Promise<{
2
+ router: import("react-router-dom").DataRouter;
3
+ context: import("react-router-dom").StaticHandlerContext;
4
+ }>;
@@ -0,0 +1,17 @@
1
+ import { createStaticHandler, createStaticRouter } from "virtual-react-router-server";
2
+ import { createPageRoutes } from "./PageRoute.js";
3
+ import { removeTrailingSlash, withBase } from "./utils.js";
4
+ async function createServerRouter(routePath) {
5
+ const basename = removeTrailingSlash(withBase('/'));
6
+ const { query, dataRoutes } = createStaticHandler(createPageRoutes(), {
7
+ basename
8
+ });
9
+ const context = await query(new Request(new URL(`${basename}${routePath}`, 'http://rspress.local')));
10
+ if (context instanceof Response) throw new Error(`Unexpected response while rendering ${routePath}: ${context.status}`);
11
+ if (context.errors) throw Object.values(context.errors)[0];
12
+ return {
13
+ router: createStaticRouter(dataRoutes, context),
14
+ context
15
+ };
16
+ }
17
+ export { createServerRouter };
@@ -1,10 +1,13 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from "react-dom/client";
3
- import { ClientApp } from "./ClientApp.js";
3
+ import { ClientApp, createClientRouter } from "./ClientApp.js";
4
4
  import { redirectToCleanUrl } from "./route.js";
5
5
  function renderInBrowser() {
6
6
  redirectToCleanUrl(window.location, window.history);
7
7
  const container = document.getElementById('__rspress_root');
8
- createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {}));
8
+ const router = createClientRouter();
9
+ createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {
10
+ router: router
11
+ }));
9
12
  }
10
13
  renderInBrowser();
@@ -0,0 +1,36 @@
1
+ export interface WebMcpExecuteOptions {
2
+ /** Cancellation requested by the browser or agent. */
3
+ signal?: AbortSignal;
4
+ }
5
+ export interface WebMcpOptions<TInput = unknown, TResult = unknown> {
6
+ name: string;
7
+ title?: string;
8
+ description: string;
9
+ /** JSON Schema describing the input. Validate untrusted inputs in execute. */
10
+ inputSchema?: Record<string, unknown>;
11
+ annotations?: {
12
+ readOnlyHint?: boolean;
13
+ untrustedContentHint?: boolean;
14
+ consequentialHint?: boolean;
15
+ debugging?: boolean;
16
+ };
17
+ execute(input: TInput, options: WebMcpExecuteOptions): TResult | Promise<TResult>;
18
+ /** Register only while enabled. Defaults to true. */
19
+ enabled?: boolean;
20
+ /** Additional secure origins allowed to discover this tool. */
21
+ exposedTo?: string[];
22
+ }
23
+ export interface WebMcpState {
24
+ supported: boolean;
25
+ registered: boolean;
26
+ /** Registration error. Execution errors are returned to the caller. */
27
+ error: Error | null;
28
+ }
29
+ /**
30
+ * Registers a component-owned tool with the native browser WebMCP API.
31
+ * Calls use the latest committed handler; disabling or unmounting unregisters
32
+ * the tool. Safe during SSR and in browsers without WebMCP support.
33
+ * @returns Browser support, registration status, and any registration error.
34
+ * @unstable
35
+ */
36
+ export declare function useWebMcp<TInput = unknown, TResult = unknown>(options: WebMcpOptions<TInput, TResult>): WebMcpState;
@@ -0,0 +1,80 @@
1
+ import { useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ const useCommittedEffect = "u" < typeof window ? useEffect : useLayoutEffect;
3
+ const toError = (error)=>error instanceof Error ? error : new Error(String(error));
4
+ function useWebMcp(options) {
5
+ const { execute, enabled = true, exposedTo, ...descriptor } = options;
6
+ const current = useRef(execute);
7
+ useCommittedEffect(()=>{
8
+ current.current = execute;
9
+ });
10
+ let key = '';
11
+ let preparationError = null;
12
+ try {
13
+ key = JSON.stringify({
14
+ descriptor,
15
+ exposedTo
16
+ });
17
+ } catch (error) {
18
+ preparationError = toError(error);
19
+ }
20
+ const preparationMessage = preparationError?.message;
21
+ const [state, setState] = useState({
22
+ supported: false,
23
+ registered: false,
24
+ error: null
25
+ });
26
+ useEffect(()=>{
27
+ const context = "u" < typeof document ? void 0 : document.modelContext;
28
+ const supported = 'function' == typeof context?.registerTool;
29
+ if (!supported || !enabled || void 0 !== preparationMessage) return void setState({
30
+ supported,
31
+ registered: false,
32
+ error: void 0 === preparationMessage ? null : new Error(preparationMessage)
33
+ });
34
+ const controller = new AbortController();
35
+ const metadata = JSON.parse(key);
36
+ setState({
37
+ supported: true,
38
+ registered: false,
39
+ error: null
40
+ });
41
+ const failed = (error)=>{
42
+ if (controller.signal.aborted) return;
43
+ controller.abort();
44
+ setState({
45
+ supported: true,
46
+ registered: false,
47
+ error: toError(error)
48
+ });
49
+ console.error(`[Rspress] Failed to register ${metadata.descriptor.name}:`, error);
50
+ };
51
+ try {
52
+ const registration = context.registerTool({
53
+ ...metadata.descriptor,
54
+ execute: (input, executionOptions)=>{
55
+ executionOptions?.signal?.throwIfAborted();
56
+ return current.current(input, executionOptions ?? {});
57
+ }
58
+ }, {
59
+ signal: controller.signal,
60
+ exposedTo: metadata.exposedTo
61
+ });
62
+ Promise.resolve(registration).then(()=>{
63
+ if (!controller.signal.aborted) setState({
64
+ supported: true,
65
+ registered: true,
66
+ error: null
67
+ });
68
+ }, failed);
69
+ } catch (error) {
70
+ failed(error);
71
+ }
72
+ return ()=>controller.abort();
73
+ }, [
74
+ key,
75
+ enabled,
76
+ preparationMessage
77
+ ]);
78
+ return state;
79
+ }
80
+ export { useWebMcp };
@@ -7,6 +7,7 @@ export { useActiveMatcher } from './hooks/useActiveMatcher.js';
7
7
  export { ThemeContext, useDark } from './hooks/useDark.js';
8
8
  export { useFrontmatter } from './hooks/useFrontmatter.js';
9
9
  export { useI18n } from './hooks/useI18n.js';
10
+ export { useI18nText } from './hooks/useI18nText.js';
10
11
  export { useLang } from './hooks/useLang.js';
11
12
  export { useLocaleSiteData } from './hooks/useLocaleSiteData.js';
12
13
  export { useNav } from './hooks/useNav.js';
@@ -16,11 +17,13 @@ export { usePages, searchIndexHash } from './hooks/usePages.js';
16
17
  export { getSidebarDataGroup, useSidebar, useSidebarDynamic, } from './hooks/useSidebar.js';
17
18
  export { useSite } from './hooks/useSite.js';
18
19
  export { useVersion } from './hooks/useVersion.js';
20
+ export { useWebMcp, type WebMcpOptions, type WebMcpState, type WebMcpExecuteOptions, } from './hooks/useWebMcp.js';
19
21
  export { useWindowSize } from './hooks/useWindowSize.js';
20
- export { initPageData, warmPageData } from './initPageData.js';
22
+ export { initPageData } from './initPageData.js';
21
23
  export { NoSSR } from './NoSSR.js';
22
- export { safePreconnect, safePreload } from './reactDom.js';
24
+ export { safeUse } from './react.js';
25
+ export { safePreconnect, safePreload, safeBrowserOnly } from './reactDom.js';
23
26
  export { isActive, pathnameToRouteService, preloadLink } from './route.js';
24
27
  export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin, } from './utils.js';
25
- export declare const socialLinks: Record<string, string>;
28
+ export { socialLinks } from './socialLinks.js';
26
29
  export { useSearchHooks, type SearchHooks } from './hooks/useSearchHooks.js';
@@ -1,6 +1,4 @@
1
- import virtual_social_links from "virtual-social-links";
2
1
  export * from "react-router-dom";
3
- const socialLinks = virtual_social_links;
4
2
  export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
5
3
  export { Head, useHead } from "@unhead/react";
6
4
  export { BrowserOnly } from "./BrowserOnly.js";
@@ -9,6 +7,7 @@ export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
9
7
  export { ThemeContext, useDark } from "./hooks/useDark.js";
10
8
  export { useFrontmatter } from "./hooks/useFrontmatter.js";
11
9
  export { useI18n } from "./hooks/useI18n.js";
10
+ export { useI18nText } from "./hooks/useI18nText.js";
12
11
  export { useLang } from "./hooks/useLang.js";
13
12
  export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
14
13
  export { useNav } from "./hooks/useNav.js";
@@ -18,11 +17,13 @@ export { searchIndexHash, usePages } from "./hooks/usePages.js";
18
17
  export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
19
18
  export { useSite } from "./hooks/useSite.js";
20
19
  export { useVersion } from "./hooks/useVersion.js";
20
+ export { useWebMcp } from "./hooks/useWebMcp.js";
21
21
  export { useWindowSize } from "./hooks/useWindowSize.js";
22
- export { initPageData, warmPageData } from "./initPageData.js";
22
+ export { initPageData } from "./initPageData.js";
23
23
  export { NoSSR } from "./NoSSR.js";
24
- export { safePreconnect, safePreload } from "./reactDom.js";
24
+ export { safeUse } from "./react.js";
25
+ export { safeBrowserOnly, safePreconnect, safePreload } from "./reactDom.js";
25
26
  export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
26
27
  export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin } from "./utils.js";
28
+ export { socialLinks } from "./socialLinks.js";
27
29
  export { useSearchHooks } from "./hooks/useSearchHooks.js";
28
- export { socialLinks };
@@ -1,6 +1,3 @@
1
1
  import { type PageDataLegacy } from '@rspress/shared';
2
2
  export type Page = PageDataLegacy['page'];
3
- export declare function warmPageData(routePath: string, data: Page): void;
4
- export declare function consumeCachedPageData(routePath: string): Page | undefined;
5
- export declare function setCurrentPageData(routePath: string, data: Page): void;
6
3
  export declare function initPageData(routePath: string): Promise<Page>;
@@ -3,40 +3,6 @@ import { pageData } from "./hooks/usePages.js";
3
3
  import { pathnameToRouteService } from "./route.js";
4
4
  import { siteData } from "./hooks/useSite.js";
5
5
  import { isEqualPath } from "./utils.js";
6
- const slots = [
7
- void 0,
8
- void 0,
9
- void 0
10
- ];
11
- function warmPageData(routePath, data) {
12
- slots[0] = {
13
- routePath,
14
- data
15
- };
16
- }
17
- function consumeCachedPageData(routePath) {
18
- if (slots[0]?.routePath === routePath) {
19
- const data = slots[0].data;
20
- slots[2] = slots[1];
21
- slots[1] = slots[0];
22
- slots[0] = void 0;
23
- return data;
24
- }
25
- if (slots[2]?.routePath === routePath) {
26
- const data = slots[2].data;
27
- slots[0] = slots[1];
28
- slots[1] = slots[2];
29
- slots[2] = void 0;
30
- return data;
31
- }
32
- }
33
- function setCurrentPageData(routePath, data) {
34
- slots[2] = slots[1];
35
- slots[1] = {
36
- routePath,
37
- data
38
- };
39
- }
40
6
  async function initPageData(routePath) {
41
7
  const matchedRoute = pathnameToRouteService(routePath);
42
8
  if (matchedRoute) {
@@ -59,16 +25,14 @@ async function initPageData(routePath) {
59
25
  }
60
26
  let lang = siteData.lang || '';
61
27
  let version = siteData.multiVersion?.default || '';
62
- if (siteData.lang && "u" > typeof window) {
63
- const path = window.location.pathname.replace(siteData.base, '').split('/').slice(0, 2);
64
- if (siteData.locales.length) {
65
- const result = siteData.locales.find(({ lang })=>path.includes(lang));
66
- if (result) lang = result.lang;
67
- }
68
- if (siteData.multiVersion.versions) {
69
- const result = siteData.multiVersion.versions.find((version)=>path.includes(version));
70
- if (result) version = result;
71
- }
28
+ const path = routePath.replace(/^\//, '').split('/').slice(0, 2);
29
+ if (siteData.locales.length) {
30
+ const result = siteData.locales.find(({ lang })=>path.includes(lang));
31
+ if (result) lang = result.lang;
32
+ }
33
+ if (siteData.multiVersion.versions) {
34
+ const result = siteData.multiVersion.versions.find((version)=>path.includes(version));
35
+ if (result) version = result;
72
36
  }
73
37
  return {
74
38
  pagePath: '',
@@ -83,4 +47,4 @@ async function initPageData(routePath) {
83
47
  _relativePath: ''
84
48
  };
85
49
  }
86
- export { consumeCachedPageData, initPageData, setCurrentPageData, warmPageData };
50
+ export { initPageData };
@@ -0,0 +1,11 @@
1
+ import type { LoaderFunctionArgs } from 'react-router-dom';
2
+ export declare const PAGE_ROUTE_ID = "rspress-page";
3
+ export declare function pageDataLoader({ request }: LoaderFunctionArgs): Promise<import("@rspress/shared").BaseRuntimePageInfo & {
4
+ [key: string]: unknown;
5
+ headingTitle?: string;
6
+ pagePath: string;
7
+ lastUpdatedTime?: string;
8
+ lastUpdatedAuthor?: string;
9
+ description?: string;
10
+ pageType: import("@rspress/shared").PageType;
11
+ }>;
@@ -0,0 +1,7 @@
1
+ import { initPageData } from "./initPageData.js";
2
+ import { removeBase } from "./utils.js";
3
+ const PAGE_ROUTE_ID = 'rspress-page';
4
+ function pageDataLoader({ request }) {
5
+ return initPageData(removeBase(new URL(request.url).pathname));
6
+ }
7
+ export { PAGE_ROUTE_ID, pageDataLoader };