@rspress/core 2.0.23 → 2.1.0-beta.1

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 (104) hide show
  1. package/dist/b~0.js +1 -3
  2. package/dist/cli/index.js +1 -1
  3. package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
  4. package/dist/config/loadConfigFile.js +1 -1
  5. package/dist/eject-theme/components/Link/getHref.ts +1 -0
  6. package/dist/eject-theme/components/Link/index.tsx +0 -3
  7. package/dist/eject-theme/components/Link/useLinkNavigate.ts +29 -54
  8. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
  9. package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
  10. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
  11. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
  12. package/dist/entry/worker.js +1 -1
  13. package/dist/{a~0.js → h~0.js} +18 -15
  14. package/dist/index.d.ts +1 -1
  15. package/dist/node/PluginDriver.js +8 -2
  16. package/dist/node/auto-nav-sidebar/index.js +1 -1
  17. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  18. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  19. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  20. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  21. package/dist/node/eject.js +1 -1
  22. package/dist/node/initRsbuild.js +8 -4
  23. package/dist/node/llms.d.ts +1 -1
  24. package/dist/node/llms.js +2 -2
  25. package/dist/node/logger/hint.d.ts +1 -0
  26. package/dist/node/logger/hint.js +8 -2
  27. package/dist/node/route/RoutePage.js +1 -1
  28. package/dist/node/route/RouteService.js +1 -1
  29. package/dist/node/route/extractPageData.js +1 -1
  30. package/dist/node/route/normalizeRoutePath.js +1 -1
  31. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +28 -0
  32. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
  33. package/dist/node/runtimeModule/i18n.js +1 -1
  34. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  35. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  36. package/dist/node/runtimeModule/searchHooks.js +2 -2
  37. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  38. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  39. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  40. package/dist/node/serve.js +1 -1
  41. package/dist/node/sitemap.d.ts +2 -0
  42. package/dist/node/sitemap.js +103 -0
  43. package/dist/node/ssg/alternateLinks.js +1 -1
  44. package/dist/node/ssg/renderPages.js +1 -1
  45. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  46. package/dist/node/ssg/ssgEnv.js +1 -1
  47. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  48. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  49. package/dist/node/ssg-md/renderPage.js +5 -4
  50. package/dist/node/ssg-md/renderPages.js +1 -1
  51. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  52. package/dist/node/utils/checkLanguageParity.js +1 -1
  53. package/dist/node/utils/createHash.js +1 -1
  54. package/dist/node/utils/flattenMdxContent.js +1 -1
  55. package/dist/node/utils/getPageKey.js +1 -1
  56. package/dist/node/utils/reactAlias.js +5 -2
  57. package/dist/runtime/App.js +12 -25
  58. package/dist/runtime/ClientApp.d.ts +3 -2
  59. package/dist/runtime/ClientApp.js +27 -21
  60. package/dist/runtime/ErrorRoute.d.ts +1 -0
  61. package/dist/runtime/ErrorRoute.js +30 -0
  62. package/dist/runtime/PageRoute.d.ts +2 -0
  63. package/dist/runtime/PageRoute.js +58 -0
  64. package/dist/runtime/createServerRouter.d.ts +4 -0
  65. package/dist/runtime/createServerRouter.js +17 -0
  66. package/dist/runtime/csrClientEntry.js +5 -2
  67. package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
  68. package/dist/runtime/hooks/useWebMcp.js +80 -0
  69. package/dist/runtime/index.d.ts +3 -1
  70. package/dist/runtime/index.js +3 -1
  71. package/dist/runtime/initPageData.d.ts +0 -3
  72. package/dist/runtime/initPageData.js +9 -45
  73. package/dist/runtime/pageDataLoader.d.ts +11 -0
  74. package/dist/runtime/pageDataLoader.js +7 -0
  75. package/dist/runtime/ssrClientEntry.js +14 -6
  76. package/dist/runtime/ssrMdServerEntry.js +10 -21
  77. package/dist/runtime/ssrServerEntry.js +10 -21
  78. package/dist/static/assets/package.json +58 -0
  79. package/dist/theme/components/Link/index.js +0 -4
  80. package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
  81. package/dist/theme/components/Link/useLinkNavigate.js +13 -35
  82. package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
  83. package/dist/theme/components/Search/useSearchPanel.js +74 -26
  84. package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
  85. package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
  86. package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
  87. package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
  88. package/dist/theme/hooks/useWebMcpPageList.js +25 -0
  89. package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
  90. package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
  91. package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
  92. package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
  93. package/dist/theme/index.d.ts +5 -0
  94. package/dist/theme/index.js +5 -0
  95. package/dist/theme/layout/ErrorLayout/index.css +52 -0
  96. package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
  97. package/dist/theme/layout/ErrorLayout/index.js +76 -0
  98. package/dist/theme/webMcp/tools.d.ts +56 -0
  99. package/dist/theme/webMcp/tools.js +122 -0
  100. package/dist/theme/webMcp/types.d.ts +35 -0
  101. package/dist/theme/webMcp/types.js +0 -0
  102. package/dist/tinypool~0.js +19 -49
  103. package/dist/tu~0.js +3 -0
  104. package/package.json +12 -12
