@rspress/core 2.0.0-beta.10 → 2.0.0-beta.11

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.
package/dist/index.d.ts CHANGED
@@ -162,8 +162,8 @@ export declare class RouteService {
162
162
  getRoutes(): RouteMeta[];
163
163
  isExistRoute(routePath: string): boolean;
164
164
  isEmpty(): boolean;
165
- generateRoutesCode(isStaticImport?: boolean): string;
166
- generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
165
+ generateRoutesCode(): string;
166
+ generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
167
167
  getRoutePathParts(routePath: string): readonly [string, string, string];
168
168
  normalizeRoutePath(routePath: string): {
169
169
  routePath: string;
package/dist/index.js CHANGED
@@ -182,7 +182,7 @@ const pluginVirtualModule = (pluginOptions = {})=>({
182
182
  }
183
183
  }
184
184
  });
185
- var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.10"}');
185
+ var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.11"}');
186
186
  const RSPRESS_VERSION = package_namespaceObject.i8;
187
187
  const isProduction = ()=>'production' === process.env.NODE_ENV;
188
188
  const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
@@ -259,6 +259,9 @@ function hintSSGFailed() {
259
259
  function hintSSGFalse() {
260
260
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('`ssg: false` detected, SSG will be disabled.');
261
261
  }
262
+ function hintReactVersion() {
263
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('[Rspress v2] Rspress support React 18 and 19, please confirm that both react and react-dom are installed in package.json with the same version. ');
264
+ }
262
265
  const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
263
266
  function slash(p) {
264
267
  return p.replace(/\\/g, '/');
@@ -413,21 +416,21 @@ class RouteService {
413
416
  isEmpty() {
414
417
  return 0 === this.routeData.size;
415
418
  }
416
- generateRoutesCode(isStaticImport = false) {
417
- return this.generateRoutesCodeByRouteMeta(this.getRoutes(), isStaticImport);
419
+ generateRoutesCode() {
420
+ return this.generateRoutesCodeByRouteMeta(this.getRoutes());
418
421
  }
419
- generateRoutesCodeByRouteMeta(routeMeta, isStaticImport) {
422
+ generateRoutesCodeByRouteMeta(routeMeta) {
420
423
  return `
421
424
  import React from 'react';
422
425
  import { lazyWithPreload } from "react-lazy-with-preload";
423
- ${routeMeta.map((route, index)=>isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
426
+ ${routeMeta.map((route, index)=>`const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`).join('\n')}
424
427
  export const routes = [
425
428
  ${routeMeta.map((route, index)=>{
426
- const preload = isStaticImport ? `() => Route${index}` : `async () => {
429
+ const preload = `async () => {
427
430
  await Route${index}.preload();
428
431
  return import("${route.absolutePath}");
429
432
  }`;
430
- const component = isStaticImport ? `Route${index}.default` : `Route${index}`;
433
+ const component = `Route${index}`;
431
434
  return `{ path: '${route.routePath}', element: React.createElement(${component}), filePath: '${route.relativePath}', preload: ${preload}, lang: '${route.lang}', version: '${route.version}' }`;
432
435
  }).join(',\n')}
433
436
  ];
@@ -935,7 +938,7 @@ const Props_${index++} = ${JSON.stringify(source[1])};\n`;
935
938
  const routeListVMPlugin = (context)=>{
936
939
  const { routeService } = context;
937
940
  return {
938
- [types_RuntimeModuleID.Routes]: ({ environment })=>'node' === environment.name ? routeService.generateRoutesCode(true) : routeService.generateRoutesCode(false)
941
+ [types_RuntimeModuleID.Routes]: ()=>routeService.generateRoutesCode()
939
942
  };
940
943
  };
941
944
  const searchHookVMPlugin = (context)=>({
@@ -995,6 +998,97 @@ function serveSearchIndexMiddleware(config) {
995
998
  } else next?.();
996
999
  };
997
1000
  }
1001
+ async function pMap(iterable, mapper, { concurrency = Number.POSITIVE_INFINITY, stopOnError = true, signal } = {}) {
1002
+ return new Promise((resolve_, reject_)=>{
1003
+ if (void 0 === iterable[Symbol.iterator] && void 0 === iterable[Symbol.asyncIterator]) throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
1004
+ if ('function' != typeof mapper) throw new TypeError('Mapper function is required');
1005
+ if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === Number.POSITIVE_INFINITY)) throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
1006
+ const result = [];
1007
+ const errors = [];
1008
+ const skippedIndexesMap = new Map();
1009
+ let isRejected = false;
1010
+ let isResolved = false;
1011
+ let isIterableDone = false;
1012
+ let resolvingCount = 0;
1013
+ let currentIndex = 0;
1014
+ const iterator = void 0 === iterable[Symbol.iterator] ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
1015
+ const signalListener = ()=>{
1016
+ reject(signal.reason);
1017
+ };
1018
+ const cleanup = ()=>{
1019
+ signal?.removeEventListener('abort', signalListener);
1020
+ };
1021
+ const resolve = (value)=>{
1022
+ resolve_(value);
1023
+ cleanup();
1024
+ };
1025
+ const reject = (reason)=>{
1026
+ isRejected = true;
1027
+ isResolved = true;
1028
+ reject_(reason);
1029
+ cleanup();
1030
+ };
1031
+ if (signal) {
1032
+ if (signal.aborted) reject(signal.reason);
1033
+ signal.addEventListener('abort', signalListener, {
1034
+ once: true
1035
+ });
1036
+ }
1037
+ const next = async ()=>{
1038
+ if (isResolved) return;
1039
+ const nextItem = await iterator.next();
1040
+ const index = currentIndex;
1041
+ currentIndex++;
1042
+ if (nextItem.done) {
1043
+ isIterableDone = true;
1044
+ if (0 === resolvingCount && !isResolved) {
1045
+ if (!stopOnError && errors.length > 0) return void reject(new AggregateError(errors));
1046
+ isResolved = true;
1047
+ if (0 === skippedIndexesMap.size) return void resolve(result);
1048
+ const pureResult = [];
1049
+ for (const [index, value] of result.entries())if (skippedIndexesMap.get(index) !== pMapSkip) pureResult.push(value);
1050
+ resolve(pureResult);
1051
+ }
1052
+ return;
1053
+ }
1054
+ resolvingCount++;
1055
+ (async ()=>{
1056
+ try {
1057
+ const element = await nextItem.value;
1058
+ if (isResolved) return;
1059
+ const value = await mapper(element, index);
1060
+ if (value === pMapSkip) skippedIndexesMap.set(index, value);
1061
+ result[index] = value;
1062
+ resolvingCount--;
1063
+ await next();
1064
+ } catch (error) {
1065
+ if (stopOnError) reject(error);
1066
+ else {
1067
+ errors.push(error);
1068
+ resolvingCount--;
1069
+ try {
1070
+ await next();
1071
+ } catch (error) {
1072
+ reject(error);
1073
+ }
1074
+ }
1075
+ }
1076
+ })();
1077
+ };
1078
+ (async ()=>{
1079
+ for(let index = 0; index < concurrency; index++){
1080
+ try {
1081
+ await next();
1082
+ } catch (error) {
1083
+ reject(error);
1084
+ break;
1085
+ }
1086
+ if (isIterableDone || isRejected) break;
1087
+ }
1088
+ })();
1089
+ });
1090
+ }
1091
+ const pMapSkip = Symbol('skip');
998
1092
  async function renderFrontmatterHead(route) {
999
1093
  if (!isRouteMeta(route)) return '';
1000
1094
  const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
@@ -1057,7 +1151,8 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
1057
1151
  if (!is404RouteInRoutes) allRoutes.push({
1058
1152
  routePath: '/404'
1059
1153
  });
1060
- await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
1154
+ const filteredRoutes = allRoutes.filter((route)=>!route.routePath.includes(':'));
1155
+ await pMap(filteredRoutes, async (route)=>{
1061
1156
  const head = (0, __WEBPACK_EXTERNAL_MODULE__unhead_react_server_7e85c952__.createHead)();
1062
1157
  const { routePath } = route;
1063
1158
  let appHtml = '';
@@ -1081,7 +1176,9 @@ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, ht
1081
1176
  };
1082
1177
  const fileName = normalizeHtmlFilePath(routePath);
1083
1178
  emitAsset(fileName, html);
1084
- }));
1179
+ }, {
1180
+ concurrency: process.env.RSPRESS_SSG_CONCURRENCY ? Number.parseInt(process.env.RSPRESS_SSG_CONCURRENCY, 10) : 32
1181
+ });
1085
1182
  const totalTime = Date.now() - startTime;
1086
1183
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
1087
1184
  } catch (e) {
@@ -1227,7 +1324,10 @@ async function resolveReactAlias(reactVersion, isSSR) {
1227
1324
  });
1228
1325
  });
1229
1326
  } catch (e) {
1230
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found: \n`, e);
1327
+ if (e instanceof Error) {
1328
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`${lib} not found: \n ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].gray(e.toString())}`);
1329
+ hintReactVersion();
1330
+ }
1231
1331
  }
