@modern-js/app-tools 3.7.0 → 3.8.0

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 (306) hide show
  1. package/bin/modern-bundle-docs.js +7 -0
  2. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
  3. package/dist/cjs/bundleDocs.js +114 -0
  4. package/dist/cjs/commands/build.js +2 -1
  5. package/dist/cjs/commands/deploy.js +4 -2
  6. package/dist/cjs/commands/index.js +0 -4
  7. package/dist/cjs/config/default.js +2 -0
  8. package/dist/cjs/index.js +52 -14
  9. package/dist/cjs/plugins/analyze/index.js +2 -2
  10. package/dist/cjs/plugins/analyze/utils.js +3 -2
  11. package/dist/cjs/plugins/initialize/index.js +4 -3
  12. package/dist/cjs/plugins/serverBuild.js +3 -2
  13. package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
  14. package/dist/esm/bundleDocs.mjs +62 -0
  15. package/dist/esm/commands/build.mjs +2 -1
  16. package/dist/esm/commands/deploy.mjs +4 -2
  17. package/dist/esm/commands/index.mjs +0 -4
  18. package/dist/esm/config/default.mjs +2 -0
  19. package/dist/esm/index.mjs +15 -1
  20. package/dist/esm/plugins/analyze/index.mjs +2 -2
  21. package/dist/esm/plugins/analyze/utils.mjs +3 -2
  22. package/dist/esm/plugins/initialize/index.mjs +4 -3
  23. package/dist/esm/plugins/serverBuild.mjs +3 -2
  24. package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
  25. package/dist/esm-node/bundleDocs.mjs +63 -0
  26. package/dist/esm-node/commands/build.mjs +2 -1
  27. package/dist/esm-node/commands/deploy.mjs +4 -2
  28. package/dist/esm-node/commands/index.mjs +0 -4
  29. package/dist/esm-node/config/default.mjs +2 -0
  30. package/dist/esm-node/index.mjs +15 -1
  31. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  32. package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
  33. package/dist/esm-node/plugins/initialize/index.mjs +4 -3
  34. package/dist/esm-node/plugins/serverBuild.mjs +3 -2
  35. package/dist/types/bundleDocs.d.ts +20 -0
  36. package/dist/types/commands/deploy.d.ts +2 -1
  37. package/dist/types/index.d.ts +4 -1
  38. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  39. package/dist/types/types/config/dev.d.ts +6 -0
  40. package/docs/apis/app/commands.md +241 -0
  41. package/docs/apis/app/hooks/api/lambda.md +9 -0
  42. package/docs/apis/app/hooks/config/favicon.md +24 -0
  43. package/docs/apis/app/hooks/config/html.md +5 -0
  44. package/docs/apis/app/hooks/config/icon.md +24 -0
  45. package/docs/apis/app/hooks/config/mock.md +6 -0
  46. package/docs/apis/app/hooks/config/public.md +26 -0
  47. package/docs/apis/app/hooks/config/upload.md +50 -0
  48. package/docs/apis/app/hooks/modern-config.md +5 -0
  49. package/docs/apis/app/hooks/server/server.md +5 -0
  50. package/docs/apis/app/hooks/shared.md +3 -0
  51. package/docs/apis/app/hooks/src/app.md +30 -0
  52. package/docs/apis/app/hooks/src/entry.md +34 -0
  53. package/docs/apis/app/hooks/src/entry.server.md +51 -0
  54. package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
  55. package/docs/apis/app/hooks/src/routes.md +86 -0
  56. package/docs/apis/app/hooks/src/server.md +3 -0
  57. package/docs/apis/app/runtime/bff/use-hono-context.md +27 -0
  58. package/docs/apis/app/runtime/core/create-root.md +19 -0
  59. package/docs/apis/app/runtime/core/render.md +39 -0
  60. package/docs/apis/app/runtime/core/runtime-context.md +156 -0
  61. package/docs/apis/app/runtime/router/router.md +280 -0
  62. package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
  63. package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
  64. package/docs/apis/app/runtime/ssr/renderString.md +60 -0
  65. package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
  66. package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
  67. package/docs/apis/app/runtime/utility/head.md +35 -0
  68. package/docs/apis/app/runtime/utility/loadable.md +82 -0
  69. package/docs/community/blog/2022-0708-updates.md +91 -0
  70. package/docs/community/blog/2022-0910-updates.md +76 -0
  71. package/docs/community/blog/overview.md +63 -0
  72. package/docs/community/blog/v2-release-note.md +238 -0
  73. package/docs/community/blog/v3-release-note.md +622 -0
  74. package/docs/community/contributing-guide.md +253 -0
  75. package/docs/community/releases.md +27 -0
  76. package/docs/community/showcase.md +34 -0
  77. package/docs/community/team.md +14 -0
  78. package/docs/configure/app/bff/cross-project.md +20 -0
  79. package/docs/configure/app/bff/prefix.md +29 -0
  80. package/docs/configure/app/builder-plugins.md +66 -0
  81. package/docs/configure/app/dev/asset-prefix.md +13 -0
  82. package/docs/configure/app/dev/before-start-url.md +17 -0
  83. package/docs/configure/app/dev/client.md +41 -0
  84. package/docs/configure/app/dev/hmr.md +10 -0
  85. package/docs/configure/app/dev/host.md +18 -0
  86. package/docs/configure/app/dev/https.md +77 -0
  87. package/docs/configure/app/dev/lazy-compilation.md +39 -0
  88. package/docs/configure/app/dev/live-reload.md +10 -0
  89. package/docs/configure/app/dev/mock-dir.md +31 -0
  90. package/docs/configure/app/dev/progress-bar.md +19 -0
  91. package/docs/configure/app/dev/server.md +124 -0
  92. package/docs/configure/app/dev/setup-middlewares.md +32 -0
  93. package/docs/configure/app/dev/start-url.md +48 -0
  94. package/docs/configure/app/dev/watch-files.md +27 -0
  95. package/docs/configure/app/dev/write-to-disk.md +10 -0
  96. package/docs/configure/app/experiments/source-build.md +31 -0
  97. package/docs/configure/app/html/app-icon.md +28 -0
  98. package/docs/configure/app/html/crossorigin.md +10 -0
  99. package/docs/configure/app/html/favicon.md +16 -0
  100. package/docs/configure/app/html/inject.md +10 -0
  101. package/docs/configure/app/html/meta.md +24 -0
  102. package/docs/configure/app/html/mount-id.md +10 -0
  103. package/docs/configure/app/html/output-structure.md +10 -0
  104. package/docs/configure/app/html/script-loading.md +10 -0
  105. package/docs/configure/app/html/tags.md +15 -0
  106. package/docs/configure/app/html/template-parameters.md +33 -0
  107. package/docs/configure/app/html/template.md +10 -0
  108. package/docs/configure/app/html/title.md +18 -0
  109. package/docs/configure/app/output/asset-prefix.md +11 -0
  110. package/docs/configure/app/output/assets-retry.md +77 -0
  111. package/docs/configure/app/output/charset.md +10 -0
  112. package/docs/configure/app/output/clean-dist-path.md +16 -0
  113. package/docs/configure/app/output/convert-to-rem.md +79 -0
  114. package/docs/configure/app/output/copy.md +10 -0
  115. package/docs/configure/app/output/css-modules.md +48 -0
  116. package/docs/configure/app/output/data-uri-limit.md +26 -0
  117. package/docs/configure/app/output/disable-css-module-extension.md +55 -0
  118. package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
  119. package/docs/configure/app/output/disable-svgr.md +16 -0
  120. package/docs/configure/app/output/disable-ts-checker.md +49 -0
  121. package/docs/configure/app/output/dist-path.md +43 -0
  122. package/docs/configure/app/output/enable-asset-manifest.md +36 -0
  123. package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
  124. package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
  125. package/docs/configure/app/output/externals.md +20 -0
  126. package/docs/configure/app/output/filename-hash.md +10 -0
  127. package/docs/configure/app/output/filename.md +55 -0
  128. package/docs/configure/app/output/inject-styles.md +10 -0
  129. package/docs/configure/app/output/inline-scripts.md +29 -0
  130. package/docs/configure/app/output/inline-styles.md +29 -0
  131. package/docs/configure/app/output/legal-comments.md +18 -0
  132. package/docs/configure/app/output/minify.md +22 -0
  133. package/docs/configure/app/output/override-browserslist.md +22 -0
  134. package/docs/configure/app/output/polyfill.md +12 -0
  135. package/docs/configure/app/output/source-map.md +30 -0
  136. package/docs/configure/app/output/split-route-chunks.md +16 -0
  137. package/docs/configure/app/output/ssg.md +81 -0
  138. package/docs/configure/app/output/ssgByEntries.md +90 -0
  139. package/docs/configure/app/output/svg-default-export.md +30 -0
  140. package/docs/configure/app/output/temp-dir.md +20 -0
  141. package/docs/configure/app/performance/build-cache.md +39 -0
  142. package/docs/configure/app/performance/chunk-split.md +40 -0
  143. package/docs/configure/app/performance/dns-prefetch.md +15 -0
  144. package/docs/configure/app/performance/preconnect.md +16 -0
  145. package/docs/configure/app/performance/prefetch.md +21 -0
  146. package/docs/configure/app/performance/preload.md +23 -0
  147. package/docs/configure/app/performance/print-file-size.md +40 -0
  148. package/docs/configure/app/performance/profile.md +10 -0
  149. package/docs/configure/app/performance/remove-console.md +10 -0
  150. package/docs/configure/app/performance/remove-moment-locale.md +10 -0
  151. package/docs/configure/app/plugins.md +59 -0
  152. package/docs/configure/app/resolve/alias-strategy.md +10 -0
  153. package/docs/configure/app/resolve/alias.md +9 -0
  154. package/docs/configure/app/resolve/condition-names.md +13 -0
  155. package/docs/configure/app/resolve/dedupe.md +9 -0
  156. package/docs/configure/app/resolve/extensions.md +13 -0
  157. package/docs/configure/app/runtime/0-intro.md +58 -0
  158. package/docs/configure/app/runtime/plugins.md +58 -0
  159. package/docs/configure/app/runtime/router.md +35 -0
  160. package/docs/configure/app/security/check-syntax.md +69 -0
  161. package/docs/configure/app/security/nonce.md +15 -0
  162. package/docs/configure/app/security/sri.md +20 -0
  163. package/docs/configure/app/server/base-url.md +26 -0
  164. package/docs/configure/app/server/port.md +18 -0
  165. package/docs/configure/app/server/public-routes.md +22 -0
  166. package/docs/configure/app/server/routes.md +86 -0
  167. package/docs/configure/app/server/rsc.md +26 -0
  168. package/docs/configure/app/server/ssr-by-entries.md +25 -0
  169. package/docs/configure/app/server/ssr.md +78 -0
  170. package/docs/configure/app/server/tsconfig-path.md +59 -0
  171. package/docs/configure/app/source/alias-strategy.md +14 -0
  172. package/docs/configure/app/source/alias.md +23 -0
  173. package/docs/configure/app/source/config-dir.md +20 -0
  174. package/docs/configure/app/source/decorators.md +25 -0
  175. package/docs/configure/app/source/define.md +16 -0
  176. package/docs/configure/app/source/disable-default-entries.md +28 -0
  177. package/docs/configure/app/source/enable-async-entry.md +54 -0
  178. package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
  179. package/docs/configure/app/source/entries-dir.md +35 -0
  180. package/docs/configure/app/source/entries.md +179 -0
  181. package/docs/configure/app/source/exclude.md +10 -0
  182. package/docs/configure/app/source/global-vars.md +106 -0
  183. package/docs/configure/app/source/include.md +36 -0
  184. package/docs/configure/app/source/main-entry-name.md +24 -0
  185. package/docs/configure/app/source/pre-entry.md +10 -0
  186. package/docs/configure/app/source/react-compiler.md +68 -0
  187. package/docs/configure/app/source/transform-import.md +27 -0
  188. package/docs/configure/app/split-chunks.md +17 -0
  189. package/docs/configure/app/tools/autoprefixer.md +44 -0
  190. package/docs/configure/app/tools/bundler-chain.md +26 -0
  191. package/docs/configure/app/tools/css-extract.md +33 -0
  192. package/docs/configure/app/tools/css-loader.md +17 -0
  193. package/docs/configure/app/tools/dev-server.md +113 -0
  194. package/docs/configure/app/tools/html-plugin.md +41 -0
  195. package/docs/configure/app/tools/less.md +81 -0
  196. package/docs/configure/app/tools/lightningcss-loader.md +35 -0
  197. package/docs/configure/app/tools/minify-css.md +53 -0
  198. package/docs/configure/app/tools/postcss.md +34 -0
  199. package/docs/configure/app/tools/rspack.md +10 -0
  200. package/docs/configure/app/tools/sass.md +78 -0
  201. package/docs/configure/app/tools/style-loader.md +10 -0
  202. package/docs/configure/app/tools/swc.md +65 -0
  203. package/docs/configure/app/tools/ts-checker.md +109 -0
  204. package/docs/configure/app/usage.md +276 -0
  205. package/docs/guides/advanced-features/bff/cross-project.md +109 -0
  206. package/docs/guides/advanced-features/bff/extend-server.md +120 -0
  207. package/docs/guides/advanced-features/bff/frameworks.md +124 -0
  208. package/docs/guides/advanced-features/bff/function.md +314 -0
  209. package/docs/guides/advanced-features/bff/operators.md +554 -0
  210. package/docs/guides/advanced-features/bff/sdk.md +116 -0
  211. package/docs/guides/advanced-features/bff/upload.md +101 -0
  212. package/docs/guides/advanced-features/bff.md +18 -0
  213. package/docs/guides/advanced-features/build-performance.md +130 -0
  214. package/docs/guides/advanced-features/compatibility.md +120 -0
  215. package/docs/guides/advanced-features/international/advanced.md +128 -0
  216. package/docs/guides/advanced-features/international/api.md +231 -0
  217. package/docs/guides/advanced-features/international/best-practices.md +286 -0
  218. package/docs/guides/advanced-features/international/configuration.md +227 -0
  219. package/docs/guides/advanced-features/international/locale-detection.md +126 -0
  220. package/docs/guides/advanced-features/international/quick-start.md +128 -0
  221. package/docs/guides/advanced-features/international/resource-loading.md +154 -0
  222. package/docs/guides/advanced-features/international/routing.md +130 -0
  223. package/docs/guides/advanced-features/international.md +27 -0
  224. package/docs/guides/advanced-features/low-level.md +46 -0
  225. package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
  226. package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
  227. package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
  228. package/docs/guides/advanced-features/page-performance/react-compiler.md +69 -0
  229. package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
  230. package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
  231. package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
  232. package/docs/guides/advanced-features/source-build.md +164 -0
  233. package/docs/guides/advanced-features/web-server.md +288 -0
  234. package/docs/guides/basic-features/alias.md +102 -0
  235. package/docs/guides/basic-features/css/css-in-js.md +72 -0
  236. package/docs/guides/basic-features/css/css-modules.md +212 -0
  237. package/docs/guides/basic-features/css/css.md +27 -0
  238. package/docs/guides/basic-features/css/tailwindcss.md +27 -0
  239. package/docs/guides/basic-features/data/data-cache.md +510 -0
  240. package/docs/guides/basic-features/data/data-fetch.md +415 -0
  241. package/docs/guides/basic-features/data/data-write.md +227 -0
  242. package/docs/guides/basic-features/debug/mock.md +109 -0
  243. package/docs/guides/basic-features/debug/proxy.md +21 -0
  244. package/docs/guides/basic-features/debug/rsdoctor.md +62 -0
  245. package/docs/guides/basic-features/debug/using-storybook.md +112 -0
  246. package/docs/guides/basic-features/deploy.md +458 -0
  247. package/docs/guides/basic-features/env-vars.md +177 -0
  248. package/docs/guides/basic-features/html.md +255 -0
  249. package/docs/guides/basic-features/output-files.md +141 -0
  250. package/docs/guides/basic-features/render/before-render.md +108 -0
  251. package/docs/guides/basic-features/render/overview.md +47 -0
  252. package/docs/guides/basic-features/render/rsc.md +525 -0
  253. package/docs/guides/basic-features/render/ssg.md +228 -0
  254. package/docs/guides/basic-features/render/ssr-cache.md +201 -0
  255. package/docs/guides/basic-features/render/ssr.md +321 -0
  256. package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
  257. package/docs/guides/basic-features/routes/config-routes.md +426 -0
  258. package/docs/guides/basic-features/routes/routes.md +498 -0
  259. package/docs/guides/basic-features/static-assets/json-files.md +120 -0
  260. package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
  261. package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
  262. package/docs/guides/basic-features/static-assets.md +160 -0
  263. package/docs/guides/basic-features/testing/playwright.md +120 -0
  264. package/docs/guides/basic-features/testing/rstest.md +251 -0
  265. package/docs/guides/concept/builder.md +37 -0
  266. package/docs/guides/concept/entries.md +319 -0
  267. package/docs/guides/concept/server.md +35 -0
  268. package/docs/guides/get-started/ai-coding-agents.md +58 -0
  269. package/docs/guides/get-started/glossary.md +63 -0
  270. package/docs/guides/get-started/introduction.md +36 -0
  271. package/docs/guides/get-started/quick-start.md +236 -0
  272. package/docs/guides/get-started/tech-stack.md +82 -0
  273. package/docs/guides/get-started/upgrade.md +123 -0
  274. package/docs/guides/topic-detail/module-federation/application.md +116 -0
  275. package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
  276. package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
  277. package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
  278. package/docs/guides/topic-detail/module-federation/ssr.md +118 -0
  279. package/docs/guides/topic-detail/module-federation/usage.md +219 -0
  280. package/docs/guides/troubleshooting/builder.md +110 -0
  281. package/docs/guides/troubleshooting/cli.md +35 -0
  282. package/docs/guides/troubleshooting/dependencies.md +119 -0
  283. package/docs/guides/troubleshooting/hmr.md +144 -0
  284. package/docs/guides/upgrade/config.md +963 -0
  285. package/docs/guides/upgrade/entry.md +463 -0
  286. package/docs/guides/upgrade/other.md +183 -0
  287. package/docs/guides/upgrade/overview.md +33 -0
  288. package/docs/guides/upgrade/tailwindcss.md +91 -0
  289. package/docs/guides/upgrade/web-server.md +109 -0
  290. package/docs/index.md +33 -0
  291. package/docs/llms.txt +285 -0
  292. package/docs/plugin/cli-plugins/api.md +573 -0
  293. package/docs/plugin/cli-plugins/life-cycle.md +2 -0
  294. package/docs/plugin/introduction.md +152 -0
  295. package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
  296. package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
  297. package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
  298. package/docs/plugin/official/cli-plugins.md +4 -0
  299. package/docs/plugin/plugin-system.md +238 -0
  300. package/docs/plugin/runtime-plugins/api.md +194 -0
  301. package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
  302. package/docs/plugin/server-plugins/api.md +209 -0
  303. package/docs/plugin/server-plugins/life-cycle.md +13 -0
  304. package/docs/tutorials/examples/csr-auth.md +9 -0
  305. package/docs/tutorials/foundations/introduction.md +16 -0
  306. package/package.json +46 -13