@@ -0,0 +1,58 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import nprogress from "nprogress";
3
+ import { useCallback, useEffect, useMemo, useState } from "react";
4
+ import { 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
+ id: PAGE_ROUTE_ID,
50
+ path: '*',
51
+ loader: pageDataLoader,
52
+ element: /*#__PURE__*/ jsx(PageRoute, {}),
53
+ errorElement: /*#__PURE__*/ jsx(ErrorRoute, {}),
54
+ hydrateFallbackElement: /*#__PURE__*/ jsx(Fragment, {})
55
+ }
56
+ ];
57
+ }
58
+ 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,8 +17,9 @@ 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
24
  export { safePreconnect, safePreload } from './reactDom.js';
23
25
  export { isActive, pathnameToRouteService, preloadLink } from './route.js';
@@ -9,6 +9,7 @@ export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
9
9
  export { ThemeContext, useDark } from "./hooks/useDark.js";
10
10
  export { useFrontmatter } from "./hooks/useFrontmatter.js";
11
11
  export { useI18n } from "./hooks/useI18n.js";
12
+ export { useI18nText } from "./hooks/useI18nText.js";
12
13
  export { useLang } from "./hooks/useLang.js";
13
14
  export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
14
15
  export { useNav } from "./hooks/useNav.js";
@@ -18,8 +19,9 @@ export { searchIndexHash, usePages } from "./hooks/usePages.js";
18
19
  export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
19
20
  export { useSite } from "./hooks/useSite.js";
20
21
  export { useVersion } from "./hooks/useVersion.js";
22
+ export { useWebMcp } from "./hooks/useWebMcp.js";
21
23
  export { useWindowSize } from "./hooks/useWindowSize.js";
22
- export { initPageData, warmPageData } from "./initPageData.js";
24
+ export { initPageData } from "./initPageData.js";
23
25
  export { NoSSR } from "./NoSSR.js";
24
26
  export { safePreconnect, safePreload } from "./reactDom.js";
25
27
  export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
@@ -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 };
@@ -1,19 +1,27 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { removeBase } from "@rspress/core/runtime";
3
3
  import { startTransition } from "react";
4
- import { hydrateRoot } from "react-dom/client";
5
- import { ClientApp } from "./ClientApp.js";
6
- import { initPageData, setCurrentPageData } from "./initPageData.js";
4
+ import { createRoot, hydrateRoot } from "react-dom/client";
5
+ import { ClientApp, createClientRouter } from "./ClientApp.js";
6
+ import { initPageData } from "./initPageData.js";
7
7
  import { redirectToCleanUrl } from "./route.js";