1232
1332
  }));
1233
1333
  return alias;
@@ -1447,6 +1547,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1447
1547
  entry: {
1448
1548
  index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
1449
1549
  },
1550
+ preEntry: [
1551
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(DEFAULT_THEME, '../styles/index.js'),
1552
+ 'virtual-global-styles'
1553
+ ],
1450
1554
  define: {
1451
1555
  'process.env.__SSR__': JSON.stringify(false)
1452
1556
  }
package/dist/loader.d.ts CHANGED
@@ -64,8 +64,8 @@ declare class RouteService {
64
64
  getRoutes(): RouteMeta[];
65
65
  isExistRoute(routePath: string): boolean;
66
66
  isEmpty(): boolean;
67
- generateRoutesCode(isStaticImport?: boolean): string;
68
- generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[], isStaticImport: boolean): string;
67
+ generateRoutesCode(): string;
68
+ generateRoutesCodeByRouteMeta(routeMeta: RouteMeta[]): string;
69
69
  getRoutePathParts(routePath: string): readonly [string, string, string];
70
70
  normalizeRoutePath(routePath: string): {
71
71
  routePath: string;
@@ -1,12 +1,19 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__ from "react-dom/client";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__ from "./ClientApp.js";
4
5
  import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
5
6
  async function renderInBrowser() {
6
7
  const container = document.getElementById('root');
7
8
  const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(window.location.pathname);
8
- (0, __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__.hydrateRoot)(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
9
- initialPageData: initialPageData
10
- }));
9
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.startTransition)(()=>{
10
+ (0, __WEBPACK_EXTERNAL_MODULE_react_dom_client_76b1397c__.hydrateRoot)(container, /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__ClientApp_js_4935dbba__.ClientApp, {
11
+ initialPageData: initialPageData
12
+ }), {
13
+ onRecoverableError (error, errorInfo) {
14
+ if (error instanceof Error) console.warn('hydrateRoot recoverable error:', error, errorInfo);
15
+ }
16
+ });
17
+ });
11
18
  }
