@rspress/core 2.0.15 → 2.0.17

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 (99) hide show
  1. package/bin/rspress.js +6 -1
  2. package/dist/0~execa.js +1 -1
  3. package/dist/{9882.js → 102.js} +1 -1
  4. package/dist/{9958.js → 7448.js} +1 -1
  5. package/dist/{5580.js → 8629.js} +2455 -6
  6. package/dist/cli/index.d.ts +8 -1
  7. package/dist/cli/index.js +105 -102
  8. package/dist/config/loadConfigFile.js +1 -1
  9. package/dist/eject-theme/components/Callout/index.scss +32 -0
  10. package/dist/eject-theme/components/Callout/index.tsx +9 -1
  11. package/dist/eject-theme/components/Link/index.tsx +1 -1
  12. package/dist/eject-theme/components/Link/useLinkNavigate.ts +17 -4
  13. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -1
  14. package/dist/eject-theme/components/Overview/index.tsx +1 -2
  15. package/dist/eject-theme/components/Overview/utils.ts +4 -10
  16. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +3 -1
  17. package/dist/eject-theme/components/SidebarMenu/useClickOutside.ts +1 -2
  18. package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +48 -0
  19. package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +35 -20
  20. package/dist/index.d.ts +2 -1
  21. package/dist/index.js +2 -1
  22. package/dist/node/PluginDriver.js +1 -1
  23. package/dist/node/auto-nav-sidebar/index.js +1 -1
  24. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  25. package/dist/node/auto-nav-sidebar/normalize.js +2 -2
  26. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  27. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  28. package/dist/node/constants.js +1 -1
  29. package/dist/node/eject.js +2 -2
  30. package/dist/node/initRsbuild.js +5 -5
  31. package/dist/node/logger/hint.js +1 -1
  32. package/dist/node/mdx/options.js +1 -1
  33. package/dist/node/mdx/processor.js +1 -1
  34. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  35. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  36. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  37. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  38. package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +2 -1
  39. package/dist/node/mdx/remarkPlugins/containerSyntax.js +13 -6
  40. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +2 -2
  41. package/dist/node/mdx/remarkPlugins/image.js +2 -2
  42. package/dist/node/mdx/remarkPlugins/link.js +2 -2
  43. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  44. package/dist/node/medium-zoom/index.js +1 -1
  45. package/dist/node/route/RoutePage.js +1 -1
  46. package/dist/node/route/RouteService.js +1 -1
  47. package/dist/node/route/extractPageData.js +1 -1
  48. package/dist/node/route/normalizeRoutePath.js +1 -1
  49. package/dist/node/runtimeModule/i18n.js +3 -3
  50. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  51. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  52. package/dist/node/runtimeModule/searchHooks.js +1 -1
  53. package/dist/node/runtimeModule/siteData/createSiteData.js +6 -2
  54. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  55. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  56. package/dist/node/serve.js +1 -1
  57. package/dist/node/ssg/htmlFile.js +1 -1
  58. package/dist/node/ssg/renderPage.js +2 -2
  59. package/dist/node/ssg/renderPageWorker.js +2 -2
  60. package/dist/node/ssg/renderPages.js +3 -3
  61. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  62. package/dist/node/ssg/ssgEnv.js +1 -1
  63. package/dist/node/ssg-md/llms/emitLlmsTxt.js +3 -3
  64. package/dist/node/ssg-md/llms/llmsTxt.d.ts +3 -3
  65. package/dist/node/ssg-md/llms/llmsTxt.js +8 -8
  66. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  67. package/dist/node/ssg-md/renderPage.js +2 -2
  68. package/dist/node/ssg-md/renderPages.js +3 -3
  69. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  70. package/dist/node/utils/checkLanguageParity.js +1 -1
  71. package/dist/node/utils/createHash.js +1 -1
  72. package/dist/node/utils/error.js +1 -1
  73. package/dist/node/utils/flattenMdxContent.js +1 -1
  74. package/dist/node/utils/fs.js +1 -1
  75. package/dist/node/utils/getPageKey.js +1 -1
  76. package/dist/node/utils/normalizePath.js +1 -1
  77. package/dist/node/utils/reactAlias.js +2 -2
  78. package/dist/runtime/App.js +1 -1
  79. package/dist/runtime/ClientApp.js +4 -2
  80. package/dist/runtime/route.js +2 -0
  81. package/dist/theme/components/Callout/index.css +29 -0
  82. package/dist/theme/components/Callout/index.d.ts +1 -1
  83. package/dist/theme/components/DocContent/docComponents/index.d.ts +25 -18
  84. package/dist/theme/components/Link/index.d.ts +1 -1
  85. package/dist/theme/components/Link/useLinkNavigate.d.ts +1 -1
  86. package/dist/theme/components/Link/useLinkNavigate.js +13 -5
  87. package/dist/theme/components/Llms/LlmsContainer.d.ts +1 -2
  88. package/dist/theme/components/Search/SearchPanel.js +8 -8
  89. package/dist/theme/components/SocialLinks/GithubStars.js +27 -17
  90. package/dist/theme/logic/getCopyableText.js +1 -0
  91. package/package.json +12 -12
  92. package/dist/6010.js +0 -2461
  93. package/dist/{0~8787.js → 0~8016.js} +0 -0
  94. package/dist/{7986.js → 4538.js} +0 -0
  95. package/dist/{3358.js → 5357.js} +0 -0
  96. package/dist/{8005.js → 7748.js} +2 -2
  97. /package/dist/{5580.js.LICENSE.txt → 8629.js.LICENSE.txt} +0 -0
  98. /package/dist/{6646.js → 9857.js} +0 -0
  99. /package/dist/{9283.js → 9940.js} +0 -0
