@bleedingdev/modern-js-main-doc 3.2.0-ultramodern.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.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/builder-doc/docs/en/config/performance/rsdoctor.md +37 -0
- package/builder-doc/docs/zh/config/performance/rsdoctor.md +37 -0
- package/docs/en/_nav.json +36 -0
- package/docs/en/apis/_meta.json +13 -0
- package/docs/en/apis/app/commands.mdx +215 -0
- package/docs/en/apis/app/hooks/_meta.json +28 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +13 -0
- package/docs/en/apis/app/hooks/config/_meta.json +1 -0
- package/docs/en/apis/app/hooks/config/favicon.mdx +29 -0
- package/docs/en/apis/app/hooks/config/html.mdx +9 -0
- package/docs/en/apis/app/hooks/config/icon.mdx +29 -0
- package/docs/en/apis/app/hooks/config/mock.mdx +7 -0
- package/docs/en/apis/app/hooks/config/public.mdx +30 -0
- package/docs/en/apis/app/hooks/config/upload.mdx +54 -0
- package/docs/en/apis/app/hooks/modern-config.mdx +9 -0
- package/docs/en/apis/app/hooks/server/server.mdx +10 -0
- package/docs/en/apis/app/hooks/shared.mdx +7 -0
- package/docs/en/apis/app/hooks/src/app.mdx +30 -0
- package/docs/en/apis/app/hooks/src/entry.mdx +39 -0
- package/docs/en/apis/app/hooks/src/entry.server.mdx +56 -0
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/en/apis/app/hooks/src/routes.mdx +90 -0
- package/docs/en/apis/app/hooks/src/server.mdx +7 -0
- package/docs/en/apis/app/runtime/_meta.json +32 -0
- package/docs/en/apis/app/runtime/bff/use-backend-context.mdx +30 -0
- package/docs/en/apis/app/runtime/core/create-root.mdx +22 -0
- package/docs/en/apis/app/runtime/core/render.mdx +42 -0
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +160 -0
- package/docs/en/apis/app/runtime/router/router.mdx +288 -0
- package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +38 -0
- package/docs/en/apis/app/runtime/ssr/renderStreaming.mdx +71 -0
- package/docs/en/apis/app/runtime/ssr/renderString.mdx +64 -0
- package/docs/en/apis/app/runtime/ssr/requestHandler.mdx +48 -0
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +44 -0
- package/docs/en/apis/app/runtime/utility/head.mdx +38 -0
- package/docs/en/apis/app/runtime/utility/loadable.mdx +85 -0
- package/docs/en/community/_meta.json +11 -0
- package/docs/en/community/blog/2022-0708-updates.md +95 -0
- package/docs/en/community/blog/2022-0910-updates.md +80 -0
- package/docs/en/community/blog/_meta.json +7 -0
- package/docs/en/community/blog/overview.md +67 -0
- package/docs/en/community/blog/v2-release-note.mdx +244 -0
- package/docs/en/community/blog/v3-release-note.mdx +628 -0
- package/docs/en/community/contributing-guide.mdx +257 -0
- package/docs/en/community/releases.mdx +31 -0
- package/docs/en/community/showcase.mdx +15 -0
- package/docs/en/community/team.mdx +29 -0
- package/docs/en/components/auto-upgrade.mdx +0 -0
- package/docs/en/components/bff-upload.mdx +97 -0
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/bundler.mdx +3 -0
- package/docs/en/components/convention-routing-motivation.mdx +0 -0
- package/docs/en/components/debug-app.mdx +15 -0
- package/docs/en/components/default-browserslist.mdx +7 -0
- package/docs/en/components/deploy-command.mdx +14 -0
- package/docs/en/components/deploy.mdx +1 -0
- package/docs/en/components/enable-bff-caution.mdx +3 -0
- package/docs/en/components/enable-bff.mdx +56 -0
- package/docs/en/components/enable-ssg.mdx +49 -0
- package/docs/en/components/entry-mode.mdx +0 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/extend-bff-function.mdx +3 -0
- package/docs/en/components/hono.mdx +120 -0
- package/docs/en/components/init-app.mdx +111 -0
- package/docs/en/components/init-rspack-app.mdx +5 -0
- package/docs/en/components/internal-logger.mdx +25 -0
- package/docs/en/components/internal-metrics.mdx +20 -0
- package/docs/en/components/international/custom-instance-code.mdx +16 -0
- package/docs/en/components/international/init-options-desc.mdx +1 -0
- package/docs/en/components/international/install-command.mdx +10 -0
- package/docs/en/components/international/instance-code.mdx +16 -0
- package/docs/en/components/international/introduce.mdx +5 -0
- package/docs/en/components/international/platform-support.mdx +0 -0
- package/docs/en/components/language-config.mdx +9 -0
- package/docs/en/components/micro-frontend.mdx +6 -0
- package/docs/en/components/micro-master-manifest-config.mdx +15 -0
- package/docs/en/components/micro-runtime-config.mdx +17 -0
- package/docs/en/components/module-federation.mdx +7 -0
- package/docs/en/components/new-entry-tooltip.mdx +0 -0
- package/docs/en/components/nodeVersion.mdx +28 -0
- package/docs/en/components/other-plugins.mdx +0 -0
- package/docs/en/components/output-asset-prefix-extend.mdx +0 -0
- package/docs/en/components/output-distpath-warning.mdx +0 -0
- package/docs/en/components/output-polyfill-extend.mdx +1 -0
- package/docs/en/components/prerequisites.mdx +18 -0
- package/docs/en/components/release-note.mdx +1 -0
- package/docs/en/components/routes-practice.mdx +0 -0
- package/docs/en/components/rsbuild-config-tooltip.mdx +5 -0
- package/docs/en/components/rsbuild.mdx +3 -0
- package/docs/en/components/rsc-deploy-tip.mdx +1 -0
- package/docs/en/components/rspack.mdx +3 -0
- package/docs/en/components/rspackTip.mdx +7 -0
- package/docs/en/components/runtime-cli-config.mdx +0 -0
- package/docs/en/components/serve-command.mdx +22 -0
- package/docs/en/components/ssr-monitor.mdx +3 -0
- package/docs/en/components/stream-ssr-performance.mdx +0 -0
- package/docs/en/components/swc.mdx +3 -0
- package/docs/en/components/tech-stack-node-framework.mdx +1 -0
- package/docs/en/components/turtorials-example-list.mdx +2 -0
- package/docs/en/components/ua-polyfill.mdx +44 -0
- package/docs/en/components/upgrade-browserslist.mdx +0 -0
- package/docs/en/components/upgrade-config-deploy.mdx +0 -0
- package/docs/en/components/upgrade-faq.mdx +0 -0
- package/docs/en/configure/_meta.json +78 -0
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/bff/effect.mdx +152 -0
- package/docs/en/configure/app/bff/prefix.mdx +33 -0
- package/docs/en/configure/app/bff/runtime-framework.mdx +28 -0
- package/docs/en/configure/app/builder-plugins.mdx +70 -0
- package/docs/en/configure/app/dev/asset-prefix.mdx +18 -0
- package/docs/en/configure/app/dev/before-start-url.mdx +21 -0
- package/docs/en/configure/app/dev/client.mdx +45 -0
- package/docs/en/configure/app/dev/hmr.mdx +14 -0
- package/docs/en/configure/app/dev/host.mdx +22 -0
- package/docs/en/configure/app/dev/https.mdx +81 -0
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/live-reload.mdx +14 -0
- package/docs/en/configure/app/dev/progress-bar.mdx +23 -0
- package/docs/en/configure/app/dev/server.mdx +128 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +36 -0
- package/docs/en/configure/app/dev/start-url.mdx +53 -0
- package/docs/en/configure/app/dev/watch-files.mdx +31 -0
- package/docs/en/configure/app/dev/write-to-disk.mdx +14 -0
- package/docs/en/configure/app/experiments/source-build.mdx +33 -0
- package/docs/en/configure/app/html/app-icon.mdx +32 -0
- package/docs/en/configure/app/html/crossorigin.mdx +14 -0
- package/docs/en/configure/app/html/favicon.mdx +20 -0
- package/docs/en/configure/app/html/inject.mdx +14 -0
- package/docs/en/configure/app/html/meta.mdx +28 -0
- package/docs/en/configure/app/html/mount-id.mdx +14 -0
- package/docs/en/configure/app/html/output-structure.mdx +14 -0
- package/docs/en/configure/app/html/script-loading.mdx +14 -0
- package/docs/en/configure/app/html/tags.mdx +19 -0
- package/docs/en/configure/app/html/template-parameters.mdx +37 -0
- package/docs/en/configure/app/html/template.mdx +14 -0
- package/docs/en/configure/app/html/title.mdx +22 -0
- package/docs/en/configure/app/output/asset-prefix.mdx +18 -0
- package/docs/en/configure/app/output/assets-retry.mdx +81 -0
- package/docs/en/configure/app/output/charset.mdx +14 -0
- package/docs/en/configure/app/output/clean-dist-path.mdx +20 -0
- package/docs/en/configure/app/output/convert-to-rem.mdx +83 -0
- package/docs/en/configure/app/output/copy.mdx +14 -0
- package/docs/en/configure/app/output/css-modules.mdx +52 -0
- package/docs/en/configure/app/output/data-uri-limit.mdx +30 -0
- package/docs/en/configure/app/output/disable-css-module-extension.mdx +59 -0
- package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +45 -0
- package/docs/en/configure/app/output/disable-svgr.mdx +20 -0
- package/docs/en/configure/app/output/disable-ts-checker.mdx +53 -0
- package/docs/en/configure/app/output/dist-path.mdx +51 -0
- package/docs/en/configure/app/output/enable-asset-manifest.mdx +40 -0
- package/docs/en/configure/app/output/enable-css-module-tsdeclaration.mdx +32 -0
- package/docs/en/configure/app/output/enable-inline-route-manifests.mdx +20 -0
- package/docs/en/configure/app/output/externals.mdx +24 -0
- package/docs/en/configure/app/output/filename-hash.mdx +14 -0
- package/docs/en/configure/app/output/filename.mdx +59 -0
- package/docs/en/configure/app/output/inject-styles.mdx +14 -0
- package/docs/en/configure/app/output/inline-scripts.mdx +33 -0
- package/docs/en/configure/app/output/inline-styles.mdx +33 -0
- package/docs/en/configure/app/output/legal-comments.mdx +22 -0
- package/docs/en/configure/app/output/minify.mdx +26 -0
- package/docs/en/configure/app/output/override-browserslist.mdx +26 -0
- package/docs/en/configure/app/output/polyfill.mdx +18 -0
- package/docs/en/configure/app/output/source-map.mdx +34 -0
- package/docs/en/configure/app/output/split-route-chunks.mdx +20 -0
- package/docs/en/configure/app/output/ssg.mdx +85 -0
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/output/svg-default-export.mdx +34 -0
- package/docs/en/configure/app/output/temp-dir.mdx +24 -0
- package/docs/en/configure/app/performance/build-cache.mdx +43 -0
- package/docs/en/configure/app/performance/chunk-split.mdx +44 -0
- package/docs/en/configure/app/performance/dns-prefetch.mdx +19 -0
- package/docs/en/configure/app/performance/preconnect.mdx +20 -0
- package/docs/en/configure/app/performance/prefetch.mdx +25 -0
- package/docs/en/configure/app/performance/preload.mdx +27 -0
- package/docs/en/configure/app/performance/print-file-size.mdx +44 -0
- package/docs/en/configure/app/performance/profile.mdx +14 -0
- package/docs/en/configure/app/performance/remove-console.mdx +14 -0
- package/docs/en/configure/app/performance/remove-moment-locale.mdx +14 -0
- package/docs/en/configure/app/performance/rsdoctor.mdx +39 -0
- package/docs/en/configure/app/plugins.mdx +59 -0
- package/docs/en/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/en/configure/app/resolve/alias.mdx +13 -0
- package/docs/en/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/en/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/en/configure/app/resolve/extensions.mdx +18 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +61 -0
- package/docs/en/configure/app/runtime/plugins.mdx +58 -0
- package/docs/en/configure/app/runtime/router.mdx +39 -0
- package/docs/en/configure/app/security/check-syntax.mdx +73 -0
- package/docs/en/configure/app/security/nonce.mdx +19 -0
- package/docs/en/configure/app/security/sri.mdx +24 -0
- package/docs/en/configure/app/server/base-url.mdx +30 -0
- package/docs/en/configure/app/server/port.mdx +22 -0
- package/docs/en/configure/app/server/public-routes.mdx +26 -0
- package/docs/en/configure/app/server/routes.mdx +90 -0
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr-by-entries.mdx +29 -0
- package/docs/en/configure/app/server/ssr.mdx +85 -0
- package/docs/en/configure/app/server/tsconfig-path.mdx +63 -0
- package/docs/en/configure/app/source/alias-strategy.mdx +18 -0
- package/docs/en/configure/app/source/alias.mdx +27 -0
- package/docs/en/configure/app/source/config-dir.mdx +24 -0
- package/docs/en/configure/app/source/decorators.mdx +29 -0
- package/docs/en/configure/app/source/define.mdx +20 -0
- package/docs/en/configure/app/source/disable-default-entries.mdx +32 -0
- package/docs/en/configure/app/source/enable-async-entry.mdx +54 -0
- package/docs/en/configure/app/source/enable-async-pre-entry.mdx +30 -0
- package/docs/en/configure/app/source/entries-dir.mdx +39 -0
- package/docs/en/configure/app/source/entries.mdx +183 -0
- package/docs/en/configure/app/source/exclude.mdx +14 -0
- package/docs/en/configure/app/source/global-vars.mdx +110 -0
- package/docs/en/configure/app/source/include.mdx +40 -0
- package/docs/en/configure/app/source/main-entry-name.mdx +28 -0
- package/docs/en/configure/app/source/pre-entry.mdx +14 -0
- package/docs/en/configure/app/source/transform-import.mdx +31 -0
- package/docs/en/configure/app/split-chunks.mdx +17 -0
- package/docs/en/configure/app/tools/autoprefixer.mdx +48 -0
- package/docs/en/configure/app/tools/bundler-chain.mdx +30 -0
- package/docs/en/configure/app/tools/css-extract.mdx +37 -0
- package/docs/en/configure/app/tools/css-loader.mdx +21 -0
- package/docs/en/configure/app/tools/dev-server.mdx +117 -0
- package/docs/en/configure/app/tools/html-plugin.mdx +45 -0
- package/docs/en/configure/app/tools/less.mdx +85 -0
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +39 -0
- package/docs/en/configure/app/tools/minify-css.mdx +57 -0
- package/docs/en/configure/app/tools/postcss.mdx +38 -0
- package/docs/en/configure/app/tools/rspack.mdx +14 -0
- package/docs/en/configure/app/tools/sass.mdx +82 -0
- package/docs/en/configure/app/tools/style-loader.mdx +14 -0
- package/docs/en/configure/app/tools/swc.mdx +69 -0
- package/docs/en/configure/app/tools/ts-checker.mdx +56 -0
- package/docs/en/configure/app/usage.mdx +276 -0
- package/docs/en/guides/_meta.json +37 -0
- package/docs/en/guides/advanced-features/_meta.json +32 -0
- package/docs/en/guides/advanced-features/bff/_meta.json +10 -0
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +110 -0
- package/docs/en/guides/advanced-features/bff/data-platform.mdx +118 -0
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +120 -0
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +118 -0
- package/docs/en/guides/advanced-features/bff/function.mdx +261 -0
- package/docs/en/guides/advanced-features/bff/operators.mdx +629 -0
- package/docs/en/guides/advanced-features/bff/sdk.mdx +116 -0
- package/docs/en/guides/advanced-features/bff/upload.mdx +7 -0
- package/docs/en/guides/advanced-features/bff.mdx +22 -0
- package/docs/en/guides/advanced-features/build-performance.mdx +134 -0
- package/docs/en/guides/advanced-features/compatibility.mdx +81 -0
- package/docs/en/guides/advanced-features/international/_meta.json +10 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +132 -0
- package/docs/en/guides/advanced-features/international/api.mdx +235 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +290 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +221 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +130 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +112 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +158 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +134 -0
- package/docs/en/guides/advanced-features/international.mdx +29 -0
- package/docs/en/guides/advanced-features/low-level.mdx +50 -0
- package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +81 -0
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +163 -0
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +101 -0
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +54 -0
- package/docs/en/guides/advanced-features/server-monitor/_meta.json +1 -0
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +19 -0
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +41 -0
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +242 -0
- package/docs/en/guides/advanced-features/source-build.mdx +168 -0
- package/docs/en/guides/advanced-features/web-server.mdx +284 -0
- package/docs/en/guides/basic-features/_meta.json +49 -0
- package/docs/en/guides/basic-features/alias.mdx +106 -0
- package/docs/en/guides/basic-features/css/_meta.json +1 -0
- package/docs/en/guides/basic-features/css/css-in-js.mdx +69 -0
- package/docs/en/guides/basic-features/css/css-modules.mdx +212 -0
- package/docs/en/guides/basic-features/css/css.mdx +31 -0
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +27 -0
- package/docs/en/guides/basic-features/data/_meta.json +1 -0
- package/docs/en/guides/basic-features/data/data-cache.mdx +515 -0
- package/docs/en/guides/basic-features/data/data-fetch.mdx +419 -0
- package/docs/en/guides/basic-features/data/data-write.mdx +230 -0
- package/docs/en/guides/basic-features/debug/_meta.json +1 -0
- package/docs/en/guides/basic-features/debug/mock.mdx +102 -0
- package/docs/en/guides/basic-features/debug/proxy.mdx +25 -0
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +48 -0
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +100 -0
- package/docs/en/guides/basic-features/deploy.mdx +448 -0
- package/docs/en/guides/basic-features/env-vars.mdx +181 -0
- package/docs/en/guides/basic-features/html.mdx +259 -0
- package/docs/en/guides/basic-features/output-files.mdx +145 -0
- package/docs/en/guides/basic-features/render/_meta.json +10 -0
- package/docs/en/guides/basic-features/render/before-render.mdx +108 -0
- package/docs/en/guides/basic-features/render/overview.mdx +52 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +534 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +167 -0
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +201 -0
- package/docs/en/guides/basic-features/render/ssr.mdx +323 -0
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +267 -0
- package/docs/en/guides/basic-features/render/tanstack-rsc.mdx +226 -0
- package/docs/en/guides/basic-features/routes/_meta.json +1 -0
- package/docs/en/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/en/guides/basic-features/routes/routes.mdx +517 -0
- package/docs/en/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +124 -0
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +172 -0
- package/docs/en/guides/basic-features/static-assets/wasm-assets.mdx +66 -0
- package/docs/en/guides/basic-features/static-assets.mdx +164 -0
- package/docs/en/guides/basic-features/testing/_meta.json +1 -0
- package/docs/en/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/en/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/en/guides/basic-features/testing/playwright.mdx +111 -0
- package/docs/en/guides/basic-features/testing/rstest.mdx +163 -0
- package/docs/en/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/en/guides/concept/_meta.json +1 -0
- package/docs/en/guides/concept/builder.mdx +60 -0
- package/docs/en/guides/concept/entries.mdx +325 -0
- package/docs/en/guides/concept/server.mdx +35 -0
- package/docs/en/guides/get-started/_meta.json +8 -0
- package/docs/en/guides/get-started/glossary.mdx +63 -0
- package/docs/en/guides/get-started/introduction.mdx +45 -0
- package/docs/en/guides/get-started/quick-start.mdx +92 -0
- package/docs/en/guides/get-started/tech-stack.mdx +91 -0
- package/docs/en/guides/get-started/ultramodern.mdx +98 -0
- package/docs/en/guides/get-started/upgrade.mdx +114 -0
- package/docs/en/guides/topic-detail/_meta.json +8 -0
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -0
- package/docs/en/guides/topic-detail/module-federation/application.mdx +116 -0
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +104 -0
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +36 -0
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +170 -0
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +202 -0
- package/docs/en/guides/troubleshooting/_meta.json +1 -0
- package/docs/en/guides/troubleshooting/builder.mdx +114 -0
- package/docs/en/guides/troubleshooting/cli.mdx +39 -0
- package/docs/en/guides/troubleshooting/dependencies.mdx +123 -0
- package/docs/en/guides/troubleshooting/hmr.mdx +148 -0
- package/docs/en/guides/upgrade/_meta.json +1 -0
- package/docs/en/guides/upgrade/config.mdx +949 -0
- package/docs/en/guides/upgrade/entry.mdx +463 -0
- package/docs/en/guides/upgrade/other.mdx +183 -0
- package/docs/en/guides/upgrade/overview.mdx +33 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +92 -0
- package/docs/en/guides/upgrade/web-server.md +109 -0
- package/docs/en/index.md +4 -0
- package/docs/en/plugin/_meta.json +25 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -0
- package/docs/en/plugin/cli-plugins/api.mdx +573 -0
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +135 -0
- package/docs/en/plugin/introduction.mdx +153 -0
- package/docs/en/plugin/official/_meta.json +7 -0
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -0
- package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +4 -0
- package/docs/en/plugin/plugin-system.mdx +244 -0
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -0
- package/docs/en/plugin/runtime-plugins/api.mdx +193 -0
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +29 -0
- package/docs/en/plugin/server-plugins/_meta.json +1 -0
- package/docs/en/plugin/server-plugins/api.mdx +212 -0
- package/docs/en/plugin/server-plugins/life-cycle.mdx +43 -0
- package/docs/en/tutorials/_meta.json +7 -0
- package/docs/en/tutorials/examples/csr-auth.mdx +31 -0
- package/docs/en/tutorials/foundations/introduction.mdx +22 -0
- package/docs/zh/_nav.json +36 -0
- package/docs/zh/apis/_meta.json +13 -0
- package/docs/zh/apis/app/commands.mdx +215 -0
- package/docs/zh/apis/app/hooks/_meta.json +28 -0
- package/docs/zh/apis/app/hooks/api/lambda.mdx +14 -0
- package/docs/zh/apis/app/hooks/config/_meta.json +1 -0
- package/docs/zh/apis/app/hooks/config/favicon.mdx +29 -0
- package/docs/zh/apis/app/hooks/config/html.mdx +9 -0
- package/docs/zh/apis/app/hooks/config/icon.mdx +29 -0
- package/docs/zh/apis/app/hooks/config/mock.mdx +7 -0
- package/docs/zh/apis/app/hooks/config/public.mdx +30 -0
- package/docs/zh/apis/app/hooks/config/upload.mdx +54 -0
- package/docs/zh/apis/app/hooks/modern-config.mdx +9 -0
- package/docs/zh/apis/app/hooks/server/server.mdx +10 -0
- package/docs/zh/apis/app/hooks/shared.mdx +7 -0
- package/docs/zh/apis/app/hooks/src/app.mdx +36 -0
- package/docs/zh/apis/app/hooks/src/entry.mdx +39 -0
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +56 -0
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/zh/apis/app/hooks/src/routes.mdx +90 -0
- package/docs/zh/apis/app/hooks/src/server.mdx +7 -0
- package/docs/zh/apis/app/runtime/_meta.json +32 -0
- package/docs/zh/apis/app/runtime/bff/use-backend-context.mdx +31 -0
- package/docs/zh/apis/app/runtime/core/create-root.mdx +22 -0
- package/docs/zh/apis/app/runtime/core/render.mdx +43 -0
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +160 -0
- package/docs/zh/apis/app/runtime/router/router.mdx +287 -0
- package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +38 -0
- package/docs/zh/apis/app/runtime/ssr/renderStreaming.mdx +71 -0
- package/docs/zh/apis/app/runtime/ssr/renderString.mdx +64 -0
- package/docs/zh/apis/app/runtime/ssr/requestHandler.mdx +48 -0
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +44 -0
- package/docs/zh/apis/app/runtime/utility/head.mdx +38 -0
- package/docs/zh/apis/app/runtime/utility/loadable.mdx +83 -0
- package/docs/zh/community/_meta.json +11 -0
- package/docs/zh/community/blog/2022-0708-updates.md +95 -0
- package/docs/zh/community/blog/2022-0910-updates.md +80 -0
- package/docs/zh/community/blog/_meta.json +7 -0
- package/docs/zh/community/blog/overview.md +74 -0
- package/docs/zh/community/blog/v2-release-note.mdx +244 -0
- package/docs/zh/community/blog/v3-release-note.mdx +628 -0
- package/docs/zh/community/contributing-guide.mdx +256 -0
- package/docs/zh/community/releases.mdx +31 -0
- package/docs/zh/community/showcase.mdx +15 -0
- package/docs/zh/community/team.mdx +29 -0
- package/docs/zh/components/auto-upgrade.mdx +0 -0
- package/docs/zh/components/bff-operator-code.mdx +5 -0
- package/docs/zh/components/bff-upload.mdx +98 -0
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/bundler.mdx +3 -0
- package/docs/zh/components/convention-routing-motivation.mdx +0 -0
- package/docs/zh/components/debug-app.mdx +16 -0
- package/docs/zh/components/default-browserslist.mdx +7 -0
- package/docs/zh/components/deploy-command.mdx +14 -0
- package/docs/zh/components/deploy.mdx +1 -0
- package/docs/zh/components/enable-bff-caution.mdx +4 -0
- package/docs/zh/components/enable-bff.mdx +56 -0
- package/docs/zh/components/enable-ssg.mdx +49 -0
- package/docs/zh/components/entry-mode.mdx +0 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/extend-bff-function.mdx +3 -0
- package/docs/zh/components/hono.mdx +120 -0
- package/docs/zh/components/init-app.mdx +111 -0
- package/docs/zh/components/init-rspack-app.mdx +5 -0
- package/docs/zh/components/internal-logger.mdx +25 -0
- package/docs/zh/components/internal-metrics.mdx +20 -0
- package/docs/zh/components/international/custom-instance-code.mdx +16 -0
- package/docs/zh/components/international/init-options-desc.mdx +1 -0
- package/docs/zh/components/international/install-command.mdx +11 -0
- package/docs/zh/components/international/instance-code.mdx +16 -0
- package/docs/zh/components/international/introduce.mdx +5 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/language-config.mdx +9 -0
- package/docs/zh/components/micro-frontend.mdx +6 -0
- package/docs/zh/components/micro-master-manifest-config.mdx +15 -0
- package/docs/zh/components/micro-runtime-config.mdx +17 -0
- package/docs/zh/components/module-federation.mdx +7 -0
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +28 -0
- package/docs/zh/components/other-plugins.mdx +0 -0
- package/docs/zh/components/output-asset-prefix-extend.mdx +0 -0
- package/docs/zh/components/output-distpath-warning.mdx +0 -0
- package/docs/zh/components/output-polyfill-extend.mdx +1 -0
- package/docs/zh/components/prerequisites.mdx +18 -0
- package/docs/zh/components/release-note.mdx +1 -0
- package/docs/zh/components/routes-practice.mdx +0 -0
- package/docs/zh/components/rsbuild-config-tooltip.mdx +5 -0
- package/docs/zh/components/rsbuild.mdx +3 -0
- package/docs/zh/components/rsc-deploy-tip.mdx +1 -0
- package/docs/zh/components/rspack.mdx +3 -0
- package/docs/zh/components/rspackTip.mdx +7 -0
- package/docs/zh/components/runtime-cli-config.mdx +0 -0
- package/docs/zh/components/self-route-example.mdx +21 -0
- package/docs/zh/components/serve-command.mdx +22 -0
- package/docs/zh/components/ssr-monitor.mdx +3 -0
- package/docs/zh/components/stream-ssr-performance.mdx +0 -0
- package/docs/zh/components/swc.mdx +3 -0
- package/docs/zh/components/tech-stack-node-framework.mdx +1 -0
- package/docs/zh/components/turtorials-example-list.mdx +2 -0
- package/docs/zh/components/ua-polyfill.mdx +44 -0
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/components/upgrade-config-deploy.mdx +0 -0
- package/docs/zh/components/upgrade-faq.mdx +0 -0
- package/docs/zh/configure/_meta.json +78 -0
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/bff/effect.mdx +152 -0
- package/docs/zh/configure/app/bff/prefix.mdx +33 -0
- package/docs/zh/configure/app/bff/runtime-framework.mdx +28 -0
- package/docs/zh/configure/app/builder-plugins.mdx +72 -0
- package/docs/zh/configure/app/dev/asset-prefix.mdx +18 -0
- package/docs/zh/configure/app/dev/before-start-url.mdx +21 -0
- package/docs/zh/configure/app/dev/client.mdx +45 -0
- package/docs/zh/configure/app/dev/hmr.mdx +14 -0
- package/docs/zh/configure/app/dev/host.mdx +22 -0
- package/docs/zh/configure/app/dev/https.mdx +82 -0
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/live-reload.mdx +14 -0
- package/docs/zh/configure/app/dev/progress-bar.mdx +23 -0
- package/docs/zh/configure/app/dev/server.mdx +128 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +36 -0
- package/docs/zh/configure/app/dev/start-url.mdx +54 -0
- package/docs/zh/configure/app/dev/watch-files.mdx +31 -0
- package/docs/zh/configure/app/dev/write-to-disk.mdx +14 -0
- package/docs/zh/configure/app/experiments/source-build.mdx +35 -0
- package/docs/zh/configure/app/html/app-icon.mdx +32 -0
- package/docs/zh/configure/app/html/crossorigin.mdx +15 -0
- package/docs/zh/configure/app/html/favicon.mdx +21 -0
- package/docs/zh/configure/app/html/inject.mdx +14 -0
- package/docs/zh/configure/app/html/meta.mdx +28 -0
- package/docs/zh/configure/app/html/mount-id.mdx +14 -0
- package/docs/zh/configure/app/html/output-structure.mdx +14 -0
- package/docs/zh/configure/app/html/script-loading.mdx +14 -0
- package/docs/zh/configure/app/html/tags.mdx +19 -0
- package/docs/zh/configure/app/html/template-parameters.mdx +37 -0
- package/docs/zh/configure/app/html/template.mdx +14 -0
- package/docs/zh/configure/app/html/title.mdx +22 -0
- package/docs/zh/configure/app/output/asset-prefix.mdx +18 -0
- package/docs/zh/configure/app/output/assets-retry.mdx +81 -0
- package/docs/zh/configure/app/output/charset.mdx +14 -0
- package/docs/zh/configure/app/output/clean-dist-path.mdx +20 -0
- package/docs/zh/configure/app/output/convert-to-rem.mdx +84 -0
- package/docs/zh/configure/app/output/copy.mdx +14 -0
- package/docs/zh/configure/app/output/css-modules.mdx +52 -0
- package/docs/zh/configure/app/output/data-uri-limit.mdx +30 -0
- package/docs/zh/configure/app/output/disable-css-module-extension.mdx +59 -0
- package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +45 -0
- package/docs/zh/configure/app/output/disable-svgr.mdx +21 -0
- package/docs/zh/configure/app/output/disable-ts-checker.mdx +53 -0
- package/docs/zh/configure/app/output/dist-path.mdx +50 -0
- package/docs/zh/configure/app/output/enable-asset-manifest.mdx +40 -0
- package/docs/zh/configure/app/output/enable-css-module-tsdeclaration.mdx +32 -0
- package/docs/zh/configure/app/output/enable-inline-route-manifests.mdx +21 -0
- package/docs/zh/configure/app/output/externals.mdx +24 -0
- package/docs/zh/configure/app/output/filename-hash.mdx +14 -0
- package/docs/zh/configure/app/output/filename.mdx +62 -0
- package/docs/zh/configure/app/output/inject-styles.mdx +14 -0
- package/docs/zh/configure/app/output/inline-scripts.mdx +33 -0
- package/docs/zh/configure/app/output/inline-styles.mdx +33 -0
- package/docs/zh/configure/app/output/legal-comments.mdx +22 -0
- package/docs/zh/configure/app/output/minify.mdx +26 -0
- package/docs/zh/configure/app/output/override-browserslist.mdx +26 -0
- package/docs/zh/configure/app/output/polyfill.mdx +18 -0
- package/docs/zh/configure/app/output/source-map.mdx +38 -0
- package/docs/zh/configure/app/output/split-route-chunks.mdx +20 -0
- package/docs/zh/configure/app/output/ssg.mdx +84 -0
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/output/svg-default-export.mdx +34 -0
- package/docs/zh/configure/app/output/temp-dir.mdx +22 -0
- package/docs/zh/configure/app/performance/build-cache.mdx +43 -0
- package/docs/zh/configure/app/performance/chunk-split.mdx +44 -0
- package/docs/zh/configure/app/performance/dns-prefetch.mdx +19 -0
- package/docs/zh/configure/app/performance/preconnect.mdx +20 -0
- package/docs/zh/configure/app/performance/prefetch.mdx +25 -0
- package/docs/zh/configure/app/performance/preload.mdx +27 -0
- package/docs/zh/configure/app/performance/print-file-size.mdx +44 -0
- package/docs/zh/configure/app/performance/profile.mdx +14 -0
- package/docs/zh/configure/app/performance/remove-console.mdx +14 -0
- package/docs/zh/configure/app/performance/remove-moment-locale.mdx +14 -0
- package/docs/zh/configure/app/performance/rsdoctor.mdx +39 -0
- package/docs/zh/configure/app/plugins.mdx +59 -0
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/zh/configure/app/resolve/alias.mdx +13 -0
- package/docs/zh/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/zh/configure/app/resolve/dedupe.mdx +14 -0
- package/docs/zh/configure/app/resolve/extensions.mdx +18 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +58 -0
- package/docs/zh/configure/app/runtime/plugins.mdx +58 -0
- package/docs/zh/configure/app/runtime/router.mdx +39 -0
- package/docs/zh/configure/app/security/check-syntax.mdx +73 -0
- package/docs/zh/configure/app/security/nonce.mdx +19 -0
- package/docs/zh/configure/app/security/sri.mdx +24 -0
- package/docs/zh/configure/app/server/base-url.mdx +30 -0
- package/docs/zh/configure/app/server/port.mdx +23 -0
- package/docs/zh/configure/app/server/public-routes.mdx +26 -0
- package/docs/zh/configure/app/server/routes.mdx +90 -0
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr-by-entries.mdx +29 -0
- package/docs/zh/configure/app/server/ssr.mdx +85 -0
- package/docs/zh/configure/app/server/tsconfig-path.mdx +63 -0
- package/docs/zh/configure/app/source/alias-strategy.mdx +18 -0
- package/docs/zh/configure/app/source/alias.mdx +27 -0
- package/docs/zh/configure/app/source/config-dir.mdx +24 -0
- package/docs/zh/configure/app/source/decorators.mdx +27 -0
- package/docs/zh/configure/app/source/define.mdx +20 -0
- package/docs/zh/configure/app/source/disable-default-entries.mdx +32 -0
- package/docs/zh/configure/app/source/enable-async-entry.mdx +54 -0
- package/docs/zh/configure/app/source/enable-async-pre-entry.mdx +77 -0
- package/docs/zh/configure/app/source/entries-dir.mdx +39 -0
- package/docs/zh/configure/app/source/entries.mdx +185 -0
- package/docs/zh/configure/app/source/exclude.mdx +14 -0
- package/docs/zh/configure/app/source/global-vars.mdx +109 -0
- package/docs/zh/configure/app/source/include.mdx +40 -0
- package/docs/zh/configure/app/source/main-entry-name.mdx +28 -0
- package/docs/zh/configure/app/source/pre-entry.mdx +14 -0
- package/docs/zh/configure/app/source/transform-import.mdx +31 -0
- package/docs/zh/configure/app/split-chunks.mdx +17 -0
- package/docs/zh/configure/app/tools/autoprefixer.mdx +48 -0
- package/docs/zh/configure/app/tools/bundler-chain.mdx +33 -0
- package/docs/zh/configure/app/tools/css-extract.mdx +34 -0
- package/docs/zh/configure/app/tools/css-loader.mdx +21 -0
- package/docs/zh/configure/app/tools/dev-server.mdx +117 -0
- package/docs/zh/configure/app/tools/html-plugin.mdx +45 -0
- package/docs/zh/configure/app/tools/less.mdx +86 -0
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +39 -0
- package/docs/zh/configure/app/tools/minify-css.mdx +57 -0
- package/docs/zh/configure/app/tools/postcss.mdx +39 -0
- package/docs/zh/configure/app/tools/rspack.mdx +14 -0
- package/docs/zh/configure/app/tools/sass.mdx +80 -0
- package/docs/zh/configure/app/tools/style-loader.mdx +14 -0
- package/docs/zh/configure/app/tools/swc.mdx +69 -0
- package/docs/zh/configure/app/tools/ts-checker.mdx +56 -0
- package/docs/zh/configure/app/usage.mdx +276 -0
- package/docs/zh/guides/_meta.json +37 -0
- package/docs/zh/guides/advanced-features/_meta.json +32 -0
- package/docs/zh/guides/advanced-features/bff/_meta.json +10 -0
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +112 -0
- package/docs/zh/guides/advanced-features/bff/data-platform.mdx +118 -0
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +125 -0
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +118 -0
- package/docs/zh/guides/advanced-features/bff/function.mdx +262 -0
- package/docs/zh/guides/advanced-features/bff/operators.mdx +629 -0
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +117 -0
- package/docs/zh/guides/advanced-features/bff/upload.mdx +7 -0
- package/docs/zh/guides/advanced-features/bff.mdx +21 -0
- package/docs/zh/guides/advanced-features/build-performance.mdx +134 -0
- package/docs/zh/guides/advanced-features/compatibility.mdx +80 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +10 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +132 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +234 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +290 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +219 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +130 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +112 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +155 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +134 -0
- package/docs/zh/guides/advanced-features/international.mdx +29 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +48 -0
- package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +81 -0
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +162 -0
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +101 -0
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +54 -0
- package/docs/zh/guides/advanced-features/server-monitor/_meta.json +1 -0
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +21 -0
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +42 -0
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +240 -0
- package/docs/zh/guides/advanced-features/source-build.mdx +168 -0
- package/docs/zh/guides/advanced-features/web-server.mdx +281 -0
- package/docs/zh/guides/basic-features/_meta.json +49 -0
- package/docs/zh/guides/basic-features/alias.mdx +100 -0
- package/docs/zh/guides/basic-features/css/_meta.json +1 -0
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +69 -0
- package/docs/zh/guides/basic-features/css/css-modules.mdx +218 -0
- package/docs/zh/guides/basic-features/css/css.mdx +31 -0
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +27 -0
- package/docs/zh/guides/basic-features/data/_meta.json +1 -0
- package/docs/zh/guides/basic-features/data/data-cache.mdx +498 -0
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +421 -0
- package/docs/zh/guides/basic-features/data/data-write.mdx +234 -0
- package/docs/zh/guides/basic-features/debug/_meta.json +1 -0
- package/docs/zh/guides/basic-features/debug/mock.mdx +102 -0
- package/docs/zh/guides/basic-features/debug/proxy.mdx +25 -0
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +48 -0
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +92 -0
- package/docs/zh/guides/basic-features/deploy.mdx +432 -0
- package/docs/zh/guides/basic-features/env-vars.mdx +180 -0
- package/docs/zh/guides/basic-features/html.mdx +262 -0
- package/docs/zh/guides/basic-features/output-files.mdx +145 -0
- package/docs/zh/guides/basic-features/render/_meta.json +10 -0
- package/docs/zh/guides/basic-features/render/before-render.mdx +108 -0
- package/docs/zh/guides/basic-features/render/overview.mdx +53 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +619 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +168 -0
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +205 -0
- package/docs/zh/guides/basic-features/render/ssr.mdx +334 -0
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +276 -0
- package/docs/zh/guides/basic-features/render/tanstack-rsc.mdx +226 -0
- package/docs/zh/guides/basic-features/routes/_meta.json +1 -0
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +426 -0
- package/docs/zh/guides/basic-features/routes/routes.mdx +521 -0
- package/docs/zh/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +124 -0
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +174 -0
- package/docs/zh/guides/basic-features/static-assets/wasm-assets.mdx +66 -0
- package/docs/zh/guides/basic-features/static-assets.mdx +160 -0
- package/docs/zh/guides/basic-features/testing/_meta.json +1 -0
- package/docs/zh/guides/basic-features/testing/cypress.mdx +95 -0
- package/docs/zh/guides/basic-features/testing/jest.mdx +148 -0
- package/docs/zh/guides/basic-features/testing/playwright.mdx +112 -0
- package/docs/zh/guides/basic-features/testing/rstest.mdx +163 -0
- package/docs/zh/guides/basic-features/testing/vitest.mdx +100 -0
- package/docs/zh/guides/concept/_meta.json +1 -0
- package/docs/zh/guides/concept/builder.mdx +60 -0
- package/docs/zh/guides/concept/entries.mdx +323 -0
- package/docs/zh/guides/concept/server.mdx +35 -0
- package/docs/zh/guides/get-started/_meta.json +8 -0
- package/docs/zh/guides/get-started/glossary.mdx +63 -0
- package/docs/zh/guides/get-started/introduction.mdx +45 -0
- package/docs/zh/guides/get-started/quick-start.mdx +90 -0
- package/docs/zh/guides/get-started/tech-stack.mdx +91 -0
- package/docs/zh/guides/get-started/ultramodern.mdx +80 -0
- package/docs/zh/guides/get-started/upgrade.mdx +114 -0
- package/docs/zh/guides/topic-detail/_meta.json +8 -0
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -0
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +117 -0
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +104 -0
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +35 -0
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +168 -0
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +200 -0
- package/docs/zh/guides/troubleshooting/_meta.json +1 -0
- package/docs/zh/guides/troubleshooting/builder.mdx +134 -0
- package/docs/zh/guides/troubleshooting/cli.mdx +39 -0
- package/docs/zh/guides/troubleshooting/dependencies.mdx +123 -0
- package/docs/zh/guides/troubleshooting/hmr.mdx +148 -0
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +953 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +190 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +92 -0
- package/docs/zh/guides/upgrade/web-server.md +111 -0
- package/docs/zh/index.md +4 -0
- package/docs/zh/plugin/_meta.json +25 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +569 -0
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +135 -0
- package/docs/zh/plugin/introduction.mdx +153 -0
- package/docs/zh/plugin/official/_meta.json +7 -0
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -0
- package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +4 -0
- package/docs/zh/plugin/plugin-system.mdx +231 -0
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -0
- package/docs/zh/plugin/runtime-plugins/api.mdx +193 -0
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +29 -0
- package/docs/zh/plugin/server-plugins/_meta.json +1 -0
- package/docs/zh/plugin/server-plugins/api.mdx +212 -0
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +43 -0
- package/docs/zh/tutorials/_meta.json +7 -0
- package/docs/zh/tutorials/examples/csr-auth.mdx +31 -0
- package/docs/zh/tutorials/foundations/introduction.mdx +22 -0
- package/i18n.json +142 -0
- package/main-doc/docs/en/guides/get-started/ultramodern.mdx +320 -0
- package/main-doc/docs/zh/guides/get-started/ultramodern.mdx +304 -0
- package/package.json +52 -0
- package/rspress.config.ts +153 -0
- package/src/components/ContentCard/index.module.scss +65 -0
- package/src/components/ContentCard/index.tsx +24 -0
- package/src/components/FeatureLayout/index.module.css +8 -0
- package/src/components/FeatureLayout/index.tsx +8 -0
- package/src/components/Footer/index.tsx +118 -0
- package/src/components/Footer/styles.module.scss +49 -0
- package/src/components/FrameworkCode/index.tsx +605 -0
- package/src/components/ListCard/index.module.css +57 -0
- package/src/components/ListCard/index.tsx +26 -0
- package/src/components/Mermaid/index.tsx +64 -0
- package/src/components/Mermaid/style.scss +221 -0
- package/src/components/RandomMemberList/index.module.scss +35 -0
- package/src/components/RandomMemberList/index.tsx +122 -0
- package/src/components/RsbuildLink/index.tsx +19 -0
- package/src/components/Sandpack/index.css +10 -0
- package/src/components/Sandpack/index.tsx +22 -0
- package/src/components/SecondaryTitle/index.module.css +14 -0
- package/src/components/SecondaryTitle/index.tsx +15 -0
- package/src/components/ShowcaseList/index.module.scss +80 -0
- package/src/components/ShowcaseList/index.tsx +39 -0
- package/src/components/ShowcaseList/useShowcases.ts +101 -0
- package/src/components/SolutionCards/index.module.scss +73 -0
- package/src/components/SolutionCards/index.tsx +30 -0
- package/src/custom.scss +15 -0
- package/src/global.d.ts +28 -0
- package/src/i18n/enUS.ts +54 -0
- package/src/i18n/index.ts +18 -0
- package/src/i18n/zhCN.ts +54 -0
- package/src/index.ts +5 -0
- package/src/pages/index.module.scss +349 -0
- package/src/pages/index.tsx +133 -0
- package/src/sandbox/csr-auth/src/routes/Auth-tsx.txt +74 -0
- package/src/sandbox/csr-auth/src/routes/fakeAuth-ts.txt +16 -0
- package/src/sandbox/csr-auth/src/routes/layout-tsx.txt +21 -0
- package/src/sandbox/csr-auth/src/routes/login/page-tsx.txt +40 -0
- package/src/sandbox/csr-auth/src/routes/page-tsx.txt +17 -0
- package/src/sandbox/csr-auth/src/routes/protected/page-tsx.txt +11 -0
- package/static/img/favicon.ico +0 -0
- package/static/img/features/ai.svg +1 -0
- package/static/img/features/api.svg +1 -0
- package/static/img/features/app.svg +1 -0
- package/static/img/features/blocks.svg +1 -0
- package/static/img/features/browser.svg +12 -0
- package/static/img/features/cloud.svg +1 -0
- package/static/img/features/coding-backend.svg +1 -0
- package/static/img/features/compiler.svg +1 -0
- package/static/img/features/css-file.svg +1 -0
- package/static/img/features/customize.svg +1 -0
- package/static/img/features/developer.svg +1 -0
- package/static/img/features/dynamic.svg +1 -0
- package/static/img/features/editor.svg +1 -0
- package/static/img/features/framework-config.svg +1 -0
- package/static/img/features/framework.svg +1 -0
- package/static/img/features/frameworks.svg +1 -0
- package/static/img/features/html.svg +1 -0
- package/static/img/features/icon2.svg +1 -0
- package/static/img/features/javascript.svg +1 -0
- package/static/img/features/monorepo.svg +1 -0
- package/static/img/features/product.svg +1 -0
- package/static/img/features/server-network.svg +1 -0
- package/static/img/features/serverless.svg +1 -0
- package/static/img/features/test.svg +1 -0
- package/static/img/features/trinity.svg +1 -0
- package/static/img/features/unity.svg +1 -0
- package/static/img/features/url.svg +1 -0
- package/static/img/features/visual.svg +1 -0
- package/static/img/features/web-server.svg +1 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 数据获取
|
|
3
|
+
sidebar_position: 3
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 数据获取
|
|
7
|
+
|
|
8
|
+
Modern.js 中提供了开箱即用的数据获取能力,开发者可以通过这些 API,在项目中获取数据。需要注意的是,这些 API 并不帮助应用发起请求,而是帮助开发者更好地管理数据,提升项目的性能。
|
|
9
|
+
|
|
10
|
+
## 什么是 Data Loader
|
|
11
|
+
|
|
12
|
+
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `loader` 函数,我们称为 Data Loader,它会在对应的路由组件渲染之前执行,为组件提供数据。如下面示例:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
.
|
|
16
|
+
└── routes
|
|
17
|
+
├── layout.tsx
|
|
18
|
+
└── user
|
|
19
|
+
├── layout.tsx
|
|
20
|
+
├── layout.data.ts
|
|
21
|
+
├── page.tsx
|
|
22
|
+
└── page.data.ts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
在 `routes/user/page.data.ts` 文件中,可以导出一个 `loader` 函数:
|
|
26
|
+
|
|
27
|
+
```ts title="routes/user/page.data.ts"
|
|
28
|
+
export type ProfileData = {
|
|
29
|
+
/* some types */
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const loader = async (): Promise<ProfileData> => {
|
|
33
|
+
const res = await fetch('https://api/user/profile');
|
|
34
|
+
return await res.json();
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
在路由组件中,你可以通过 `useLoaderData` 函数获取数据:
|
|
39
|
+
|
|
40
|
+
```ts title="routes/user/page.tsx"
|
|
41
|
+
import { useLoaderData } from '@modern-js/runtime/router';
|
|
42
|
+
import type { ProfileData } from './page.data.ts';
|
|
43
|
+
|
|
44
|
+
export default function UserPage() {
|
|
45
|
+
const profileData = useLoaderData() as ProfileData;
|
|
46
|
+
return <div>{profileData}</div>;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
:::caution
|
|
51
|
+
路由组件和 `.data` 文件共享类型,要使用 `import type` 语法,避免引入预期之外的副作用。
|
|
52
|
+
:::
|
|
53
|
+
|
|
54
|
+
在 CSR 项目中,`loader` 函数会在客户端执行,`loader` 函数内可以使用浏览器的 API。
|
|
55
|
+
|
|
56
|
+
在 SSR 项目中,不管是首屏还是在客户端的导航,`loader` 函数只会在服务端执行,这里可以调用任意的 Node.js API,同时这里使用的任何依赖和代码都不会包含在客户端的 bundle 中。
|
|
57
|
+
|
|
58
|
+
当在浏览器端导航时,基于[约定式路由](/guides/basic-features/routes/routes),Modern.js 能够支持所有的 `loader` 函数并行执行(请求)。即当访问 `/user/profile` 时,`/user` 和 `/user/profile` 下的 `loader` 函数都会并行执行(请求),这种方式解决了部分请求、渲染瀑布流的问题,较大的提升了页面性能。
|
|
59
|
+
|
|
60
|
+
:::tip
|
|
61
|
+
`loader` 的职责是数据获取,入参已提供路由参数和请求信息,一般无需访问浏览器 API。建议保持环境无关性,以便未来使用 SSR。
|
|
62
|
+
:::
|
|
63
|
+
|
|
64
|
+
## `loader` 函数
|
|
65
|
+
|
|
66
|
+
`loader` 函数有两个入参,分别用于获取路由参数和请求信息。
|
|
67
|
+
|
|
68
|
+
### params
|
|
69
|
+
|
|
70
|
+
`params` 是当路由为[动态路由](/guides/basic-features/routes/routes#动态路由)时的动态路由片段,会作为参数传入 `loader` 函数:
|
|
71
|
+
|
|
72
|
+
```tsx title="routes/user/[id]/page.data.ts"
|
|
73
|
+
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
74
|
+
|
|
75
|
+
// 访问 /user/123 时,函数的参数为 `{ params: { id: '123' } }`
|
|
76
|
+
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
77
|
+
const { id } = params;
|
|
78
|
+
const res = await fetch(`https://api/user/${id}`);
|
|
79
|
+
return res.json();
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### request
|
|
84
|
+
|
|
85
|
+
`request` 是一个 [Fetch Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) 实例。一个常见的使用场景是通过 `request` 获取查询参数:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
89
|
+
|
|
90
|
+
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
91
|
+
const url = new URL(request.url);
|
|
92
|
+
const userId = url.searchParams.get('id');
|
|
93
|
+
return queryUser(userId);
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 返回值
|
|
98
|
+
|
|
99
|
+
`loader` 函数的返回值**只能是两种数据结构之一**,可序列化的数据对象或者 [Fetch Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) 实例:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
const loader = async (): Promise<ProfileData> => {
|
|
103
|
+
return {
|
|
104
|
+
message: 'hello world',
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export default loader;
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
默认情况下,`loader` 返回的响应 `Content-type` 是 `application/json`,`status` 为 200,你可以通过自定义 `Response` 来设置:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
const loader = async (): Promise<ProfileData> => {
|
|
114
|
+
const data = { message: 'hello world' };
|
|
115
|
+
return new Response(JSON.stringify(data), {
|
|
116
|
+
status: 200,
|
|
117
|
+
headers: {
|
|
118
|
+
'Content-Type': 'application/json; utf-8',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 在不同环境使用 Data Loader
|
|
125
|
+
|
|
126
|
+
`loader` 函数可能会在服务端或浏览器端执行。在服务端执行的 `loader` 函数,我们称为 Server Loader,在浏览器端执行的称为 Client Loader。
|
|
127
|
+
|
|
128
|
+
在 CSR 应用中,`loader` 函数会在浏览器端执行,即默认都是 Client Loader。
|
|
129
|
+
|
|
130
|
+
在 SSR 应用中,`loader` 函数只会在服务端执行,即默认都是 Server Loader。在 SSR 渲染时,Modern.js 会直接在服务端调用对应的 `loader` 函数。在浏览器端切换路由时,Modern.js 会发送一个 http 请求到 SSR 服务,同样在服务端触发 `loader` 函数。
|
|
131
|
+
|
|
132
|
+
:::note
|
|
133
|
+
SSR 应用的 `loader` 函数只在服务端执行可以带来以下好处:
|
|
134
|
+
|
|
135
|
+
- **简化使用方式**:保证 SSR 应用获取数据的方式是同构的,开发者无需根据环境区分 `loader` 函数执行的代码。
|
|
136
|
+
- **减少浏览器端 bundle 体积**:将逻辑代码及其依赖,从浏览器端移动到了服务端。
|
|
137
|
+
- **提高可维护性**:将逻辑代码移动到服务端,减少了数据逻辑对前端 UI 的直接影响。此外,也避免了浏览器端 bundle 中误引入服务端依赖,或服务端 bundle 中误引入浏览器端依赖的问题。
|
|
138
|
+
|
|
139
|
+
:::
|
|
140
|
+
|
|
141
|
+
我们推荐在 `loader` 函数中使用 `fetch` API 发起请求。在 Modern.js 中默认对 `fetch` API 做了 polyfill,允许服务端使用该 API 发起请求,这意味你都可以在 CSR 和 SSR 时同构的获取数据:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
export async function loader() {
|
|
145
|
+
const res = await fetch('URL_ADDRESS');
|
|
146
|
+
const data = await res.json();
|
|
147
|
+
return {
|
|
148
|
+
message: data.message,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## 错误处理
|
|
154
|
+
|
|
155
|
+
### 基本用法
|
|
156
|
+
|
|
157
|
+
在 `loader` 函数中,可以通过 `throw error` 或者 `throw response` 的方式处理错误,当 `loader` 函数中有错误被抛出时,Modern.js 会停止执行当前 `loader` 中的代码,并将前端 UI 切换到定义的 [`ErrorBoundary`](/guides/basic-features/routes/routes#错误处理) 组件:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
// routes/user/profile/page.data.ts
|
|
161
|
+
export async function loader() {
|
|
162
|
+
const res = await fetch('https://api/user/profile');
|
|
163
|
+
if (!res.ok) {
|
|
164
|
+
throw res;
|
|
165
|
+
}
|
|
166
|
+
return res.json();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// routes/user/profile/error.tsx
|
|
170
|
+
import { useRouteError } from '@modern-js/runtime/router';
|
|
171
|
+
const ErrorBoundary = () => {
|
|
172
|
+
const error = useRouteError() as Response;
|
|
173
|
+
return (
|
|
174
|
+
<div>
|
|
175
|
+
<h1>{error.status}</h1>
|
|
176
|
+
<h2>{error.statusText}</h2>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export default ErrorBoundary;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 修改 HTTP 状态码
|
|
185
|
+
|
|
186
|
+
在 SSR 项目中你可以通过在 `loader` 函数中 `throw response` 的方式,控制页面的状态码,展示对应的 UI。
|
|
187
|
+
|
|
188
|
+
如以下示例,页面的状态码将与这个 `response` 保持一致,页面也会展示为 `ErrorBoundary` 的 UI:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
// routes/user/profile/page.data.ts
|
|
192
|
+
export async function loader() {
|
|
193
|
+
const user = await fetchUser();
|
|
194
|
+
if (!user) {
|
|
195
|
+
throw new Response('The user was not found', { status: 404 });
|
|
196
|
+
}
|
|
197
|
+
return user;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// routes/error.tsx
|
|
201
|
+
import { useRouteError } from '@modern-js/runtime/router';
|
|
202
|
+
const ErrorBoundary = () => {
|
|
203
|
+
const error = useRouteError() as { data: string };
|
|
204
|
+
return <div className="error">{error.data}</div>;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export default ErrorBoundary;
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
:::tip
|
|
211
|
+
`throw` 和上文介绍的 `return` Response 都可以修改状态码,区别是 `throw` 会进入 `ErrorBoundary`,而 `return` 不会。
|
|
212
|
+
:::
|
|
213
|
+
|
|
214
|
+
## 获取上层组件的数据
|
|
215
|
+
|
|
216
|
+
很多场景下,子组件需要获取到上层组件 `loader` 中的数据,你可以通过 `useRouteLoaderData` 方便地获取到上层组件的数据:
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
// routes/user/profile/page.tsx
|
|
220
|
+
import { useRouteLoaderData } from '@modern-js/runtime/router';
|
|
221
|
+
|
|
222
|
+
export function UserLayout() {
|
|
223
|
+
// 获取 routes/user/layout.data.ts 中 `loader` 返回的数据
|
|
224
|
+
const data = useRouteLoaderData('user/layout');
|
|
225
|
+
return (
|
|
226
|
+
<div>
|
|
227
|
+
<h1>{data.name}</h1>
|
|
228
|
+
<h2>{data.age}</h2>
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
`userRouteLoaderData` 接受一个参数 `routeId`。在使用约定式路由时,Modern.js 会为你自动生成 `routeId`,`routeId` 的值是对应组件相对于 `src/routes` 的路径,如上面的例子中,子组件想要获取 `routes/user/layout.tsx` 中 loader 返回的数据,`routeId` 的值就是 `user/layout`。
|
|
235
|
+
|
|
236
|
+
在多入口场景下,`routeId` 的值需要加上对应入口的名称,入口名称非指定情况下一般是入口的目录名,如以下目录结构:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
.
|
|
240
|
+
└── src
|
|
241
|
+
├── entry1
|
|
242
|
+
│ └── routes
|
|
243
|
+
│ └── layout.tsx
|
|
244
|
+
└── entry2
|
|
245
|
+
└── routes
|
|
246
|
+
└── layout.tsx
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
如果想获取 `entry1/routes/layout.tsx` 中 `loader` 返回的数据,`routeId` 的值就是 `entry1_layout`。
|
|
250
|
+
|
|
251
|
+
## Loading UI (Experimental)
|
|
252
|
+
|
|
253
|
+
:::info Experimental
|
|
254
|
+
此功能当前是实验性功能,后续 API 可能有调整。
|
|
255
|
+
:::
|
|
256
|
+
|
|
257
|
+
创建 `user/layout.data.ts`,并添加以下代码:
|
|
258
|
+
|
|
259
|
+
```ts title="routes/user/layout.data.ts"
|
|
260
|
+
import { defer } from '@modern-js/runtime/router';
|
|
261
|
+
|
|
262
|
+
export const loader = () =>
|
|
263
|
+
defer({
|
|
264
|
+
userInfo: new Promise(resolve => {
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
resolve({
|
|
267
|
+
age: 1,
|
|
268
|
+
name: 'user layout',
|
|
269
|
+
});
|
|
270
|
+
}, 1000);
|
|
271
|
+
}),
|
|
272
|
+
});
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
在 `user/layout.tsx` 中添加以下代码:
|
|
276
|
+
|
|
277
|
+
```tsx title="routes/user/layout.tsx"
|
|
278
|
+
import { Await, defer, useLoaderData, Outlet } from '@modern-js/runtime/router';
|
|
279
|
+
|
|
280
|
+
export default function UserLayout() {
|
|
281
|
+
const { userInfo } = useLoaderData() as { userInfo: Promise<UserInfo> };
|
|
282
|
+
return (
|
|
283
|
+
<div>
|
|
284
|
+
<React.Suspense fallback={<p>Loading...</p>}>
|
|
285
|
+
<Await
|
|
286
|
+
resolve={userInfo}
|
|
287
|
+
children={userInfo => (
|
|
288
|
+
<div>
|
|
289
|
+
<span>{userInfo.name}</span>
|
|
290
|
+
<span>{userInfo.age}</span>
|
|
291
|
+
<Outlet />
|
|
292
|
+
</div>
|
|
293
|
+
)}
|
|
294
|
+
></Await>
|
|
295
|
+
</React.Suspense>
|
|
296
|
+
</div>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
:::tip
|
|
302
|
+
`<Await>` 组件的具体用法请查看 [Await](https://reactrouter.com/en/main/components/await),`defer` 的具体用法请查看 [defer](https://reactrouter.com/en/main/guides/deferred)。
|
|
303
|
+
:::
|
|
304
|
+
|
|
305
|
+
## 数据缓存
|
|
306
|
+
|
|
307
|
+
在路由导航时,Modern.js 只会加载路由变化的部分的数据。如当前路由是 `a/b`,`a` 路径对应的 Data Loader 已经执行过,当从 `/a/b` 跳转到 `/a/c`时,`a` 路径对应的 Data Loader 不会重新执行,`c` 路径对应的 Data Loader 会执行,并获取了数据。
|
|
308
|
+
|
|
309
|
+
这种默认的优化策略避免了无效重复数据的请求。此时你可能会疑惑,如何更新 `a` 路径对应 Data Loader 的数据?
|
|
310
|
+
|
|
311
|
+
在 Modern.js 中,以下几种情况,Modern.js 会重新加载对应路由路径的数据:
|
|
312
|
+
|
|
313
|
+
1. 在 [Data Action](/guides/basic-features/data/data-write.md) 触发后
|
|
314
|
+
2. URL 参数发生变化后
|
|
315
|
+
3. 用户点击的链接与当前页面的 URL 相同
|
|
316
|
+
4. 在路由组件中定义了 [`shouldRevalidate`](#/shouldrevalidate) 函数,该函数返回 `true`
|
|
317
|
+
|
|
318
|
+
:::tip
|
|
319
|
+
如果你在路由上定义了 [`shouldRevalidate`](#/shouldrevalidate) 函数,会先检查该函数,判断是否需要重新加载数据。
|
|
320
|
+
:::
|
|
321
|
+
|
|
322
|
+
### `shouldRevalidate`
|
|
323
|
+
|
|
324
|
+
:::warning
|
|
325
|
+
目前 `shouldRevalidate` 只会在 CSR 和 Streaming SSR 下生效。
|
|
326
|
+
:::
|
|
327
|
+
|
|
328
|
+
在路由组件(`layout.tsx`,`page.tsx`,`$.tsx`)中,我们可以导出一个 `shouldRevalidate` 函数。每次项目中的路由变化时,这个函数会被触发,该函数可以控制要重新加载哪些路由中的数据。如果这个函数返回 `true`,Modern.js 就会重新加载对应路由的数据。
|
|
329
|
+
|
|
330
|
+
```ts title="routes/user/layout.tsx"
|
|
331
|
+
import type { ShouldRevalidateFunction } from '@modern-js/runtime/router';
|
|
332
|
+
export const shouldRevalidate: ShouldRevalidateFunction = ({
|
|
333
|
+
actionResult,
|
|
334
|
+
currentParams,
|
|
335
|
+
currentUrl,
|
|
336
|
+
defaultShouldRevalidate,
|
|
337
|
+
formAction,
|
|
338
|
+
formData,
|
|
339
|
+
formEncType,
|
|
340
|
+
formMethod,
|
|
341
|
+
nextParams,
|
|
342
|
+
nextUrl,
|
|
343
|
+
}) => {
|
|
344
|
+
return true;
|
|
345
|
+
};
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
:::tip
|
|
349
|
+
`shouldRevalidate` 函数的更多信息可以参考 [react-router](https://reactrouter.com/start/data/route-object#shouldrevalidate)。
|
|
350
|
+
:::
|
|
351
|
+
|
|
352
|
+
## 错误用法
|
|
353
|
+
|
|
354
|
+
1. `loader` 中只能返回可序列化的数据,在 SSR 环境下,`loader` 函数的返回值会被序列化为 JSON 字符串,然后在浏览器端被反序列化为对象。因此,`loader` 函数中不能返回不可序列化的数据(如函数)。
|
|
355
|
+
|
|
356
|
+
:::warning
|
|
357
|
+
目前 CSR 下没有这个限制,但我们强烈推荐你遵循该限制,且未来我们可能在 CSR 下也加上该限制。
|
|
358
|
+
|
|
359
|
+
:::
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
// This won't work!
|
|
363
|
+
export default () => {
|
|
364
|
+
return {
|
|
365
|
+
user: {},
|
|
366
|
+
method: () => {},
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
2. Modern.js 会帮你调用 `loader` 函数,你不应该自己调用 `loader` 函数:
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
// This won't work!
|
|
375
|
+
export const loader = async () => {
|
|
376
|
+
const res = fetch('https://api/user/profile');
|
|
377
|
+
return res.json();
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
import { loader } from './page.data.ts';
|
|
381
|
+
export default function RouteComp() {
|
|
382
|
+
const data = loader();
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
3. 不能从路由组件中引入 `loader` 文件,也不能从 `loader` 文件引入路由组件中的变量,如果需要共享类型的话,应该使用 `import type`
|
|
387
|
+
|
|
388
|
+
```ts
|
|
389
|
+
// Not allowed
|
|
390
|
+
// routes/layout.tsx
|
|
391
|
+
import { useLoaderData } from '@modern-js/runtime/router';
|
|
392
|
+
import { ProfileData } from './page.data.ts'; // should use "import type" instead
|
|
393
|
+
|
|
394
|
+
export const fetch = wrapFetch(fetch);
|
|
395
|
+
|
|
396
|
+
export default function UserPage() {
|
|
397
|
+
const profileData = useLoaderData() as ProfileData;
|
|
398
|
+
return <div>{profileData}</div>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// routes/layout.data.ts
|
|
402
|
+
import { fetch } from './layout.tsx'; // should not be imported from the routing component
|
|
403
|
+
export type ProfileData = {
|
|
404
|
+
/* some types */
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const loader = async (): Promise<ProfileData> => {
|
|
408
|
+
const res = await fetch('https://api/user/profile');
|
|
409
|
+
return await res.json();
|
|
410
|
+
};
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
4. 在服务端运行时,`loader` 函数会被打包为一个统一的 bundle,所以我们不推荐服务端的代码使用 `__filename` 和 `__dirname`。
|
|
414
|
+
|
|
415
|
+
## 常见问题
|
|
416
|
+
|
|
417
|
+
1. `loader` 和 BFF 函数的关系是什么?
|
|
418
|
+
|
|
419
|
+
在 CSR 项目中,`loader` 在浏览器端执行,在 `loader` 可以直接调用 BFF 函数进行接口请求。
|
|
420
|
+
|
|
421
|
+
在 SSR 项目中,每个 `loader` 也是一个服务端接口。我们推荐使用 `loader` 替代 HTTP Method 为 GET 的 BFF 函数,避免多一层转发和执行。
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 数据写入
|
|
3
|
+
sidebar_position: 4
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 数据写入
|
|
7
|
+
|
|
8
|
+
在[数据获取](/guides/basic-features/data/data-fetch)章节中,介绍了 Modern.js 获取数据的方式,你可能会遇到两个问题:
|
|
9
|
+
|
|
10
|
+
1. 如何更新 Data Loader 返回的数据?
|
|
11
|
+
2. 如何将新的数据传递到服务器?
|
|
12
|
+
|
|
13
|
+
在 Modern.js 中,可以通过 Data Action 解决和实现。
|
|
14
|
+
|
|
15
|
+
## 什么是 Data Action
|
|
16
|
+
|
|
17
|
+
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `action` 函数,我们称为 Data Action,开发者可以在合适的时机调用它:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
.
|
|
21
|
+
└── routes
|
|
22
|
+
└── user
|
|
23
|
+
├── layout.tsx
|
|
24
|
+
└── layout.data.ts
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
在 `routes/user/layout.data.ts` 文件中,可以导出一个 Data Action 函数:
|
|
28
|
+
|
|
29
|
+
```ts title="routes/user/layout.data.ts"
|
|
30
|
+
import type { ActionFunction } from '@modern-js/runtime/router';
|
|
31
|
+
|
|
32
|
+
export const action: ActionFunction = async ({ request }) => {
|
|
33
|
+
const newUser = await request.json();
|
|
34
|
+
const name = newUser.name;
|
|
35
|
+
return updateUserProfile(name);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
在路由组件中,你可以通过 `useFetcher` 获取对应 `submit` 函数,执行并触发 Data Action:
|
|
40
|
+
|
|
41
|
+
```tsx title="routes/user/layout.tsx"
|
|
42
|
+
import {
|
|
43
|
+
useFetcher,
|
|
44
|
+
useLoaderData,
|
|
45
|
+
useParams,
|
|
46
|
+
Outlet
|
|
47
|
+
} from '@modern-js/runtime/router';
|
|
48
|
+
|
|
49
|
+
export default () => {
|
|
50
|
+
const userInfo = useLoaderData();
|
|
51
|
+
const { submit } = useFetcher();
|
|
52
|
+
const editUser = () => {
|
|
53
|
+
const newUser = {
|
|
54
|
+
name: 'Modern.js'
|
|
55
|
+
}
|
|
56
|
+
return submit(newUser, {
|
|
57
|
+
method: 'post',
|
|
58
|
+
encType: 'application/json',
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
<button onClick={editUser}>edit user</button>
|
|
64
|
+
<div className="user-profile">
|
|
65
|
+
{userInfo}
|
|
66
|
+
</div>
|
|
67
|
+
<Outlet context={userInfo}></Outlet>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
当执行 `submit` 后,会触发定义的 `action` 函数。在 `action` 函数中,可以通过[入参](/guides/basic-features/data/data-write.html#入参)获取提交的数据,最终发送数据到服务端。
|
|
74
|
+
|
|
75
|
+
`action` 函数执行完后,Modern.js 将自动执行 `loader` 函数代码,并更新对应的数据和视图。
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## `action` 函数
|
|
80
|
+
|
|
81
|
+
与 `loader` 函数一样,`action` 函数有两个入参,`params` 和 `request`。
|
|
82
|
+
|
|
83
|
+
### params
|
|
84
|
+
|
|
85
|
+
`params` 是当路由为[动态路由](/guides/basic-features/routes/routes#动态路由)时动态路由片段,会作为参数传入 `action` 函数:
|
|
86
|
+
|
|
87
|
+
```tsx title="routes/user/[id]/page.data.ts"
|
|
88
|
+
import { ActionFunctionArgs } from '@modern-js/runtime/router';
|
|
89
|
+
|
|
90
|
+
// 访问 /user/123 时,函数的参数为 `{ params: { id: '123' } }`
|
|
91
|
+
export const action = async ({ params }: ActionFunctionArgs) => {
|
|
92
|
+
const { id } = params;
|
|
93
|
+
const res = await fetch(`https://api/user/${id}`);
|
|
94
|
+
return res.json();
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### request
|
|
99
|
+
|
|
100
|
+
`request` 是一个 [Fetch Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) 实例。通过 `request`,可以在 action 函数中获取到浏览器端提交的数据,如 `request.json()`,`request.formData()`,`request.text()` 等。具体使用哪个 API,请参考[数据类型](#数据类型)。
|
|
101
|
+
|
|
102
|
+
```tsx title="routes/user/[id]/page.data.ts"
|
|
103
|
+
import { ActionFunctionArgs } from '@modern-js/runtime/router';
|
|
104
|
+
|
|
105
|
+
export const action = async ({ request }: ActionFunctionArgs) => {
|
|
106
|
+
const newUser = await request.json();
|
|
107
|
+
return updateUser(newUser);
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 返回值
|
|
112
|
+
|
|
113
|
+
`action` 函数的返回值可以是任何可序列化的内容,也可以是一个 [Fetch Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) 实例,
|
|
114
|
+
可以通过 [`useActionData`](https://reactrouter.com/en/main/hooks/use-action-data) 访问 response 中内容。
|
|
115
|
+
|
|
116
|
+
## useSubmit 和 useFetcher
|
|
117
|
+
|
|
118
|
+
### 区别
|
|
119
|
+
|
|
120
|
+
你可以通过 [`useSubmit`](https://reactrouter.com/en/main/hooks/use-submit) 或 [`useFetcher`](https://reactrouter.com/en/main/hooks/use-fetcher) 调用 Data Action。它们的区别是通过
|
|
121
|
+
`useSubmit` 调用,会触发浏览器的导航,通过 `useFetcher` 则不会触发浏览器的导航。
|
|
122
|
+
|
|
123
|
+
useSubmit:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const submit = useSubmit();
|
|
127
|
+
submit(null, { method: "post", action: "/logout" });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
useFetcher:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const { submit } = useFetcher();
|
|
134
|
+
submit(null, { method: "post", action: "/logout" });
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`submit` 函数有两个入参,第一个入参是传递到服务端的 `formData`。第二个入参是可选参数,其中
|
|
138
|
+
- `method` 相当于表单提交时的 `method`,大部分写入数据的场景下,`method` 可以传入 `post`。
|
|
139
|
+
- `action` 用来指定触发哪个路由组件的 Data Action,如果未传入 `action` 入参,默认会触发当前路由组件的 action,即 `user/page.tsx` 组件或子组件中执行 submit,会触发 `user/page.data.ts` 中定义的 action。
|
|
140
|
+
|
|
141
|
+
:::info
|
|
142
|
+
|
|
143
|
+
更多 API 的信息可参考相关文档:[`useSubmit`](https://reactrouter.com/en/main/hooks/use-submit)、[`useFetcher`](https://reactrouter.com/en/main/hooks/use-fetcher)。
|
|
144
|
+
|
|
145
|
+
:::
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### 数据类型
|
|
149
|
+
|
|
150
|
+
`submit` 函数的第一个入参,可以接受不同类型的值。
|
|
151
|
+
|
|
152
|
+
如 `FormData`:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
let formData = new FormData();
|
|
156
|
+
formData.append("cheese", "gouda");
|
|
157
|
+
submit(formData);
|
|
158
|
+
// In the action, you can get the data by request.json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
或 `URLSearchParams` 类型的值:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
let searchParams = new URLSearchParams();
|
|
165
|
+
searchParams.append("cheese", "gouda");
|
|
166
|
+
submit(searchParams);
|
|
167
|
+
// In the action, you can get the data by request.json
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
或任意 `URLSearchParams` 构造函数可接受的值:
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
submit("cheese=gouda&toasted=yes");
|
|
174
|
+
submit([
|
|
175
|
+
["cheese", "gouda"],
|
|
176
|
+
["toasted", "yes"],
|
|
177
|
+
]);
|
|
178
|
+
// In the action, you can get the data by request.json
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
默认情况下,如果 `submit` 函数中的第一个入参是一个对象,对应的数据会被 encode 为 `formData`:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
submit(
|
|
185
|
+
{ key: "value" },
|
|
186
|
+
{
|
|
187
|
+
method: "post",
|
|
188
|
+
encType: "application/x-www-form-urlencoded",
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// In the action, you can get the data by request.formData
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
你也可以通过第二个参数,指定为编码方式:
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
submit(
|
|
199
|
+
{ key: "value" },
|
|
200
|
+
{ method: "post", encType: "application/json" }
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
submit('{"key":"value"}', {
|
|
204
|
+
method: "post",
|
|
205
|
+
encType: "application/json",
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// In the action, you can get the data by request.json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
或提交纯文本:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
submit("value", { method: "post", encType: "text/plain" });
|
|
215
|
+
// In the action, you can get the data by request.text
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## 为什么要提供 Data Action
|
|
219
|
+
|
|
220
|
+
Modern.js 中提供 Data Action 主要是为了使 UI 和服务器的状态能保持同步,通过这种方式可以减少状态管理的负担,
|
|
221
|
+
传统的状态管理方式,会在浏览器端和远程分别持有状态:
|
|
222
|
+
|
|
223
|
+

|
|
224
|
+
|
|
225
|
+
而在 Modern.js 中,我们希望通过 Loader 和 Action 帮助开发者自动的同步浏览器端和服务端的状态:
|
|
226
|
+
|
|
227
|
+

|
|
228
|
+
|
|
229
|
+
如果项目中组件共享的数据主要来自于服务端的状态,则无需在项目引入浏览器端状态管理库。可以使用 Data Loader 请求数据,通过 [`useRouteLoaderData`](/guides/basic-features/data/data-fetch.md) 在子组件中共享数据,使用 Data Action 修改和同步服务端的状态。
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
## CSR 和 SSR
|
|
233
|
+
|
|
234
|
+
与 Data Loader 一样,SSR 项目中,Data Action 是在服务端执行的(框架会自动发请求触发 Data Action),而在 CSR 项目中,Data Action 是在浏览器端执行的。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["mock", "proxy", "rsdoctor", "using-storybook"]
|