8
8
  async function renderInBrowser() {
9
9
  redirectToCleanUrl(window.location, window.history);
10
10
  const container = document.getElementById('__rspress_root');
11
11
  const pathname = removeBase(window.location.pathname);
12
- const initialPageData = await initPageData(pathname);
13
- setCurrentPageData(pathname, initialPageData);
12
+ let initialPageData;
13
+ try {
14
+ initialPageData = await initPageData(pathname);
15
+ } catch {
16
+ createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {
17
+ router: createClientRouter()
18
+ }));
19
+ return;
20
+ }
21
+ const router = createClientRouter(initialPageData);
14
22
  startTransition(()=>{
15
23
  hydrateRoot(container, /*#__PURE__*/ jsx(ClientApp, {
16
- initialPageData: initialPageData
24
+ router: router
17
25
  }), {
18
26
  onRecoverableError (error, errorInfo) {
19
27
  if (error instanceof Error) console.warn('hydrateRoot recoverable error:', error, errorInfo);
@@ -1,33 +1,22 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/core/runtime";
2
+ import { ThemeContext } from "@rspress/core/runtime";
3
3
  import { UnheadProvider } from "@unhead/react/server";
4
4
  import { renderToMarkdownString } from "react-render-to-markdown";
5
- import { StaticRouter } from "react-router-dom";
6
- import { App } from "./App.js";
7
- import { initPageData } from "./initPageData.js";
5
+ import { StaticRouterProvider } from "virtual-react-router-server";
6
+ import { createServerRouter } from "./createServerRouter.js";
8
7
  const DEFAULT_THEME = 'light';
9
- async function preloadRoute(pathname) {
10
- const route = pathnameToRouteService(pathname);
11
- await route?.preload();
12
- }
13
8
  async function render(routePath, head) {
14
- const initialPageData = await initPageData(routePath);
15
- await preloadRoute(routePath);
9
+ const { router, context } = await createServerRouter(routePath);
16
10
  const appMd = await renderToMarkdownString(/*#__PURE__*/ jsx(ThemeContext.Provider, {
17
11
  value: {
18
12
  theme: DEFAULT_THEME
19
13
  },
20
- children: /*#__PURE__*/ jsx(PageContext.Provider, {
21
- value: {
22
- data: initialPageData
23
- },
24
- children: /*#__PURE__*/ jsx(StaticRouter, {
25
- location: withBase(routePath),
26
- basename: removeTrailingSlash(withBase('/')),
27
- children: /*#__PURE__*/ jsx(UnheadProvider, {
28
- value: head,
29
- children: /*#__PURE__*/ jsx(App, {})
30
- })
14
+ children: /*#__PURE__*/ jsx(UnheadProvider, {
15
+ value: head,
16
+ children: /*#__PURE__*/ jsx(StaticRouterProvider, {
17
+ router: router,
18
+ context: context,
19
+ hydrate: false
31
20
  })
32
21
  })
33
22
  }));
@@ -1,17 +1,12 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { PassThrough } from "node:stream";
3
3
  import { text as consumers_text } from "node:stream/consumers";
4
- import { PageContext, ThemeContext, pathnameToRouteService, removeTrailingSlash, withBase } from "@rspress/core/runtime";
4
+ import { ThemeContext } from "@rspress/core/runtime";
5
5
  import { UnheadProvider } from "@unhead/react/server";
6
6
  import { renderToPipeableStream } from "react-dom/server";
7
- import { StaticRouter } from "react-router-dom";
8
- import { App } from "./App.js";
9
- import { initPageData } from "./initPageData.js";
7
+ import { StaticRouterProvider } from "virtual-react-router-server";
8
+ import { createServerRouter } from "./createServerRouter.js";
10
9
  const DEFAULT_THEME = 'light';
11
- async function preloadRoute(pathname) {
12
- const route = pathnameToRouteService(pathname);
13
- await route?.preload();
14
- }
15
10
  function renderToHtml(app) {
16
11
  return new Promise((resolve, reject)=>{
17
12
  const passThrough = new PassThrough();
@@ -28,23 +23,17 @@ function renderToHtml(app) {
28
23
  });
29
24
  }
30
25
  async function render(routePath, head) {
31
- const initialPageData = await initPageData(routePath);
32
- await preloadRoute(routePath);
26
+ const { router, context } = await createServerRouter(routePath);
33
27
  const appHtml = await renderToHtml(/*#__PURE__*/ jsx(ThemeContext.Provider, {
34
28
  value: {
35
29
  theme: DEFAULT_THEME
36
30
  },
37
- children: /*#__PURE__*/ jsx(PageContext.Provider, {
38
- value: {
39
- data: initialPageData
40
- },
41
- children: /*#__PURE__*/ jsx(StaticRouter, {
42
- location: withBase(routePath),
43
- basename: removeTrailingSlash(withBase('/')),
44
- children: /*#__PURE__*/ jsx(UnheadProvider, {
45
- value: head,
46
- children: /*#__PURE__*/ jsx(App, {})
47
- })
31
+ children: /*#__PURE__*/ jsx(UnheadProvider, {
32
+ value: head,
33
+ children: /*#__PURE__*/ jsx(StaticRouterProvider, {
34
+ router: router,
35
+ context: context,
36
+ hydrate: false
48
37
  })
49
38
  })
50
39
  }));
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "tinypool",
3
+ "type": "module",
4
+ "version": "2.2.0",
5
+ "description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/tinylibs/tinypool#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/tinylibs/tinypool.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/tinylibs/tinypool/issues"
14
+ },
15
+ "keywords": [
16
+ "fast",
17
+ "worker threads",
18
+ "thread pool"
19
+ ],
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "engines": {
34
+ "node": "^20.0.0 || >=22.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^20.12.8",
38
+ "clean-publish": "^3.4.4",
39
+ "eslint": "^9.4.0",
40
+ "eslint-config-prettier": "^9.1.0",
41
+ "eslint-plugin-prettier": "^5.1.3",
42
+ "eslint-plugin-unicorn": "^53.0.0",
43
+ "prettier": "^3.3.2",
44
+ "tsdown": "^0.11.3",
45
+ "typescript": "^5.4.5",
46
+ "typescript-eslint": "^7.13.0",
47
+ "vite": "^5.2.11",
48
+ "vitest": "^4.0.1"
49
+ },
50
+ "scripts": {
51
+ "test": "vitest",
52
+ "bench": "vitest bench",
53
+ "dev": "tsdown --watch ./src",
54
+ "build": "tsdown",
55
+ "lint": "eslint --max-warnings=0",
56
+ "typecheck": "tsc --noEmit"
57
+ }
58
+ }
@@ -1,14 +1,10 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { preloadLink } from "@rspress/core/runtime";
3
3
  import clsx from "clsx";
4
- import nprogress from "nprogress";
5
4
  import { forwardRef } from "react";
6
5
  import "./index.css";
7
6
  import { getHref } from "./getHref.js";
8
7
  import { useLinkNavigate } from "./useLinkNavigate.js";
9
- nprogress.configure({
10
- showSpinner: false
11
- });
12
8
  const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
13
9
  const { href = '/', children, className = '', onClick, onMouseEnter, startTransition, ...otherProps } = props;
14
10
  const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
@@ -1,7 +1,7 @@
1
1
  import { type TransitionStartFunction } from 'react';
2
2
  /**
3
- * For import { Link } from '@rspress/core/theme';
4
- * useNavigate with preload logic
3
+ * Navigate with Rspress link normalization. The router loader handles page
4
+ * loading for both this helper and the native useNavigate hook.
5
5
  */
6
6
  export declare function useLinkNavigate({ startTransition, }?: {
7
7
  startTransition?: TransitionStartFunction;
@@ -1,48 +1,26 @@
1
- import { initPageData, isActive, pathnameToRouteService, useLocation, useNavigate, useSite, warmPageData } from "@rspress/core/runtime";
2
- import nprogress from "nprogress";
3
- import { startTransition as external_react_startTransition, useCallback } from "react";
1
+ import { isActive, pathnameToRouteService, useLocation, useNavigate, useSite } from "@rspress/core/runtime";
2
+ import { useCallback } from "react";
4
3
  import { getHref } from "./getHref.js";
5
- nprogress.configure({
6
- showSpinner: false
7
- });
8
- function useLinkNavigate({ startTransition = external_react_startTransition } = {
9
- startTransition: external_react_startTransition
10
- }) {
11
- const { pathname: currPagePathname } = useLocation();
4
+ function useLinkNavigate({ startTransition } = {}) {
5
+ const { pathname } = useLocation();
12
6
  const navigate = useNavigate();
13
7
  const { site } = useSite();
14
8
  const useTransitions = site?.route?.useTransitions;
15
9
  return useCallback(async (href)=>{
16
10
  const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
17
11
  if ('external' === linkType || 'hashOnly' === linkType) return void window.location.assign(href);
18
- const isTransitionable = !!(useTransitions && startTransition);
19
- const preloadChunkThenNavigate = async ()=>{
20
- const inCurrPage = isActive(removeBaseHref, currPagePathname);
21
- if (!import.meta.env.SSR && !inCurrPage) {
22
- const matchedRoute = pathnameToRouteService(routePath);
23
- if (!matchedRoute) return void window.location.assign(withBaseHref);
24
- else {
25
- const timer = setTimeout(()=>{
26
- nprogress.start();
27
- }, 200);
28
- const data = await initPageData(routePath);
29
- warmPageData(routePath, data);
30
- clearTimeout(timer);
31
- nprogress.done();
32
- }
33
- }
34
- if (isTransitionable) startTransition(()=>navigate(removeBaseHref, {
35
- replace: false
36
- }));
37
- else navigate(removeBaseHref, {
38
- replace: false
12
+ if (!isActive(removeBaseHref, pathname) && !pathnameToRouteService(routePath)) return void window.location.assign(withBaseHref);
13
+ if (useTransitions && startTransition) {
14
+ let navigation;
15
+ startTransition(()=>{
16
+ navigation = navigate(removeBaseHref);
17
+ return navigation;
39
18
  });
40
- };
41
- if (isTransitionable) startTransition(preloadChunkThenNavigate);
42
- else preloadChunkThenNavigate();
19
+ await navigation;
20
+ } else await navigate(removeBaseHref);
43
21
  }, [
44
22
  useTransitions,
45
- currPagePathname,
23
+ pathname,
46
24
  navigate,
47
25
  startTransition
48
26
  ]);
@@ -47,7 +47,10 @@ class LocalProvider {
47
47
  if (this.#fetchPromise) return this.#fetchPromise;
48
48
  const { currentLang, currentVersion } = options;
49
49
  const versioned = options.versioned ?? true;
50
- this.#fetchPromise = this.#getPages(currentLang, versioned ? currentVersion : '');
50
+ this.#fetchPromise = this.#getPages(currentLang, versioned ? currentVersion : '').catch((error)=>{
51
+ this.#fetchPromise = void 0;
52
+ throw error;
53
+ });
51
54
  return this.#fetchPromise;
52
55
  }
53
56
  async init(options) {