@@ -1 +1,8 @@
1
- export {};
1
+ export type RunCLIOptions = {
2
+ /**
3
+ * The command-line arguments to parse, matching the shape of Node.js `process.argv`
4
+ * @default process.argv
5
+ */
6
+ argv?: string[];
7
+ };
8
+ export declare function runCLI({ argv }?: RunCLIOptions): void;
package/dist/cli/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { __webpack_require__ } from "../0~rslib-runtime.js";
2
- import { node_path, logger, join, cac } from "../5580.js";
3
- import "../7986.js";
4
- import { package_namespaceObject } from "../9958.js";
2
+ import { node_path, logger, join, cac } from "../8629.js";
3
+ import "../4538.js";
4
+ import { package_namespaceObject } from "../7448.js";
5
5
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
6
6
  import { dev } from "../node/dev.js";
7
7
  import { build } from "../node/build.js";
@@ -14,115 +14,118 @@ const META_FILES = [
14
14
  '_meta.json',
15
15
  '_nav.json'
16
16
  ];
17
- const cli = cac('rspress').version(package_namespaceObject.rE).help();
18
- const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
19
- logger.greet(landingMessage);
20
17
  const setNodeEnv = (env)=>{
21
18
  process.env.NODE_ENV = env;
22
19
  };