@@ -0,0 +1,280 @@
1
+ # router
2
+
3
+ :::info
4
+ The router solution based on [react-router v7](https://reactrouter.com/).
5
+
6
+ :::
7
+
8
+ ## hooks
9
+
10
+ ### useNavigate
11
+
12
+ ```ts
13
+ declare function useNavigate(): NavigateFunction;
14
+
15
+ interface NavigateFunction {
16
+ (
17
+ to: To,
18
+ options?: {
19
+ replace?: boolean;
20
+ state?: any;
21
+ relative?: RelativeRoutingType;
22
+ },
23
+ ): void;
24
+ (delta: number): void;
25
+ }
26
+ ```
27
+
28
+ The `useNavigate` hook returns a function that lets you navigate programmatically.
29
+
30
+ ```tsx
31
+ import { useNavigate } from '@modern-js/runtime/router';
32
+
33
+ export function HomeButton() {
34
+ let navigate = useNavigate();
35
+
36
+ function handleClick() {
37
+ navigate('/home');
38
+ }
39
+
40
+ return (
41
+ <button type="button" onClick={handleClick}>
42
+ Go home
43
+ </button>
44
+ );
45
+ }
46
+ ```
47
+
48
+ ### useLocation
49
+
50
+ ```ts
51
+ declare function useLocation(): Location;
52
+
53
+ interface Location extends Path {
54
+ state: unknown;
55
+ key: Key;
56
+ }
57
+ ```
58
+
59
+ The `useLocation` hook returns the current [location](https://reactrouter.com/web/api/location) object. A new location object would be returned whenever the current location changes.
60
+
61
+ ```ts
62
+ import { useLocation } from '@modern-js/runtime/router';
63
+
64
+ function usePageViews() {
65
+ let location = useLocation();
66
+ React.useEffect(() => {
67
+ ga.send(["pageview", location.pathname]);
68
+ }, [location]);
69
+ }
70
+
71
+ function App() {
72
+ usePageViews();
73
+ return (
74
+ //...
75
+ );
76
+ }
77
+ ```
78
+
79
+ ### useParams
80
+
81
+ ```ts
82
+ declare function useParams<K extends string = string>(): Readonly<Params<K>>;
83
+ ```
84
+
85
+ The `useParams` hook returns an object of key/value pairs of the dynamic params from the current URL that were matched by the `<Route path>`.
86
+
87
+ ```tsx
88
+ import { Routes, Route, useParams } from '@modern-js/runtime/router';
89
+
90
+ function BlogPost() {
91
+ const { slug } = useParams();
92
+ return <div>Now showing post {slug}</div>;
93
+ }
94
+
95
+ function App() {
96
+ return (
97
+ <Routes>
98
+ <Route path="/" element={<div>home</div>} />
99
+ <Route path="/blog/:slug" element={<BlogPost />} />
100
+ </Routes>
101
+ );
102
+ }
103
+ ```
104
+
105
+ ### useRouteError
106
+
107
+ ```ts
108
+ export declare function useRouteError(): unknown;
109
+ ```
110
+
111
+ `useRouteError` returns the nearest ancestor Route error。
112
+
113
+ ```tsx
114
+ import { useRouteError } from '@modern-js/runtime/router';
115
+ const ErrorBoundary = () => {
116
+ const error = useRouteError();
117
+ return (
118
+ <div>
119
+ <h1>{error.status}</h1>
120
+ <h2>{error.message}</h2>
121
+ </div>
122
+ );
123
+ };
124
+ export default ErrorBoundary;
125
+ ```
126
+
127
+ ## Components
128
+
129
+ ### Link
130
+
131
+ ```ts
132
+ declare function Link(props: LinkProps): React.ReactElement;
133
+
134
+ interface LinkProps
135
+ extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> {
136
+ replace?: boolean;
137
+ state?: any;
138
+ to: To;
139
+ reloadDocument?: boolean;
140
+ }
141
+
142
+ type To = string | Partial<Path>;
143
+ ```
144
+
145
+ A `<Link>` is an element that lets the user navigate to another page by clicking or tapping on it.
146
+
147
+ ```ts
148
+ <Link to="/about">About</Link>
149
+ ```
150
+
151
+ ### NavLink
152
+
153
+ ```ts
154
+ declare function NavLink(props: NavLinkProps): React.ReactElement;
155
+
156
+ interface NavLinkProps
157
+ extends Omit<LinkProps, 'className' | 'style' | 'children'> {
158
+ caseSensitive?: boolean;
159
+ children?:
160
+ | React.ReactNode
161
+ | ((props: { isActive: boolean }) => React.ReactNode);
162
+ className?: string | ((props: { isActive: boolean }) => string | undefined);
163
+ end?: boolean;
164
+ style?:
165
+ | React.CSSProperties
166
+ | ((props: { isActive: boolean }) => React.CSSProperties);
167
+ }
168
+ ```
169
+
170
+ A `<NavLink>` is a special kind of `<Link>` that knows whether or not it is "active".
171
+
172
+ ### Outlet
173
+
174
+ ```ts
175
+ interface OutletProps {
176
+ context?: unknown;
177
+ }
178
+ declare function Outlet(props: OutletProps): React.ReactElement | null;
179
+ ```
180
+
181
+ An `<Outlet>` should be used in parent route elements to render their child route elements. This allows nested UI to show up when child routes are rendered.
182
+
183
+ ```tsx
184
+ function Dashboard() {
185
+ return (
186
+ <div>
187
+ <h1>Dashboard</h1>
188
+
189
+ {/* This element will render either <DashboardMessages> when the URL is
190
+ "/messages", <DashboardTasks> at "/tasks", or null if it is "/"
191
+ */}
192
+ <Outlet />
193
+ </div>
194
+ );
195
+ }
196
+
197
+ function App() {
198
+ return (
199
+ <Routes>
200
+ <Route path="/" element={<Dashboard />}>
201
+ <Route path="messages" element={<DashboardMessages />} />
202
+ <Route path="tasks" element={<DashboardTasks />} />
203
+ </Route>
204
+ </Routes>
205
+ );
206
+ }
207
+ ```
208
+
209
+ ### Route
210
+
211
+ ```ts
212
+ interface RouteObject {
213
+ path?: string;
214
+ index?: boolean;
215
+ children?: React.ReactNode;
216
+ caseSensitive?: boolean;
217
+ id?: string;
218
+ loader?: LoaderFunction;
219
+ action?: ActionFunction;
220
+ element?: React.ReactNode | null;
221
+ errorElement?: React.ReactNode | null;
222
+ handle?: RouteObject['handle'];
223
+ shouldRevalidate?: ShouldRevalidateFunction;
224
+ }
225
+ ```
226
+
227
+ `Route` represents the route information. A `Route` object couples URL segments to components, data loading and data mutations.
228
+
229
+ `Route` can be used as a plain object, passing to the router creation functions:
230
+
231
+ ```ts
232
+ const router = createBrowserRouter([
233
+ {
234
+ // it renders this element
235
+ element: <Team />,
236
+
237
+ // when the URL matches this segment
238
+ path: 'teams/:teamId',
239
+
240
+ // with this data loaded before rendering
241
+ loader: async ({ request, params }) => {
242
+ return fetch(`/fake/api/teams/${params.teamId}.json`, {
243
+ signal: request.signal,
244
+ });
245
+ },
246
+
247
+ // performing this mutation when data is submitted to it
248
+ action: async ({ request }) => {
249
+ return updateFakeTeam(await request.formData());
250
+ },
251
+
252
+ // and renders this element in case something went wrong
253
+ errorElement: <ErrorBoundary />,
254
+ },
255
+ ]);
256
+ ```
257
+
258
+ You can also declare your routes with JSX and `createRoutesFromElements`, the props to the element are identical to the properties of the route objects:
259
+
260
+ ```ts
261
+ const router = createBrowserRouter(
262
+ createRoutesFromElements(
263
+ <Route
264
+ element={<Team />}
265
+ path="teams/:teamId"
266
+ loader={async ({ params }) => {
267
+ return fetch(`/fake/api/teams/${params.teamId}.json`);
268
+ }}
269
+ action={async ({ request }) => {
270
+ return updateFakeTeam(await request.formData());
271
+ }}
272
+ errorElement={<ErrorBoundary />}
273
+ />,
274
+ ),
275
+ );
276
+ ```
277
+
278
+ ## More
279
+
280
+ You can access to [React Router](https://reactrouter.com/) to get the full API information.
@@ -0,0 +1,35 @@
1
+ # NoSSR
2
+
3
+ The content wrapped by NoSSR will not be rendered at the server, nor will it be rendered during the client side hydrate. it will only be rendered immediately after the entire app is rendered.
4
+
5
+ ## Usage
6
+
7
+ ```tsx
8
+ import { NoSSR } from '@modern-js/runtime/ssr';
9
+
10
+ export default () => <NoSSR>...</NoSSR>;
11
+ ```
12
+
13
+ ## Example
14
+
15
+ In the following code, the `Time` component is used to display the current time. Since the time obtained by server-side rendering and client side hydrate are diff, React will throw an exception. For this case, you can use `NoSSR` to optimize:
16
+
17
+ ```tsx
18
+ import { NoSSR } from '@modern-js/runtime/ssr';
19
+
20
+ function Time() {
21
+ return (
22
+ <NoSSR>
23
+ <div>Time: {Date.now()}</div>
24
+ </NoSSR>
25
+ );
26
+ }
27
+ ```
28
+
29
+ ## Scene
30
+
31
+ In CSR, it is often necessary to render different content according to the browser UA, or a parameter of the current page URL. If the application switches directly to SSR at this time, it is very likely that the results will not meet the expectations.
32
+
33
+ Modern.js provides complete browser side information in the SSR context, which can be used to determine the rendering result of the component on the server side.
34
+
35
+ Even so, if there is too much logic in the application, or the developer wants to use the context later, or does not want some content to be rendered at the server side. developer can use the NoSSR component to exclude this part from server-side rendering.
@@ -0,0 +1,67 @@
1
+ # renderStreaming
2
+
3
+ Used for `React v18` + `Streaming SSR` to render readable streams, used in conjunction with `createRequestHandler`.
4
+
5
+ ## Usage
6
+
7
+ ```ts title="src/entry.server.tsx"
8
+ import {
9
+ renderStreaming,
10
+ createRequestHandler,
11
+ type HandleRequest,
12
+ } from '@modern-js/runtime/ssr/server';
13
+
14
+ const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
15
+ const stream = await renderStreaming(request, <ServerRoot />, options);
16
+
17
+ return new Response(stream, {
18
+ headers: {
19
+ 'content-type': 'text/html; charset=utf-8',
20
+ },
21
+ });
22
+ };
23
+
24
+ export default createRequestHandler(handleRequest);
25
+ ```
26
+
27
+ ## Function Signature
28
+
29
+ ```ts
30
+ export type RenderStreaming = (
31
+ request: Request,
32
+ serverRoot: React.ReactElement,
33
+ optinos: RenderOptions,
34
+ ) => Promise<ReadableStream>;
35
+ ```
36
+
37
+ ## Example
38
+
39
+ ```tsx title="src/entry.server.tsx"
40
+ import {
41
+ renderStreaming,
42
+ createRequestHandler,
43
+ type HandleRequest,
44
+ } from '@modern-js/runtime/ssr/server';
45
+
46
+ const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
47
+ // do something before render
48
+ const stream = await renderStreaming(request, <ServerRoot />, options);
49
+
50
+ // docs: https://developer.mozilla.org/en-US/docs/Web/API/TransformStream
51
+ const transformStream = new TransformStream({
52
+ transform(chunk, controller) {
53
+ // do some transform
54
+ },
55
+ });
56
+
57
+ stream.pipeThrough(transformStream);
58
+
59
+ return new Response(transformStream.readable, {
60
+ headers: {
61
+ 'content-type': 'text/html; charset=utf-8',
62
+ },
63
+ });
64
+ };
65
+
66
+ export default createRequestHandler(handleRequest);
67
+ ```
@@ -0,0 +1,60 @@
1
+ # renderString
2
+
3
+ Used for React String SSR to render strings, used in conjunction with `createRequestHandler`.
4
+
5
+ ## Usage
6
+
7
+ ```tsx title="src/entry.server.tsx"
8
+ import {
9
+ renderString,
10
+ createRequestHandler,
11
+ type HandleRequest,
12
+ } from '@modern-js/runtime/ssr/server';
13
+
14
+ const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
15
+ const body = await renderString(request, <ServerRoot />, options);
16
+
17
+ return new Response(body, {
18
+ headers: {
19
+ 'content-type': 'text/html; charset=utf-8',
20
+ },
21
+ });
22
+ };
23
+
24
+ export default createRequestHandler(handleRequest);
25
+ ```
26
+
27
+ ## Function Signature
28
+
29
+ ```ts
30
+ export type RenderString = (
31
+ request: Request,
32
+ serverRoot: React.ReactElement,
33
+ optinos: RenderOptions,
34
+ ) => Promise<string>;
35
+ ```
36
+
37
+ ## Example
38
+
39
+ ```tsx title="src/entry.server.tsx"
40
+ import {
41
+ renderString,
42
+ createRequestHandler,
43
+ type HandleRequest,
44
+ } from '@modern-js/runtime/ssr/server';
45
+
46
+ const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
47
+ // do something before render
48
+ const body = await renderString(request, <ServerRoot />, options);
49
+
50
+ const newBody = body + '<div>Byte-Dance</div>';
51
+
52
+ return new Response(newBody, {
53
+ headers: {
54
+ 'content-type': 'text/html; charset=utf-8',
55
+ },
56
+ });
57
+ };
58
+
59
+ export default createRequestHandler(handleRequest);
60
+ ```
@@ -0,0 +1,44 @@
1
+ # createRequestHandler
2
+
3
+ Used to customize the Server-Side Rendering entry to return the `requestHandler`.
4
+
5
+ ## Usage
6
+
7
+ ```tsx title="src/entry.server.tsx"
8
+ import {
9
+ renderString,
10
+ createRequestHandler,
11
+ type HandleRequest,
12
+ } from '@modern-js/runtime/ssr/server';
13
+
14
+ const handleRequest: HandleRequest = async (request, ServerRoot, options) => {
15
+ const body = await renderString(request, <ServerRoot />, options);
16
+
17
+ return new Response(body, {
18
+ headers: {
19
+ 'content-type': 'text/html; charset=utf-8',
20
+ },
21
+ });
22
+ };
23
+
24
+ export default createRequestHandler(handleRequest);
25
+ ```
26
+
27
+ ## Function Signature
28
+
29
+ ```ts
30
+ export type HandleRequest = (
31
+ request: Request,
32
+ ServerRoot: React.ComponentType,
33
+ options: HandleRequestOptions,
34
+ ) => Promise<Response>;
35
+
36
+ export type RequestHandler = (
37
+ request: Request,
38
+ options: RequestHandlerOptions,
39
+ ) => Promise<Response>;
40
+
41
+ export type CreateRequestHandler = (
42
+ handleRequest: HandleRequest,
43
+ ) => Promise<RequestHandler>;
44
+ ```
@@ -0,0 +1,40 @@
1
+ # CSS-In-JS API
2
+
3
+ Use Style Component to write CSS.
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import styled from '@modern-js/plugin-styled-components/styled';
9
+ ```
10
+
11
+ ## Function Signature
12
+
13
+ see [styled-component API](https://styled-components.com/docs/api).
14
+
15
+ ## Example
16
+
17
+ ```tsx
18
+ import styled from '@modern-js/plugin-styled-components/styled';
19
+
20
+ const Button = styled.button`
21
+ background: palevioletred;
22
+ border-radius: 3px;
23
+ border: none;
24
+ color: white;
25
+ `;
26
+
27
+ const TomatoButton = styled(Button)`
28
+ background: tomato;
29
+ `;
30
+
31
+ function ButtonExample() {
32
+ return (
33
+ <>
34
+ <Button>I'm purple.</Button>
35
+ <br />
36
+ <TomatoButton>I'm red.</TomatoButton>
37
+ </>
38
+ );
39
+ }
40
+ ```
@@ -0,0 +1,35 @@
1
+ # Head
2
+
3
+ Used to add html elements (such as title, meta, script, etc.) to the `<head>` element, supports SSR.
4
+
5
+ ## Usage
6
+
7
+ ```tsx
8
+ import { Helmet } from '@modern-js/runtime/head';
9
+
10
+ export default () => <Helmet>...</Helmet>;
11
+ ```
12
+
13
+ ## Example
14
+
15
+ ```tsx
16
+ import { Helmet } from '@modern-js/runtime/head';
17
+
18
+ function IndexPage() {
19
+ return (
20
+ <div>
21
+ <Helmet>
22
+ <title>My page title</title>
23
+ <meta name="viewport" content="initial-scale=1.0, width=device-width" />
24
+ </Helmet>
25
+ <p>Hello Modern.js!</p>
26
+ </div>
27
+ );
28
+ }
29
+
30
+ export default IndexPage;
31
+ ```
32
+
33
+ ## More
34
+
35
+ For detail, see [react-helmet](https://github.com/nfl/react-helmet).
@@ -0,0 +1,82 @@
1
+ # loadable
2
+
3
+ Used to create Loadable component
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import loadable from '@modern-js/runtime/loadable';
9
+ ```
10
+
11
+ ## Function Signature
12
+
13
+ ```ts
14
+ type Options = {
15
+ resolveComponent?: (
16
+ module: Module,
17
+ props: Props,
18
+ ) => React.ComponentType<Props>,
19
+ fallback?: JSX.Element;
20
+ ssr?: boolean;
21
+ }
22
+
23
+ function loadable(loadFn: Function, options?: Options) => LoadableComponent
24
+ ```
25
+
26
+ ### Input
27
+
28
+ #### loadFn
29
+
30
+ Used to load component.
31
+
32
+ ```ts
33
+ import loadable from '@modern-js/runtime/loadable';
34
+
35
+ const OtherComponent = loadable(() => import('./OtherComponent'));
36
+ ```
37
+
38
+ #### options.resolveComponent
39
+
40
+ Type: `(module: Module, props: Props) => React.ComponentType<Props>`
41
+
42
+ `module` is the component returned by `loadFn`, and `props` is the props parameter accepted by the component.
43
+
44
+ By default, we think that the default export of file is a react component, so we can render the component directly. But when the component is named export, or we need to dynamically determine which component needs to be rendered according to the `props`, we can use `resolveComponent`. Here is an example:
45
+
46
+ ```ts title='component.js'
47
+ export const Apple = () => 'Apple!';
48
+ export const Orange = () => 'Orange!';
49
+ ```
50
+
51
+ ```ts title='loadable.js'
52
+ const LoadableApple = loadable(() => import('./components'), {
53
+ resolveComponent: components => components.Apple,
54
+ });
55
+ const LoadableOrange = loadable(() => import('./components'), {
56
+ resolveComponent: components => components.Orange,
57
+ });
58
+ const LoadableFruit = loadable(() => import('./components'), {
59
+ resolveComponent: (components, props) => components[props.fruit],
60
+ });
61
+ ```
62
+
63
+ #### options.fallback
64
+
65
+ Whether to display fallback content during loading.
66
+
67
+ #### options.ssr
68
+
69
+ Whether to support SSR, the default value is `true`.
70
+
71
+ ### Return Value
72
+
73
+ #### LoadableComponent
74
+
75
+ ```ts
76
+ type LoadableComponent<Props> = React.ComponentType<
77
+ Props & { fallback?: JSX.Element }
78
+ > & {
79
+ preload(props?: Props): void;
80
+ load(props?: Props): Promise<React.ComponentType<Props>>;
81
+ };
82
+ ```