12
19
  renderInBrowser();
@@ -3,13 +3,34 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__ from "@rspress
3
3
  import * as __WEBPACK_EXTERNAL_MODULE__rspress_runtime_server_673c713a__ from "@rspress/runtime/server";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE__unhead_react_server_7e85c952__ from "@unhead/react/server";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__ from "react-dom/server";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_node_stream_444d1c2b__ from "node:stream";
7
+ import * as __WEBPACK_EXTERNAL_MODULE_node_stream_consumers_9c152648__ from "node:stream/consumers";
6
8
  import * as __WEBPACK_EXTERNAL_MODULE__App_js_3638e61b__ from "./App.js";
7
9
  import * as __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__ from "./initPageData.js";
8
10
  import * as __WEBPACK_EXTERNAL_MODULE_virtual_routes_98776429__ from "virtual-routes";
9
11
  const DEFAULT_THEME = 'light';
12
+ async function preloadRoute(pathname) {
13
+ const route = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.pathnameToRouteService)(pathname);
14
+ await route?.preload();
15
+ }
16
+ function renderToHtml(app) {
17
+ return new Promise((resolve, reject)=>{
18
+ const passThrough = new __WEBPACK_EXTERNAL_MODULE_node_stream_444d1c2b__.PassThrough();
19
+ const { pipe } = (0, __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__.renderToPipeableStream)(app, {
20
+ onError (error) {
21
+ reject(error);
22
+ },
23
+ onAllReady () {
24
+ pipe(passThrough);
25
+ (0, __WEBPACK_EXTERNAL_MODULE_node_stream_consumers_9c152648__.text)(passThrough).then(resolve, reject);
26
+ }
27
+ });
28
+ });
29
+ }
10
30
  async function render(pagePath, head) {
11
31
  const initialPageData = await (0, __WEBPACK_EXTERNAL_MODULE__initPageData_js_731596b5__.initPageData)(pagePath);
12
- const appHtml = (0, __WEBPACK_EXTERNAL_MODULE_react_dom_server_98c38d5c__.renderToString)(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
32
+ await preloadRoute(pagePath);
33
+ const appHtml = await renderToHtml(/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.ThemeContext.Provider, {
13
34
  value: {
14
35
  theme: DEFAULT_THEME
15
36
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.11",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -71,14 +71,14 @@
71
71
  "unified": "^11.0.5",
72
72
  "unist-util-visit": "^5.0.0",
73
73
  "unist-util-visit-children": "^3.0.0",
74
- "@rspress/plugin-container-syntax": "2.0.0-beta.10",
75
- "@rspress/plugin-last-updated": "2.0.0-beta.10",
76
- "@rspress/plugin-medium-zoom": "2.0.0-beta.10",
77
- "@rspress/plugin-shiki": "2.0.0-beta.10",
78
- "@rspress/runtime": "2.0.0-beta.10",
79
- "@rspress/theme-default": "2.0.0-beta.10",
80
- "@rspress/shared": "2.0.0-beta.10",
81
- "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.10"
74
+ "@rspress/plugin-container-syntax": "2.0.0-beta.11",
75
+ "@rspress/plugin-auto-nav-sidebar": "2.0.0-beta.11",
76
+ "@rspress/plugin-last-updated": "2.0.0-beta.11",
77
+ "@rspress/plugin-medium-zoom": "2.0.0-beta.11",
78
+ "@rspress/plugin-shiki": "2.0.0-beta.11",
79
+ "@rspress/runtime": "2.0.0-beta.11",
80
+ "@rspress/theme-default": "2.0.0-beta.11",
81
+ "@rspress/shared": "2.0.0-beta.11"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@microsoft/api-extractor": "^7.52.8",
@@ -90,9 +90,10 @@
90
90
  "@types/lodash-es": "^4.17.12",
91
91
  "@types/mdast": "^4.0.4",
92
92
  "@types/node": "^22.8.1",
93
- "@types/react": "^18.3.22",
94
- "@types/react-dom": "^18.3.7",
93
+ "@types/react": "^19.1.6",
94
+ "@types/react-dom": "^19.1.6",
95
95
  "memfs": "^4.17.2",
96
+ "p-map": "^7.0.3",
96
97
  "postcss": "8.5.3",
97
98
  "rehype-stringify": "^10.0.1",
98
99
  "remark-mdx": "^3.1.0",