23
- cli.option('-c,--config [config]', 'Specify the path to the config file');
24
- cli.command('[root]', 'start dev server').alias('dev').option('--port [port]', 'port number').option('--host [host]', 'hostname').option('--base <base>', 'deployment base path').action(async (root, options)=>{
25
- setNodeEnv('development');
26
- let isRestarting = false;
27
- const cwd = process.cwd();
28
- let cliWatcher;
29
- let devServer;
30
- const startDevServer = async ()=>{
31
- const { port, host } = options || {};
32
- const { config, configFilePath } = await loadConfigFile(options?.config);
33
- config.root = resolveDocRoot(cwd, root, config.root);
34
- if (options?.base) config.base = options.base;
35
- const docDirectory = config.root;
36
- devServer = await dev({
37
- appDirectory: cwd,
38
- docDirectory,
39
- config,
40
- configFilePath,
41
- extraBuilderConfig: {
42
- server: {
43
- port,
44
- host
20
+ function runCLI({ argv = process.argv } = {}) {
21
+ const cli = cac('rspress').version(package_namespaceObject.rE).help();
22
+ const landingMessage = `🔥 Rspress v${package_namespaceObject.rE}\n`;
23
+ logger.greet(landingMessage);
24
+ cli.option('-c, --config <config>', 'Set the configuration file (relative or absolute path)');
25
+ cli.command('[root]', 'Start the dev server').alias('dev').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
26
+ setNodeEnv('development');
27
+ let isRestarting = false;
28
+ const cwd = process.cwd();
29
+ let cliWatcher;
30
+ let devServer;
31
+ const startDevServer = async ()=>{
32
+ const { port, host } = options || {};
33
+ const { config, configFilePath } = await loadConfigFile(options?.config);
34
+ config.root = resolveDocRoot(cwd, root, config.root);
35
+ if (options?.base) config.base = options.base;
36
+ const docDirectory = config.root;
37
+ devServer = await dev({
38
+ appDirectory: cwd,
39
+ docDirectory,
40
+ config,
41
+ configFilePath,
42
+ extraBuilderConfig: {
43
+ server: {
44
+ port,
45
+ host
46
+ }
45
47
  }
46
- }
47
- });
48
- cliWatcher = chokidar.w([
49
- configFilePath,
50
- docDirectory
51
- ], {
52
- ignoreInitial: true,
53
- ignored: [
54
- '**/node_modules/**',
55
- '**/.git/**',
56
- '**/.DS_Store/**',
57
- join(docDirectory, "public")
58
- ]
59
- });
60
- cliWatcher.on('all', async (eventName, filepath)=>{
61
- const basename = node_path.basename(filepath);
62
- if ('change' === eventName && META_FILES.includes(basename)) return;
63
- if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
64
- if (isRestarting) return;
65
- isRestarting = true;
66
- console.log(`\n✨ ${eventName} ${picocolors_default().green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
48
+ });
49
+ cliWatcher = chokidar.w([
50
+ configFilePath,
51
+ docDirectory
52
+ ], {
53
+ ignoreInitial: true,
54
+ ignored: [
55
+ '**/node_modules/**',
56
+ '**/.git/**',
57
+ '**/.DS_Store/**',
58
+ join(docDirectory, "public")
59
+ ]
60
+ });
61
+ cliWatcher.on('all', async (eventName, filepath)=>{
62
+ const basename = node_path.basename(filepath);
63
+ if ('change' === eventName && META_FILES.includes(basename)) return;
64
+ if ('add' === eventName || 'unlink' === eventName || 'change' === eventName && filepath === configFilePath) {
65
+ if (isRestarting) return;
66
+ isRestarting = true;
67
+ console.log(`\n✨ ${eventName} ${picocolors_default().green(node_path.relative(cwd, filepath))}, dev server will restart...\n`);
68
+ await devServer.close();
69
+ await cliWatcher.close();
70
+ await startDevServer();
71
+ isRestarting = false;
72
+ }
73
+ });
74
+ };
75
+ await startDevServer();
76
+ const exitProcess = async ()=>{
77
+ try {
67
78
  await devServer.close();
68
79
  await cliWatcher.close();
69
- await startDevServer();
70
- isRestarting = false;
80
+ } finally{
81
+ process.exit(0);
71
82
  }
72
- });
73
- };
74
- await startDevServer();
75
- const exitProcess = async ()=>{
83
+ };
84
+ process.on('SIGINT', exitProcess);
85
+ process.on('SIGTERM', exitProcess);
86
+ });
87
+ cli.command('build [root]', 'Build the documentation site for production').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
88
+ setNodeEnv('production');
89
+ const cwd = process.cwd();
90
+ const { config, configFilePath } = await loadConfigFile(options.config);
91
+ config.root = resolveDocRoot(cwd, root, config.root);
92
+ if (options.base) config.base = options.base;
93
+ const docDirectory = config.root;
76
94
  try {
77
- await devServer.close();
78
- await cliWatcher.close();
79
- } finally{
80
- process.exit(0);
95
+ await build({
96
+ docDirectory,
97
+ config,
98
+ configFilePath
99
+ });
100
+ } catch (err) {
101
+ logger.error(err);
102
+ process.exit(1);
81
103
  }
82
- };
83
- process.on('SIGINT', exitProcess);
84
- process.on('SIGTERM', exitProcess);
85
- });
86
- cli.command('build [root]').option('--base <base>', 'deployment base path').action(async (root, options)=>{
87
- setNodeEnv('production');
88
- const cwd = process.cwd();
89
- const { config, configFilePath } = await loadConfigFile(options.config);
90
- config.root = resolveDocRoot(cwd, root, config.root);
91
- if (options.base) config.base = options.base;
92
- const docDirectory = config.root;
93
- try {
94
- await build({
95
- docDirectory,
104
+ });
105
+ cli.command('preview [root]', 'Preview the production build locally').alias('serve').option('--port <port>', 'Set the port number for the server').option('--host [host]', 'Set the host that the server listens to').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
106
+ setNodeEnv('production');
107
+ const cwd = process.cwd();
108
+ const { port, host } = options || {};
109
+ const { config, configFilePath } = await loadConfigFile(options?.config);
110
+ config.root = resolveDocRoot(cwd, root, config.root);
111
+ if (options?.base) config.base = options.base;
112
+ await serve({
96
113
  config,
114
+ host,
115
+ port,
97
116
  configFilePath
98
117
  });
99
- } catch (err) {
100
- logger.error(err);
101
- process.exit(1);
102
- }
103
- });
104
- cli.command('preview [root]').alias('serve').option('--port [port]', 'port number').option('--host [host]', 'hostname').option('--base <base>', 'deployment base path').action(async (root, options)=>{
105
- setNodeEnv('production');
106
- const cwd = process.cwd();
107
- const { port, host } = options || {};
108
- const { config, configFilePath } = await loadConfigFile(options?.config);
109
- config.root = resolveDocRoot(cwd, root, config.root);
110
- if (options?.base) config.base = options.base;
111
- await serve({
112
- config,
113
- host,
114
- port,
115
- configFilePath
116
118
  });
117
- });
118
- cli.command('eject [component]', 'Eject a theme component to customize it').action(async (component)=>{
119
- if (!component) return void await listComponents();
120
- const cwd = process.cwd();
121
- try {
122
- await ejectComponent(component, cwd);
123
- } catch (error) {
124
- logger.error(`Failed to eject component: ${error}`);
125
- process.exit(1);
126
- }
127
- });
128
- cli.parse();
119
+ cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
120
+ if (!component) return void await listComponents();
121
+ const cwd = process.cwd();
122
+ try {
123
+ await ejectComponent(component, cwd);
124
+ } catch (error) {
125
+ logger.error(`Failed to eject component: ${error}`);
126
+ process.exit(1);
127
+ }
128
+ });
129
+ cli.parse(argv);
130
+ }
131
+ export { runCLI };
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../5580.js";
1
+ import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../8629.js";
2
2
  const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
3
3
  async function loadConfigFile(customConfigFile) {
4
4
  const baseDir = process.cwd();
@@ -18,6 +18,11 @@
18
18
  --rp-container-info-bg: rgba(0, 149, 255, 0.06);
19
19
  --rp-container-info-code-bg: rgba(0, 149, 255, 0.1);
20
20
 
21
+ --rp-container-important-border: rgba(137, 87, 229, 0.3);
22
+ --rp-container-important-text: #8250df;
23
+ --rp-container-important-bg: rgba(137, 87, 229, 0.08);
24
+ --rp-container-important-code-bg: rgba(137, 87, 229, 0.1);
25
+
21
26
  --rp-container-warning-border: rgba(255, 197, 23, 0.4);
22
27
  --rp-container-warning-text: #887233;
23
28
  --rp-container-warning-bg: rgba(255, 197, 23, 0.1);
@@ -52,6 +57,10 @@
52
57
  --rp-container-info-text: #66c2ff;
53
58
  --rp-container-info-bg: rgba(0, 149, 255, 0.1);
54
59
 
60
+ --rp-container-important-text: #b083f0;
61
+ --rp-container-important-border: rgba(137, 87, 229, 0.35);
62
+ --rp-container-important-bg: rgba(137, 87, 229, 0.12);
63
+
55
64
  --rp-container-warning-text: rgb(251, 180, 81);
56
65
  --rp-container-warning-border: rgba(255, 197, 23, 0.25);
57
66
  --rp-container-warning-bg: rgba(255, 197, 23, 0.12);
@@ -176,6 +185,29 @@
176
185
  }
177
186
  }
178
187
 
188
+ // important
189
+ .rp-callout--important {
190
+ border-color: var(--rp-container-important-border);
191
+ background-color: var(--rp-container-important-bg);
192
+
193
+ .rp-callout__title {
194
+ color: var(--rp-container-important-text);
195
+ &::before {
196
+ background-color: var(--rp-container-important-text);
197
+ }
198
+ }
199
+
200
+ // inline code
201
+ :not(pre) > code {
202
+ color: var(--rp-container-important-text);
203
+ background-color: var(--rp-container-important-code-bg);
204
+ }
205
+
206
+ a {
207
+ color: var(--rp-container-important-text);
208
+ }
209
+ }
210
+
179
211
  // warning
180
212
  .rp-callout--warning {
181
213
  border-color: var(--rp-container-warning-border);
@@ -2,7 +2,15 @@ import type { ReactNode } from 'react';
2
2
  import './index.scss';
3
3
 
4
4
  export interface CalloutProps {
5
- type: 'tip' | 'note' | 'warning' | 'caution' | 'danger' | 'info' | 'details';
5
+ type:
6
+ | 'tip'
7
+ | 'note'
8
+ | 'important'
9
+ | 'warning'
10
+ | 'caution'
11
+ | 'danger'
12
+ | 'info'
13
+ | 'details';
6
14
  title?: string;
7
15
  children: ReactNode;
8
16
  }
@@ -41,7 +41,7 @@ nprogress.configure({ showSpinner: false });
41
41
  * Link can tell whether it's in current site or external site.
42
42
  * 1. If external, open a new page and navigate to it.
43
43
  * 2. If inCurrentPage, scroll to anchor.
44
- * 3. If inCurrentSite, it will navigate and scroll to anchor, preload the asyncChunk onHover the link
44
+ * 3. If inCurrentSite, it will navigate and scroll to anchor, prefetch route resources when hovering over the link.
45
45
  * 4. Link is styled.
46
46
  */
47
47
  export const Link = forwardRef<HTMLAnchorElement, LinkProps>((props, ref) => {
@@ -7,6 +7,7 @@ import {
7
7
  removeBase,
8
8
  useLocation,
9
9
  useNavigate as useNavigateInner,
10
+ useSite,
10
11
  warmPageData,
11
12
  withBase,
12
13
  } from '@rspress/core/runtime';
@@ -67,12 +68,16 @@ export function getHref(href: string): {
67
68
  * useNavigate with preload logic
68
69
  */
69
70
  export function useLinkNavigate(
70
- { startTransition }: { startTransition?: TransitionStartFunction } = {
71
+ {
72
+ startTransition = reactStartTransition,
73
+ }: { startTransition?: TransitionStartFunction } = {
71
74
  startTransition: reactStartTransition,
72
75
  },
73
76
  ): (href: string) => Promise<void> {
74
77
  const { pathname: currPagePathname } = useLocation();
75
78
  const navigate = useNavigateInner();
79
+ const { site } = useSite();
80
+ const useTransitions = site?.route?.useTransitions;
76
81
 
77
82
  return useCallback(
78
83
  async (href: string) => {
@@ -82,8 +87,10 @@ export function useLinkNavigate(
82
87
  return;
83
88
  }
84
89
 
90
+ const isTransitionable = !!(useTransitions && startTransition);
85
91
  const preloadChunkThenNavigate = async () => {
86
92
  const inCurrPage = isActive(removeBaseHref, currPagePathname);
93
+
87
94
  if (!import.meta.env.SSR && !inCurrPage) {
88
95
  const matchedRoute = pathnameToRouteService(removeBaseHref);
89
96
  if (matchedRoute) {
@@ -99,15 +106,21 @@ export function useLinkNavigate(
99
106
  return;
100
107
  }
101
108
  }
102
- navigate(removeBaseHref, { replace: false });
109
+ if (isTransitionable) {
110
+ startTransition(() => {
111
+ return navigate(removeBaseHref, { replace: false });
112
+ });
113
+ } else {
114
+ navigate(removeBaseHref, { replace: false });
115
+ }
103
116
  };
104
117
 
105
- if (startTransition) {
118
+ if (isTransitionable) {
106
119
  startTransition(preloadChunkThenNavigate);
107
120
  } else {
108
121
  preloadChunkThenNavigate();
109
122
  }
110
123
  },
111
- [currPagePathname, navigate],
124
+ [useTransitions, currPagePathname, navigate, startTransition],
112
125
  );
113
126
  }
@@ -1,7 +1,7 @@
1
1
  import type React from 'react';
2
2
  import './LlmsContainer.scss';
3
3
 
4
- export interface LlmsContainerProps extends React.HTMLAttributes<HTMLDivElement> {}
4
+ export type LlmsContainerProps = React.HTMLAttributes<HTMLDivElement>;
5
5
 
6
6
  export function LlmsContainer(props: LlmsContainerProps) {
7
7
  return <div {...props} className={'rp-not-doc rp-llms-container'} />;
@@ -109,8 +109,7 @@ export function Overview(props: {
109
109
  const { pages } = siteData;
110
110
  const overviewModules = pages.filter(page => subFilter(page.routePath));
111
111
  let overviewSidebarGroups = useSidebar() as (
112
- | NormalizedSidebarGroup
113
- | SidebarItem
112
+ NormalizedSidebarGroup | SidebarItem
114
113
  )[];
115
114
 
116
115
  if (overviewSidebarGroups[0]?.link !== routePath) {
@@ -17,10 +17,7 @@ function removeIndex(link: string) {
17
17
  */
18
18
  export function findItemByRoutePath(
19
19
  items: (
20
- | SidebarItem
21
- | NormalizedSidebarGroup
22
- | SidebarDivider
23
- | SidebarSectionHeader
20
+ SidebarItem | NormalizedSidebarGroup | SidebarDivider | SidebarSectionHeader
24
21
  )[],
25
22
  routePath: string,
26
23
  ): (SidebarItem | NormalizedSidebarGroup)[] {
@@ -61,8 +58,7 @@ export function findItemByRoutePath(
61
58
  }
62
59
 
63
60
  const matchRoutePathItem = items[matchRoutePathItemIndex] as
64
- | SidebarItem
65
- | NormalizedSidebarGroup;
61
+ SidebarItem | NormalizedSidebarGroup;
66
62
 
67
63
  const isArray = (i: unknown): i is Array<unknown> =>
68
64
  Array.isArray(i) && i.length >= 1;
@@ -75,8 +71,7 @@ export function findItemByRoutePath(
75
71
  }
76
72
 
77
73
  return matchRoutePathItem.items.filter(item => !isSidebarDivider(item)) as (
78
- | SidebarItem
79
- | NormalizedSidebarGroup
74
+ SidebarItem | NormalizedSidebarGroup
80
75
  )[];
81
76
  }
82
77
 
@@ -86,8 +81,7 @@ export function findItemByRoutePath(
86
81
  result.splice(matchRoutePathItemIndex, 1);
87
82
  }
88
83
  const res = result.filter(item => !isSidebarDivider(item)) as (
89
- | SidebarItem
90
- | NormalizedSidebarGroup
84
+ SidebarItem | NormalizedSidebarGroup
91
85
  )[];
92
86
 
93
87
  return res;
@@ -29,7 +29,9 @@ interface PageIndexForFlexSearch extends PageIndexInfo {
29
29
  // Create a type that satisfies DocumentData constraints by mapping all properties
30
30
  // to DocumentValue | DocumentValue[] while preserving the original structure
31
31
  type FlexSearchCompatibleData = {
32
- [K in keyof PageIndexForFlexSearch]: PageIndexForFlexSearch[K] extends DocumentValue
32
+ [
33
+ K in keyof PageIndexForFlexSearch
34
+ ]: PageIndexForFlexSearch[K] extends DocumentValue
33
35
  ? PageIndexForFlexSearch[K]
34
36
  : DocumentValue;
35
37
  } & {
@@ -2,8 +2,7 @@ import { useEffect } from 'react';
2
2
 
3
3
  function useClickOutside(
4
4
  ref:
5
- | React.RefObject<HTMLElement | null>
6
- | React.RefObject<HTMLElement | null>[],
5
+ React.RefObject<HTMLElement | null> | React.RefObject<HTMLElement | null>[],
7
6
  handler: (event: MouseEvent | TouchEvent) => void,
8
7
  ) {
9
8
  useEffect(() => {
@@ -0,0 +1,48 @@
1
+ import { afterEach, describe, expect, it } from '@rstest/core';
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import { GithubStars } from './GithubStars';
4
+
5
+ const originalLocalStorage = Object.getOwnPropertyDescriptor(
6
+ globalThis,
7
+ 'localStorage',
8
+ );
9
+
10
+ afterEach(() => {
11
+ if (originalLocalStorage) {
12
+ Object.defineProperty(globalThis, 'localStorage', originalLocalStorage);
13
+ } else {
14
+ Reflect.deleteProperty(globalThis, 'localStorage');
15
+ }
16
+ });
17
+
18
+ function mockLocalStorage(cache: Record<string, string>) {
19
+ Object.defineProperty(globalThis, 'localStorage', {
20
+ configurable: true,
21
+ value: {
22
+ getItem: (key: string) => cache[key] ?? null,
23
+ setItem: () => {},
24
+ },
25
+ });
26
+ }
27
+
28
+ describe('GithubStars', () => {
29
+ it('does not render cached stars during the first render', () => {
30
+ mockLocalStorage({
31
+ 'rp-github-stars:web-infra-dev/rspress': JSON.stringify({
32
+ count: 12345,
33
+ fetchedAt: Date.now(),
34
+ }),
35
+ });
36
+
37
+ const markup = renderToStaticMarkup(
38
+ <GithubStars
39
+ content="https://github.com/web-infra-dev/rspress"
40
+ icon={<span data-icon="github" />}
41
+ />,
42
+ );
43
+
44
+ expect(markup).not.toContain('rp-social-links__github-stars-count');
45
+ expect(markup).not.toContain('12.3K');
46
+ expect(markup).toContain('aria-label="GitHub repository"');
47
+ });
48
+ });
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode, useEffect, useState } from 'react';
2
+ import { useStorageValue } from '../../logic/useStorageValue';
2
3
 
3
4
  const TTL_MS = 60 * 60 * 1000;
4
5
 
@@ -21,10 +22,8 @@ function parseRepo(content: string): string | null {
21
22
  }
22
23
  }
23
24
 
24
- function readCache(repo: string): Cached | null {
25
- if (typeof localStorage === 'undefined') return null;
25
+ function parseCache(raw: string | null): Cached | null {
26
26
  try {
27
- const raw = localStorage.getItem(storageKey(repo));
28
27
  if (!raw) return null;
29
28
  const parsed = JSON.parse(raw) as Cached;
30
29
  if (
@@ -39,16 +38,8 @@ function readCache(repo: string): Cached | null {
39
38
  }
40
39
  }
41
40
 
42
- function writeCache(repo: string, count: number) {
43
- if (typeof localStorage === 'undefined') return;
44
- try {
45
- localStorage.setItem(
46
- storageKey(repo),
47
- JSON.stringify({ count, fetchedAt: Date.now() }),
48
- );
49
- } catch {
50
- // Storage may be full or disabled (private mode); ignore.
51
- }
41
+ function createCacheValue(count: number): string {
42
+ return JSON.stringify({ count, fetchedAt: Date.now() });
52
43
  }
53
44
 
54
45
  function formatCount(count: number): string {
@@ -70,14 +61,34 @@ export const GithubStars = (props: GithubStarsProps) => {
70
61
  const { content, icon } = props;
71
62
  const repo = parseRepo(content);
72
63
 
73
- const [count, setCount] = useState<number | null>(() =>
74
- repo ? (readCache(repo)?.count ?? null) : null,
64
+ const [rawCache, setRawCache] = useStorageValue<string | null>(
65
+ repo ? storageKey(repo) : '',
66
+ null,
75
67
  );
68
+ const [isMounted, setIsMounted] = useState(false);
69
+ const [count, setCount] = useState<number | null>(null);
70
+
71
+ useEffect(() => {
72
+ setIsMounted(true);
73
+ }, []);
76
74
 
77
75
  useEffect(() => {
78
- if (!repo) return;
79
- const cached = readCache(repo);
80
- if (cached && Date.now() - cached.fetchedAt < TTL_MS) return;
76
+ if (!repo) {
77
+ setCount(null);
78
+ return;
79
+ }
80
+
81
+ if (!isMounted) return;
82
+
83
+ const cached = parseCache(rawCache);
84
+ if (cached) {
85
+ setCount(cached.count);
86
+ if (Date.now() - cached.fetchedAt < TTL_MS) {
87
+ return;
88
+ }
89
+ } else {
90
+ setCount(null);
91
+ }
81
92
 
82
93
  let cancelled = false;
83
94
  fetch(`https://api.github.com/repos/${repo}`)
@@ -86,7 +97,11 @@ export const GithubStars = (props: GithubStarsProps) => {
86
97
  if (cancelled) return;
87
98
  if (typeof data?.stargazers_count === 'number') {
88
99
  setCount(data.stargazers_count);
89
- writeCache(repo, data.stargazers_count);
100
+ try {
101
+ setRawCache(createCacheValue(data.stargazers_count));
102
+ } catch {
103
+ // Storage may be full or disabled (private mode); ignore.
104
+ }
90
105
  }
91
106
  })
92
107
  .catch(() => {
@@ -95,7 +110,7 @@ export const GithubStars = (props: GithubStarsProps) => {
95
110
  return () => {
96
111
  cancelled = true;
97
112
  };
98
- }, [repo]);
113
+ }, [isMounted, rawCache, repo, setRawCache]);
99
114
 
100
115
  return (
101
116
  <a
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export type { DarkMode, EditLink, Feature, FrontMatterMeta, Header, Hero, I18nText, LocalSearchOptions, Nav, NavItem, NavItemWithChildren, NavItemWithLink, NavItemWithLinkAndChildren, NormalizedSidebarGroup, PageIndexInfo, RemotePageInfo, RouteMeta, RspressPlugin, Sidebar, SidebarData, SidebarDivider, SidebarGroup, SidebarItem, SidebarSectionHeader, SocialLink, UserConfig, } from '@rspress/shared';
2
- export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, } from '@rspress/shared';
2
+ export { getSidebarDataGroup, normalizeHref, normalizePosixPath, RSPRESS_TEMP_DIR, removeTrailingSlash, withBase, withSiteOrigin, } from '@rspress/shared';
3
3
  export { logger } from '@rspress/shared/logger';
4
4
  export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shared/node-utils';
5
5
  export { matchPath } from 'react-router-dom';
6
6
  export type { UserConfigAsyncFn } from './config/defineConfig.js';
7
7
  export { defineConfig } from './config/defineConfig.js';
8
+ export { type RunCLIOptions, runCLI } from './cli/index.js';
8
9
  export { build, dev, remarkFileCodeBlock, remarkImage, remarkLink, serve, } from './node/index.js';
9
10
  export type { CustomLinkMeta, DirSectionHeaderSideMeta, DirSideMeta, DividerSideMeta, FileSideMeta, MetaJson, NavJson, SectionHeaderMeta, SideMeta, SideMetaItem, } from './node/auto-nav-sidebar/type.js';
10
11
  export { PluginDriver } from './node/PluginDriver.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { PluginDriver } from "./node/PluginDriver.js";
2
- export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase } from "./9882.js";
2
+ export { RSPRESS_TEMP_DIR, getIconUrlPath, getNodeAttribute, getSidebarDataGroup, logger, matchPath, mergeDocConfig, normalizeHref, normalizePosixPath, removeTrailingSlash, withBase, withSiteOrigin } from "./102.js";
3
3
  export { RouteService } from "./node/route/RouteService.js";
4
4
  export { build } from "./node/build.js";
5
5
  export { defineConfig } from "./config/defineConfig.js";
@@ -7,4 +7,5 @@ export { dev } from "./node/dev.js";
7
7
  export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
8
8
  export { remarkImage } from "./node/mdx/remarkPlugins/image.js";
9
9
  export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
10
+ export { runCLI } from "./cli/index.js";
10
11
  export { serve } from "./node/serve.js";
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../6010.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../8629.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
4
4
  class PluginDriver {