@modern-js/main-doc 2.69.7 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/{_meta.json → _nav.json} +5 -1
- package/docs/en/apis/app/commands.mdx +8 -33
- package/docs/en/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/en/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/en/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/en/apis/app/runtime/_meta.json +0 -18
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/router/router.mdx +1 -1
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/en/community/blog/v2-release-note.mdx +0 -2
- package/docs/en/community/contributing-guide.mdx +10 -12
- package/docs/en/components/bff-upload.mdx +19 -17
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/bundler.mdx +1 -1
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/enable-bff-caution.mdx +2 -2
- package/docs/en/components/enable-bff.mdx +42 -8
- package/docs/en/components/enable-ssg.mdx +49 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/esbuild.mdx +2 -2
- package/docs/en/components/extend-bff-function.mdx +2 -4
- package/docs/en/components/hono.mdx +119 -0
- package/docs/en/components/init-app.mdx +40 -17
- 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 +23 -0
- package/docs/en/components/international/instance-code.mdx +26 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- package/docs/en/components/nodeVersion.mdx +2 -6
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +16 -12
- package/docs/en/components/upgrade-config-deploy.mdx +0 -0
- package/docs/en/configure/_meta.json +7 -8
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/builder-plugins.mdx +1 -2
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +211 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/experiments/source-build.mdx +0 -1
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/assets-retry.mdx +1 -1
- package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/en/configure/app/output/filename.mdx +2 -4
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/en/configure/app/output/override-browserslist.mdx +6 -4
- package/docs/en/configure/app/output/source-map.mdx +6 -3
- package/docs/en/configure/app/output/ssg.mdx +12 -43
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/output/temp-dir.mdx +3 -3
- package/docs/en/configure/app/performance/build-cache.mdx +1 -5
- package/docs/en/configure/app/performance/profile.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +1 -3
- 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 +2 -51
- package/docs/en/configure/app/runtime/router.mdx +0 -4
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/security/sri.mdx +0 -1
- package/docs/en/configure/app/server/port.mdx +1 -21
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr.mdx +20 -9
- package/docs/en/configure/app/source/alias.mdx +1 -1
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/include.mdx +2 -14
- package/docs/en/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/en/configure/app/source/transform-import.mdx +1 -59
- package/docs/en/configure/app/tools/bundler-chain.mdx +5 -5
- package/docs/en/configure/app/tools/css-extract.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +22 -256
- package/docs/en/configure/app/tools/html-plugin.mdx +3 -3
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -43
- package/docs/en/configure/app/usage.mdx +5 -27
- package/docs/en/guides/_meta.json +5 -1
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +2 -8
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
- package/docs/en/guides/advanced-features/bff/function.mdx +6 -10
- package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/en/guides/advanced-features/bff/sdk.mdx +20 -12
- package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/en/guides/advanced-features/build-performance.mdx +23 -26
- package/docs/en/guides/advanced-features/compatibility.mdx +53 -9
- package/docs/en/guides/advanced-features/international/_meta.json +11 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/en/guides/advanced-features/international/api.mdx +400 -0
- package/docs/en/guides/advanced-features/international/basic.mdx +417 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +428 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +126 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/en/guides/advanced-features/international.mdx +37 -0
- package/docs/en/guides/advanced-features/low-level.mdx +21 -16
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +8 -22
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/en/guides/advanced-features/rspack-start.mdx +3 -23
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +121 -36
- package/docs/en/guides/advanced-features/web-server.mdx +82 -299
- package/docs/en/guides/basic-features/_meta.json +6 -1
- package/docs/en/guides/basic-features/css/css-in-js.mdx +46 -11
- package/docs/en/guides/basic-features/css/css-modules.mdx +5 -17
- package/docs/en/guides/basic-features/css/css.mdx +3 -3
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +5 -89
- package/docs/en/guides/basic-features/data/data-cache.mdx +65 -77
- package/docs/en/guides/basic-features/data/data-fetch.mdx +19 -18
- package/docs/en/guides/basic-features/data/data-write.mdx +2 -2
- package/docs/en/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +6 -17
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +5 -5
- package/docs/en/guides/basic-features/deploy.mdx +25 -18
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +1 -1
- package/docs/en/guides/basic-features/output-files.mdx +3 -3
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +16 -23
- package/docs/en/guides/basic-features/render/overview.mdx +51 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +399 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -67
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -10
- package/docs/en/guides/basic-features/render/ssr.mdx +31 -31
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +29 -9
- 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.mdx → routes/routes.mdx} +7 -110
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +27 -12
- package/docs/en/guides/concept/entries.mdx +139 -147
- package/docs/en/guides/get-started/glossary.mdx +0 -18
- package/docs/en/guides/get-started/introduction.mdx +1 -4
- package/docs/en/guides/get-started/quick-start.mdx +4 -71
- package/docs/en/guides/get-started/tech-stack.mdx +7 -27
- package/docs/en/guides/get-started/upgrade.mdx +30 -23
- package/docs/en/guides/topic-detail/_meta.json +0 -12
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/en/guides/topic-detail/module-federation/application.mdx +16 -15
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +5 -4
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +50 -2
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +10 -30
- package/docs/en/guides/troubleshooting/builder.mdx +3 -82
- package/docs/en/guides/troubleshooting/cli.mdx +6 -30
- package/docs/en/guides/troubleshooting/dependencies.mdx +22 -22
- package/docs/en/guides/upgrade/_meta.json +1 -0
- package/docs/en/guides/upgrade/config.mdx +936 -0
- package/docs/en/guides/upgrade/entry.mdx +463 -0
- package/docs/en/guides/upgrade/other.mdx +83 -0
- package/docs/en/guides/upgrade/overview.mdx +33 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/en/guides/upgrade/web-server.mdx +91 -0
- package/docs/en/plugin/_meta.json +5 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/cli-plugins/api.mdx +17 -68
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/en/plugin/introduction.mdx +44 -44
- package/docs/en/plugin/official/_meta.json +0 -5
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +0 -2
- package/docs/en/plugin/plugin-system.mdx +69 -62
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/server-plugins/_meta.json +1 -0
- package/docs/en/plugin/server-plugins/api.mdx +210 -1
- package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
- package/docs/en/tutorials/_meta.json +0 -10
- package/docs/en/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +9 -25
- package/docs/zh/{_meta.json → _nav.json} +10 -6
- package/docs/zh/apis/app/commands.mdx +8 -33
- package/docs/zh/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/zh/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/zh/apis/app/runtime/_meta.json +0 -18
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/zh/community/blog/v2-release-note.mdx +0 -2
- package/docs/zh/community/contributing-guide.mdx +10 -12
- 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 +8 -7
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/bundler.mdx +1 -1
- package/docs/zh/components/debug-app.mdx +1 -1
- package/docs/zh/components/enable-bff-caution.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +41 -8
- package/docs/zh/components/enable-ssg.mdx +49 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/esbuild.mdx +2 -2
- package/docs/zh/components/extend-bff-function.mdx +2 -4
- package/docs/zh/components/hono.mdx +119 -0
- package/docs/zh/components/init-app.mdx +40 -18
- 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 +23 -0
- package/docs/zh/components/international/instance-code.mdx +26 -0
- package/docs/zh/components/international/introduce.mdx +2 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/module-federation.mdx +4 -4
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +3 -7
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/components/self-route-example.mdx +3 -3
- package/docs/zh/components/ua-polyfill.mdx +11 -6
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/components/upgrade-config-deploy.mdx +0 -0
- package/docs/zh/configure/_meta.json +7 -8
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/builder-plugins.mdx +1 -2
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +211 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
- package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/zh/configure/app/output/filename.mdx +2 -4
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/zh/configure/app/output/override-browserslist.mdx +3 -3
- package/docs/zh/configure/app/output/source-map.mdx +10 -3
- package/docs/zh/configure/app/output/ssg.mdx +13 -45
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/output/temp-dir.mdx +3 -3
- package/docs/zh/configure/app/performance/build-cache.mdx +1 -5
- package/docs/zh/configure/app/performance/profile.mdx +1 -1
- package/docs/zh/configure/app/plugins.mdx +1 -2
- 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 +2 -53
- package/docs/zh/configure/app/runtime/router.mdx +0 -4
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/security/sri.mdx +0 -1
- package/docs/zh/configure/app/server/port.mdx +2 -21
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr.mdx +21 -11
- package/docs/zh/configure/app/source/alias.mdx +1 -1
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/include.mdx +2 -16
- package/docs/zh/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/zh/configure/app/source/transform-import.mdx +1 -59
- package/docs/zh/configure/app/tools/bundler-chain.mdx +6 -6
- package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +14 -248
- package/docs/zh/configure/app/tools/html-plugin.mdx +3 -2
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -43
- package/docs/zh/configure/app/usage.mdx +6 -28
- package/docs/zh/guides/_meta.json +5 -1
- package/docs/zh/guides/advanced-features/_meta.json +6 -1
- package/docs/zh/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +8 -16
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +25 -8
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +2 -16
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +23 -16
- package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/zh/guides/advanced-features/build-performance.mdx +23 -30
- package/docs/zh/guides/advanced-features/compatibility.mdx +44 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +11 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +400 -0
- package/docs/zh/guides/advanced-features/international/basic.mdx +416 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +432 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +126 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/zh/guides/advanced-features/international.mdx +36 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +21 -16
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +3 -3
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +8 -22
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +120 -37
- package/docs/zh/guides/advanced-features/web-server.mdx +79 -300
- package/docs/zh/guides/basic-features/_meta.json +6 -1
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +40 -5
- package/docs/zh/guides/basic-features/css/css-modules.mdx +6 -17
- package/docs/zh/guides/basic-features/css/css.mdx +2 -2
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +6 -90
- package/docs/zh/guides/basic-features/data/data-cache.mdx +55 -59
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +14 -16
- package/docs/zh/guides/basic-features/data/data-write.mdx +4 -4
- package/docs/zh/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +4 -15
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +6 -6
- package/docs/zh/guides/basic-features/deploy.mdx +24 -20
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -2
- package/docs/zh/guides/basic-features/output-files.mdx +3 -3
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +17 -24
- package/docs/zh/guides/basic-features/render/overview.mdx +52 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +399 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +34 -31
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +34 -14
- 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.mdx → routes/routes.mdx} +8 -114
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
- package/docs/zh/guides/basic-features/testing/cypress.mdx +5 -5
- package/docs/zh/guides/basic-features/testing/jest.mdx +12 -12
- package/docs/zh/guides/concept/builder.mdx +26 -11
- package/docs/zh/guides/concept/entries.mdx +95 -92
- package/docs/zh/guides/get-started/glossary.mdx +0 -18
- package/docs/zh/guides/get-started/introduction.mdx +1 -5
- package/docs/zh/guides/get-started/quick-start.mdx +5 -72
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -28
- package/docs/zh/guides/get-started/upgrade.mdx +30 -23
- package/docs/zh/guides/topic-detail/_meta.json +0 -12
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +18 -16
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +51 -5
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +11 -31
- package/docs/zh/guides/troubleshooting/builder.mdx +4 -85
- package/docs/zh/guides/troubleshooting/cli.mdx +6 -30
- package/docs/zh/guides/troubleshooting/dependencies.mdx +23 -23
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +940 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +90 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/zh/guides/upgrade/web-server.md +93 -0
- package/docs/zh/plugin/_meta.json +5 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +19 -70
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/zh/plugin/introduction.mdx +40 -40
- package/docs/zh/plugin/official/_meta.json +0 -5
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +0 -2
- package/docs/zh/plugin/plugin-system.mdx +43 -51
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/server-plugins/_meta.json +1 -0
- package/docs/zh/plugin/server-plugins/api.mdx +210 -1
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
- package/docs/zh/tutorials/_meta.json +0 -10
- package/docs/zh/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/zh/tutorials/foundations/introduction.mdx +8 -25
- package/i18n.json +0 -16
- package/package.json +12 -12
- package/rspress.config.ts +5 -8
- package/src/components/ContentCard/index.module.scss +11 -7
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/FeatureLayout/index.module.css +1 -1
- package/src/components/Footer/index.tsx +2 -14
- package/src/components/Footer/styles.module.scss +5 -5
- package/src/components/FrameworkCode/index.tsx +605 -0
- package/src/components/ListCard/index.tsx +1 -1
- package/src/components/RandomMemberList/index.tsx +1 -1
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/custom.scss +15 -0
- package/src/i18n/enUS.ts +2 -4
- package/src/i18n/index.ts +1 -1
- package/src/i18n/zhCN.ts +2 -4
- package/src/index.ts +2 -1
- package/src/pages/index.module.scss +59 -41
- package/src/pages/index.tsx +9 -24
- package/docs/en/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/en/apis/app/hooks/src/index_.mdx +0 -38
- package/docs/en/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/en/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/en/apis/app/runtime/core/create-app.mdx +0 -49
- package/docs/en/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +0 -140
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/en/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/en/apis/app/runtime/model/connect.mdx +0 -146
- package/docs/en/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/en/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +0 -107
- package/docs/en/apis/app/runtime/model/model_.mdx +0 -198
- package/docs/en/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/en/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +0 -51
- package/docs/en/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/en/apis/app/runtime/web-server/hook.mdx +0 -134
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +0 -113
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +0 -167
- package/docs/en/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/en/components/bff-proxy-principle.mdx +0 -1
- package/docs/en/components/builder.mdx +0 -3
- package/docs/en/components/create-bff-api-app.mdx +0 -25
- package/docs/en/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/en/components/enable-micro-frontend.mdx +0 -30
- package/docs/en/components/enableSwc.mdx +0 -17
- package/docs/en/components/global-proxy-config.mdx +0 -85
- package/docs/en/components/global-proxy.mdx +0 -29
- package/docs/en/components/package-manager.mdx +0 -11
- package/docs/en/components/reduck-notify.mdx +0 -27
- package/docs/en/components/reduck-tip.mdx +0 -8
- package/docs/en/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/en/configure/app/deploy/microFrontend.mdx +0 -53
- package/docs/en/configure/app/dev/port.mdx +0 -25
- package/docs/en/configure/app/dev/proxy.mdx +0 -9
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +0 -106
- package/docs/en/configure/app/html/disable-html-folder.mdx +0 -46
- package/docs/en/configure/app/html/favicon-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/inject-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/en/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/en/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/en/configure/app/html/template-parameters-by-entries.mdx +0 -35
- package/docs/en/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/en/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/en/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/en/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/en/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/en/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/en/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/en/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/en/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/en/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/en/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/en/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/en/configure/app/runtime/master-app.mdx +0 -36
- package/docs/en/configure/app/runtime/state.mdx +0 -52
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/en/configure/app/source/enable-custom-entry.mdx +0 -68
- package/docs/en/configure/app/source/module-scopes.mdx +0 -72
- package/docs/en/configure/app/source/resolve-extension-prefix.mdx +0 -55
- package/docs/en/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/en/configure/app/tools/babel.mdx +0 -225
- package/docs/en/configure/app/tools/esbuild.mdx +0 -44
- package/docs/en/configure/app/tools/pug.mdx +0 -54
- package/docs/en/configure/app/tools/styled-components.mdx +0 -55
- package/docs/en/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/en/configure/app/tools/terser.mdx +0 -58
- package/docs/en/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/en/configure/app/tools/webpack-chain.mdx +0 -253
- package/docs/en/configure/app/tools/webpack.mdx +0 -309
- package/docs/en/guides/deprecated.md +0 -17
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -27
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +0 -290
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -298
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -26
- package/docs/en/guides/topic-detail/model/_meta.json +0 -14
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -85
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -148
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -62
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -35
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -247
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/en/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -68
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -243
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/en/plugin/cli-plugins/migration.mdx +0 -98
- package/docs/en/plugin/official/cli-plugins/plugin-swc.mdx +0 -363
- package/docs/en/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/en/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/en/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -205
- package/docs/en/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/en/plugin/runtime-plugins/migration.mdx +0 -101
- package/docs/en/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/en/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/en/tutorials/first-app/c03-css.mdx +0 -324
- package/docs/en/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/en/tutorials/first-app/c05-loader.mdx +0 -87
- package/docs/en/tutorials/first-app/c06-model.mdx +0 -278
- package/docs/en/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/en/tutorials/first-app/c08-entries.mdx +0 -135
- package/docs/zh/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/zh/apis/app/hooks/src/index_.mdx +0 -39
- package/docs/zh/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/zh/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/zh/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/zh/apis/app/runtime/core/create-app.mdx +0 -35
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/zh/apis/app/runtime/core/use-module-apps.mdx +0 -179
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/zh/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/zh/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/zh/apis/app/runtime/model/connect.mdx +0 -143
- package/docs/zh/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/zh/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +0 -108
- package/docs/zh/apis/app/runtime/model/model_.mdx +0 -201
- package/docs/zh/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/zh/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/zh/apis/app/runtime/model/use-static-model.mdx +0 -49
- package/docs/zh/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/zh/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +0 -136
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +0 -114
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +0 -165
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/zh/components/bff-proxy-principle.mdx +0 -1
- package/docs/zh/components/builder.mdx +0 -3
- package/docs/zh/components/create-bff-api-app.mdx +0 -25
- package/docs/zh/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/zh/components/default-mwa-generate.mdx +0 -4
- package/docs/zh/components/enable-micro-frontend.mdx +0 -30
- package/docs/zh/components/enableSwc.mdx +0 -17
- package/docs/zh/components/global-proxy-config.mdx +0 -85
- package/docs/zh/components/global-proxy.mdx +0 -29
- package/docs/zh/components/package-manager.mdx +0 -11
- package/docs/zh/components/reduck-notify.mdx +0 -27
- package/docs/zh/components/reduck-tip.mdx +0 -8
- package/docs/zh/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/zh/configure/app/deploy/microFrontend.mdx +0 -55
- package/docs/zh/configure/app/dev/port.mdx +0 -25
- package/docs/zh/configure/app/dev/proxy.mdx +0 -9
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +0 -105
- package/docs/zh/configure/app/html/disable-html-folder.mdx +0 -45
- package/docs/zh/configure/app/html/favicon-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/inject-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/zh/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/zh/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +0 -36
- package/docs/zh/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/zh/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/zh/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/zh/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/zh/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/zh/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/zh/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/zh/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/zh/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/zh/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/zh/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/zh/configure/app/runtime/master-app.mdx +0 -38
- package/docs/zh/configure/app/runtime/state.mdx +0 -52
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/zh/configure/app/source/enable-custom-entry.mdx +0 -67
- package/docs/zh/configure/app/source/module-scopes.mdx +0 -72
- package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +0 -57
- package/docs/zh/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/zh/configure/app/tools/babel.mdx +0 -224
- package/docs/zh/configure/app/tools/esbuild.mdx +0 -44
- package/docs/zh/configure/app/tools/pug.mdx +0 -54
- package/docs/zh/configure/app/tools/styled-components.mdx +0 -54
- package/docs/zh/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/zh/configure/app/tools/terser.mdx +0 -58
- package/docs/zh/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/zh/configure/app/tools/webpack-chain.mdx +0 -257
- package/docs/zh/configure/app/tools/webpack.mdx +0 -309
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -154
- package/docs/zh/guides/deprecated.md +0 -19
- package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -26
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +0 -332
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -296
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -27
- package/docs/zh/guides/topic-detail/model/_meta.json +0 -14
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -88
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -147
- package/docs/zh/guides/topic-detail/model/define-model.mdx +0 -63
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -36
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -256
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -67
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -248
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/zh/plugin/cli-plugins/migration.mdx +0 -98
- package/docs/zh/plugin/official/cli-plugins/plugin-swc.mdx +0 -351
- package/docs/zh/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/zh/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/zh/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -201
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/zh/plugin/runtime-plugins/migration.mdx +0 -101
- package/docs/zh/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/zh/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/zh/tutorials/first-app/c03-css.mdx +0 -323
- package/docs/zh/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/zh/tutorials/first-app/c05-loader.mdx +0 -89
- package/docs/zh/tutorials/first-app/c06-model.mdx +0 -274
- package/docs/zh/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/zh/tutorials/first-app/c08-entries.mdx +0 -135
- /package/docs/en/components/{reduck-migration.mdx → auto-upgrade.mdx} +0 -0
- /package/docs/en/components/{router-legacy-tip.mdx → international/platform-support.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/new-entry-tooltip.mdx} +0 -0
- /package/docs/{zh/components/router-legacy-tip.mdx → en/components/upgrade-browserslist.mdx} +0 -0
|
@@ -8,11 +8,7 @@ Modern.js provides out-of-the-box data fetching capabilities. Developers can use
|
|
|
8
8
|
|
|
9
9
|
## What is Data Loader
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
In Modern.js v1 projects, data was fetched using `useLoader`. This is no longer the recommended approach; we suggest migrating to Data Loader.
|
|
13
|
-
:::
|
|
14
|
-
|
|
15
|
-
Modern.js recommends managing routes using [conventional routing](/guides/basic-features/routes). Each route component (`layout.ts`, `page.ts`, or `$.tsx`) can have a same-named `.data` file. These files can export a `loader` function, known as Data Loader, which executes before the corresponding route component renders to provide data for the component. Here is an example:
|
|
11
|
+
Modern.js recommends managing routes using [conventional routing](/guides/basic-features/routes/routes). Each route component (`layout.ts`, `page.ts`, or `$.tsx`) can have a same-named `.data` file. These files can export a `loader` function, known as Data Loader, which executes before the corresponding route component renders to provide data for the component. Here is an example:
|
|
16
12
|
|
|
17
13
|
```bash
|
|
18
14
|
.
|
|
@@ -39,15 +35,18 @@ export const loader = async (): Promise<ProfileData> => {
|
|
|
39
35
|
```
|
|
40
36
|
|
|
41
37
|
:::warning Compatibility
|
|
38
|
+
|
|
42
39
|
- In previous versions, Data Loader was defined in a `.loader` file. In the current version, we recommend defining it in a `.data` file, while maintaining compatibility with `.loader` files.
|
|
43
40
|
- In `.loader` files, the Data Loader can be exported as default. In `.data` files, it should be named `loader` export.
|
|
41
|
+
|
|
44
42
|
```ts
|
|
45
|
-
|
|
46
|
-
export default () => {}
|
|
43
|
+
// xxx.loader.ts
|
|
44
|
+
export default () => {};
|
|
47
45
|
|
|
48
46
|
// xxx.data.ts
|
|
49
|
-
export const loader = () => {}
|
|
47
|
+
export const loader = () => {};
|
|
50
48
|
```
|
|
49
|
+
|
|
51
50
|
:::
|
|
52
51
|
|
|
53
52
|
In the route component, you can use the `useLoaderData` function to fetch data:
|
|
@@ -74,7 +73,7 @@ In an SSR environment, the `loader` function only executes on the server side fo
|
|
|
74
73
|
In future versions, Modern.js may support running `loader` functions on the server side even in CSR environments to improve performance and security. Therefore, it is advisable to keep the `loader` function pure, handling only data fetching scenarios.
|
|
75
74
|
:::
|
|
76
75
|
|
|
77
|
-
When navigating on the client side, based on [conventional routing](/guides/basic-features/routes), Modern.js supports parallel execution (requests) of all `loader` functions. For example, when visiting `/user/profile`, the `loader` functions under `/user` and `/user/profile` will execute in parallel, solving the request-render waterfall issue and significantly improving page performance.
|
|
76
|
+
When navigating on the client side, based on [conventional routing](/guides/basic-features/routes/routes), Modern.js supports parallel execution (requests) of all `loader` functions. For example, when visiting `/user/profile`, the `loader` functions under `/user` and `/user/profile` will execute in parallel, solving the request-render waterfall issue and significantly improving page performance.
|
|
78
77
|
|
|
79
78
|
## `loader` Function
|
|
80
79
|
|
|
@@ -82,7 +81,7 @@ The `loader` function has two parameters used for getting route parameters and r
|
|
|
82
81
|
|
|
83
82
|
### params
|
|
84
83
|
|
|
85
|
-
`params` is the dynamic route segments when the route is a [dynamic route](/guides/basic-features/routes#dynamic-routes), which passed as parameters to the `loader` function:
|
|
84
|
+
`params` is the dynamic route segments when the route is a [dynamic route](/guides/basic-features/routes/routes#dynamic-routes), which passed as parameters to the `loader` function:
|
|
86
85
|
|
|
87
86
|
```tsx title="routes/user/[id]/page.data.ts"
|
|
88
87
|
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
@@ -100,7 +99,7 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
|
100
99
|
`request` is an instance of [Fetch Request](https://developer.mozilla.org/en-US/docs/Web/API/Request). A common use case is to get query parameters from `request`:
|
|
101
100
|
|
|
102
101
|
```tsx
|
|
103
|
-
import { LoaderFunctionArgs } from '@modern-js/runtime/router;
|
|
102
|
+
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
104
103
|
|
|
105
104
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
106
105
|
const url = new URL(request.url);
|
|
@@ -146,20 +145,22 @@ In SSR applications, the `loader` function runs only on the server, hence it is
|
|
|
146
145
|
|
|
147
146
|
:::note
|
|
148
147
|
Having the `loader` function run only on the server in SSR applications brings several benefits:
|
|
148
|
+
|
|
149
149
|
- **Simplifies usage**: Guarantees consistent data-fetching methods in SSR applications, so developers don't have to distinguish between client and server code.
|
|
150
150
|
- **Reduces client bundle size**: Moves logic code and dependencies from the client to the server.
|
|
151
151
|
- **Improves maintainability**: Less direct influence of data logic on front-end UI and avoids issues of accidentally including server dependencies in the client bundle or vice versa.
|
|
152
152
|
|
|
153
153
|
:::
|
|
154
154
|
|
|
155
|
-
We recommend using the `fetch` API in `loader` functions to make requests.
|
|
155
|
+
We recommend using the `fetch` API in `loader` functions to make requests. Modern.js provides a default polyfill for the `fetch` API, allowing it to be used on the server side. This means you can fetch data in a consistent manner whether in CSR or SSR:
|
|
156
156
|
|
|
157
157
|
```tsx
|
|
158
158
|
export async function loader() {
|
|
159
159
|
const res = await fetch('URL_ADDRESS');
|
|
160
|
+
const data = await res.json();
|
|
160
161
|
return {
|
|
161
|
-
message:
|
|
162
|
-
}
|
|
162
|
+
message: data.message,
|
|
163
|
+
};
|
|
163
164
|
}
|
|
164
165
|
```
|
|
165
166
|
|
|
@@ -167,7 +168,7 @@ export async function loader() {
|
|
|
167
168
|
|
|
168
169
|
### Basic Usage
|
|
169
170
|
|
|
170
|
-
In a `loader` function, you can handle errors by using `throw error` or `throw response`. When an error is thrown in the `loader` function, Modern.js will stop executing the remaining code in the current `loader` and switch the front-end UI to the defined [`ErrorBoundary`](/guides/basic-features/routes#error-handling) component:
|
|
171
|
+
In a `loader` function, you can handle errors by using `throw error` or `throw response`. When an error is thrown in the `loader` function, Modern.js will stop executing the remaining code in the current `loader` and switch the front-end UI to the defined [`ErrorBoundary`](/guides/basic-features/routes/routes#error-handling) component:
|
|
171
172
|
|
|
172
173
|
```tsx
|
|
173
174
|
// routes/user/profile/page.data.ts
|
|
@@ -204,14 +205,14 @@ In the following example, the page's status code will match this `response`, and
|
|
|
204
205
|
// routes/user/profile/page.data.ts
|
|
205
206
|
export async function loader() {
|
|
206
207
|
const user = await fetchUser();
|
|
207
|
-
if(!user){
|
|
208
|
+
if (!user) {
|
|
208
209
|
throw new Response('The user was not found', { status: 404 });
|
|
209
210
|
}
|
|
210
211
|
return user;
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
// routes/error.tsx
|
|
214
|
-
import { useRouteError } from '@modern-js/runtime/router;
|
|
215
|
+
import { useRouteError } from '@modern-js/runtime/router';
|
|
215
216
|
const ErrorBoundary = () => {
|
|
216
217
|
const error = useRouteError() as { data: string };
|
|
217
218
|
return <div className="error">{error.data}</div>;
|
|
@@ -240,7 +241,7 @@ export function UserLayout() {
|
|
|
240
241
|
}
|
|
241
242
|
```
|
|
242
243
|
|
|
243
|
-
`useRouteLoaderData` accepts a parameter `routeId`. In conventional routing, Modern.js automatically generates the `routeId`, which is the path of the corresponding component relative to `src/routes`.
|
|
244
|
+
`useRouteLoaderData` accepts a parameter `routeId`. In conventional routing, Modern.js automatically generates the `routeId`, which is the path of the corresponding component relative to `src/routes`. For example, in the example above, if a child component wants to get data returned by the loader in `routes/user/layout.tsx`, the `routeId` value is `user/layout`.
|
|
244
245
|
|
|
245
246
|
In a multi-entry scenario, the `routeId` value needs to include the corresponding entry name, which is typically the directory name if not explicitly specified. For example, with the following directory structure:
|
|
246
247
|
|
|
@@ -13,7 +13,7 @@ In Modern.js, you can use Data Action to address these scenarios.
|
|
|
13
13
|
|
|
14
14
|
## What is Data Action
|
|
15
15
|
|
|
16
|
-
Modern.js recommends managing routes using [conventional routing](/guides/basic-features/routes). Each route component (`layout.ts`, `page.ts`, or `$.tsx`) can have a same-named `.data` file. These files can export an `action` function, known as Data Action, which developers can call at an appropriate time:
|
|
16
|
+
Modern.js recommends managing routes using [conventional routing](/guides/basic-features/routes/routes). Each route component (`layout.ts`, `page.ts`, or `$.tsx`) can have a same-named `.data` file. These files can export an `action` function, known as Data Action, which developers can call at an appropriate time:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
19
|
.
|
|
@@ -81,7 +81,7 @@ Similar to the `loader` function, the `action` function takes two parameters: `p
|
|
|
81
81
|
|
|
82
82
|
### params
|
|
83
83
|
|
|
84
|
-
`params` is the dynamic route segments when the route is a [dynamic route](/guides/basic-features/routes#dynamic-routes), which are passed as parameters to the `action` function:
|
|
84
|
+
`params` is the dynamic route segments when the route is a [dynamic route](/guides/basic-features/routes/routes#dynamic-routes), which are passed as parameters to the `action` function:
|
|
85
85
|
|
|
86
86
|
```tsx title="routes/user/[id]/page.data.ts"
|
|
87
87
|
import { ActionFunctionArgs } from '@modern-js/runtime/router;
|
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
export default {
|
|
73
|
-
'api/getInfo': (req, res) => {
|
|
73
|
+
'/api/getInfo': (req, res) => {
|
|
74
74
|
setTimeout(() => {
|
|
75
75
|
res.end('delay 2000ms');
|
|
76
76
|
}, 2000);
|
|
@@ -83,6 +83,9 @@ export default {
|
|
|
83
83
|
Under the `config/mock/index.ts`, you can also export the `config` to control the Mock service.
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
+
import type { IncomingMessage } from 'node:http';
|
|
87
|
+
import type { ServerResponse } from 'node:http';
|
|
88
|
+
|
|
86
89
|
type MockConfig = {
|
|
87
90
|
enable: ((req: IncomingMessage, res: ServerResponse) => boolean) | boolean;
|
|
88
91
|
};
|
|
@@ -4,35 +4,24 @@ sidebar_position: 6
|
|
|
4
4
|
|
|
5
5
|
# Network Proxy
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Modern.js provides a way to configure the development proxy in [`tools.devServer`](/configure/app/tools/dev-server). For example, to proxy the local interface to an online address:
|
|
7
|
+
Modern.js provides a way to configure the development proxy in [`dev.server.proxy`](/configure/app/dev/server). For example, to proxy the local interface to an online address:
|
|
10
8
|
|
|
11
9
|
```ts title="modern.config.ts"
|
|
12
10
|
import { defineConfig } from '@modern-js/app-tools';
|
|
13
11
|
|
|
14
12
|
export default defineConfig({
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
dev: {
|
|
14
|
+
server: {
|
|
17
15
|
proxy: {
|
|
18
|
-
'/go/api':
|
|
19
|
-
target: 'http://www.example.com/',
|
|
20
|
-
changeOrigin: true,
|
|
21
|
-
},
|
|
16
|
+
'/go/api': 'http://www.example.com/',
|
|
22
17
|
},
|
|
23
18
|
},
|
|
24
19
|
},
|
|
25
20
|
});
|
|
26
21
|
```
|
|
27
22
|
|
|
28
|
-
When
|
|
23
|
+
When accessing `http://localhost:8080/go/api`, the response content will be returned from [http://www.example.com/](http://www.example.com/).
|
|
29
24
|
|
|
30
25
|
:::info
|
|
31
|
-
For
|
|
26
|
+
For configuration format, please refer to: [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware).
|
|
32
27
|
:::
|
|
33
|
-
|
|
34
|
-
## Global Proxy
|
|
35
|
-
|
|
36
|
-
import GlobalProxy from "@site-docs-en/components/global-proxy"
|
|
37
|
-
|
|
38
|
-
<GlobalProxy />
|
|
@@ -26,14 +26,14 @@ import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
|
26
26
|
export default {
|
|
27
27
|
// ...
|
|
28
28
|
tools: {
|
|
29
|
-
|
|
29
|
+
bundlerChain(chain) {
|
|
30
30
|
// Only register the plugin when RSDOCTOR is true, as the plugin will increase build time.
|
|
31
31
|
if (process.env.RSDOCTOR) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
|
|
33
|
+
{
|
|
34
34
|
// Plugin options
|
|
35
|
-
}
|
|
36
|
-
);
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
},
|
|
@@ -5,6 +5,7 @@ sidebar_position: 15
|
|
|
5
5
|
# Deploy Application
|
|
6
6
|
|
|
7
7
|
Currently, Modern.js offers two deployment way:
|
|
8
|
+
|
|
8
9
|
- You can host your application in a container that includes a Node.js environment on your own, which provides flexibility for the deployment of the application.
|
|
9
10
|
- You can also deploy your application through a platform. Currently, Modern.js officially supports deployment on [Netlify](https://www.netlify.com/), [Vercel](https://vercel.com/), and [Github pages](https://pages.github.com/).
|
|
10
11
|
|
|
@@ -12,7 +13,6 @@ Currently, Modern.js offers two deployment way:
|
|
|
12
13
|
Currently, Modern.js only supports running in a Node.js environment. Support for more runtime environments will be provided in the future.
|
|
13
14
|
:::
|
|
14
15
|
|
|
15
|
-
|
|
16
16
|
## Build Deployment Products
|
|
17
17
|
|
|
18
18
|
Running the `modern deploy` command will automatically produce deployment products. This process includes optimizing Bundler build products and their dependencies, detecting the current deployment platform, and automatically generating deployment products that can run on that platform.
|
|
@@ -50,11 +50,12 @@ At this point, you can run the entire server by `node .output/index`, and the st
|
|
|
50
50
|
|
|
51
51
|
:::info
|
|
52
52
|
By default, when running Modern.js Server, it listens on port 8080. If you want to change the listening port, you can specify the `PORT` environment variable:
|
|
53
|
+
|
|
53
54
|
```
|
|
54
55
|
PORT=3000 node .output/index
|
|
55
56
|
```
|
|
56
|
-
:::
|
|
57
57
|
|
|
58
|
+
:::
|
|
58
59
|
|
|
59
60
|
### Monorepo
|
|
60
61
|
|
|
@@ -66,7 +67,7 @@ Assume that the name in the `package.json` of the current project is `app`. Taki
|
|
|
66
67
|
{
|
|
67
68
|
"scripts": {
|
|
68
69
|
"build:packages": "pnpm --filter 'app^...' run build",
|
|
69
|
-
"deploy": "pnpm run build:packages && modern deploy"
|
|
70
|
+
"deploy": "pnpm run build:packages && modern deploy"
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
```
|
|
@@ -77,7 +78,7 @@ If you use Rush as your Monorepo management tool, you can add the following comm
|
|
|
77
78
|
{
|
|
78
79
|
"scripts": {
|
|
79
80
|
"build:packages": "rush rebuild --to-except app",
|
|
80
|
-
"deploy": "rushx build:packages && modern deploy"
|
|
81
|
+
"deploy": "rushx build:packages && modern deploy"
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
```
|
|
@@ -134,12 +135,12 @@ Full-stack projects refer to projects that use Custom Web Server, SSR or BFF. Th
|
|
|
134
135
|
```
|
|
135
136
|
|
|
136
137
|
:::info
|
|
138
|
+
|
|
137
139
|
1. Currently, Modern.js does not support deployment on Netlify Edge Functions. We will support it in future versions.
|
|
138
140
|
2. You can refer to the [deployment project example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-ssr).
|
|
139
141
|
|
|
140
142
|
:::
|
|
141
143
|
|
|
142
|
-
|
|
143
144
|
### Monorepo
|
|
144
145
|
|
|
145
146
|
:::info
|
|
@@ -172,10 +173,9 @@ Add the following script in `packages/app/package.json`, before executing the de
|
|
|
172
173
|
{
|
|
173
174
|
"scripts": {
|
|
174
175
|
"build:packages": "pnpm --filter 'app^...' run build",
|
|
175
|
-
"deploy": "pnpm run build:packages && modern deploy"
|
|
176
|
+
"deploy": "pnpm run build:packages && modern deploy"
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
|
-
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
Configure the build command in `netlify.toml`:
|
|
@@ -200,6 +200,7 @@ Vercel is a deployment platform for modern web applications that provides a rich
|
|
|
200
200
|
### Pure Front-end Project
|
|
201
201
|
|
|
202
202
|
Add the `vercel.json` file to the root directory of the current project:
|
|
203
|
+
|
|
203
204
|
```bash
|
|
204
205
|
./
|
|
205
206
|
├── src
|
|
@@ -209,6 +210,7 @@ Add the `vercel.json` file to the root directory of the current project:
|
|
|
209
210
|
```
|
|
210
211
|
|
|
211
212
|
Add the following content to `vercel.json`:
|
|
213
|
+
|
|
212
214
|
```json title="vercel.json"
|
|
213
215
|
{
|
|
214
216
|
"buildCommand": "modern deploy",
|
|
@@ -265,13 +267,13 @@ First, you need to configure the **Root Directory** as `packages/app` on the Ver
|
|
|
265
267
|
|
|
266
268
|
<img src="https://sf16-sg.tiktokcdn.com/obj/eden-sg/lmeh7nuptpfnuhd/vercel-root-directory.png" />
|
|
267
269
|
|
|
268
|
-
Specify Node.js runtime as `
|
|
270
|
+
Specify Node.js runtime as `20.x`:
|
|
269
271
|
|
|
270
272
|
```json title="package.json"
|
|
271
273
|
"engines": {
|
|
272
|
-
"node": "
|
|
274
|
+
"node": "20.x"
|
|
273
275
|
}
|
|
274
|
-
|
|
276
|
+
```
|
|
275
277
|
|
|
276
278
|
Add the following script to `packages/app/package.json` to run `build` command of the other repositories in the workspace before run the `deploy` command for the `app` repository:
|
|
277
279
|
|
|
@@ -279,7 +281,7 @@ Add the following script to `packages/app/package.json` to run `build` command o
|
|
|
279
281
|
{
|
|
280
282
|
"scripts": {
|
|
281
283
|
"build:packages": "pnpm --filter 'app^...' run build",
|
|
282
|
-
"deploy": "pnpm run build:packages && modern deploy"
|
|
284
|
+
"deploy": "pnpm run build:packages && modern deploy"
|
|
283
285
|
}
|
|
284
286
|
}
|
|
285
287
|
```
|
|
@@ -305,11 +307,11 @@ import { defineConfig } from '@modern-js/app-tools';
|
|
|
305
307
|
export default defineConfig({
|
|
306
308
|
//...
|
|
307
309
|
server: {
|
|
308
|
-
baseUrl:
|
|
310
|
+
baseUrl: '/<repository-name>',
|
|
309
311
|
},
|
|
310
312
|
output: {
|
|
311
|
-
assetPrefix:
|
|
312
|
-
}
|
|
313
|
+
assetPrefix: '/<repository-name>',
|
|
314
|
+
},
|
|
313
315
|
});
|
|
314
316
|
```
|
|
315
317
|
|
|
@@ -320,6 +322,7 @@ For branch deployment, follow these steps:
|
|
|
320
322
|
1. In the GitHub repository, navigate to Settings > Pages > Source > Deploy from a branch
|
|
321
323
|
2. Install the `gh-pages` as devDependency
|
|
322
324
|
3. Add the following script to `package.json`
|
|
325
|
+
|
|
323
326
|
```
|
|
324
327
|
"scripts": {
|
|
325
328
|
//...
|
|
@@ -330,13 +333,13 @@ For branch deployment, follow these steps:
|
|
|
330
333
|
4. Run `npm run deploy:gh-pages`
|
|
331
334
|
|
|
332
335
|
:::info
|
|
336
|
+
|
|
333
337
|
1. Running `MODERNJS_DEPLOY=ghPages modern deploy` will build the production output for GitHub in the .output directory.
|
|
334
338
|
2. You can refer to the [project](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr)
|
|
335
|
-
:::
|
|
339
|
+
:::
|
|
336
340
|
|
|
337
341
|
For GitHub Actions deployment, select Settings > Pages > Source > GitHub Actions, and add a workflow file to the project. You can refer to the [example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr).
|
|
338
342
|
|
|
339
|
-
|
|
340
343
|
## Using Self-Built Node.js Server
|
|
341
344
|
|
|
342
345
|
Typically, we recommend using the built-in Node.js server of Modern.js to deploy applications. It supports hosting both pure frontend and full-stack projects, ensuring consistent performance in both development and production environments.
|
|
@@ -381,10 +384,14 @@ const app = new Koa();
|
|
|
381
384
|
app.use(async (ctx, next) => {
|
|
382
385
|
if (ctx.path.startsWith('/static')) {
|
|
383
386
|
ctx.type = mime.lookup(ctx.path);
|
|
384
|
-
ctx.body = fs.createReadStream(
|
|
387
|
+
ctx.body = fs.createReadStream(
|
|
388
|
+
path.resolve(__dirname, `.output${ctx.path}`),
|
|
389
|
+
);
|
|
385
390
|
} else if (ctx.path === '/') {
|
|
386
391
|
ctx.type = 'html';
|
|
387
|
-
ctx.body = fs.createReadStream(
|
|
392
|
+
ctx.body = fs.createReadStream(
|
|
393
|
+
path.resolve(__dirname, '.output/html/main/index.html'),
|
|
394
|
+
);
|
|
388
395
|
}
|
|
389
396
|
});
|
|
390
397
|
app.listen(3000);
|
|
@@ -40,7 +40,7 @@ Modern.js provides some components for rendering pages to help developers genera
|
|
|
40
40
|
import { Html, Body, Root, Head, Scripts } from '@modern-js/runtime/document';
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
- `Html`: provide the ability of native HTML Element and
|
|
43
|
+
- `Html`: provide the ability of native HTML Element and render necessary components that the developer did not add by default. `<Head>` and `<Body>` must exist, and other components can be assembled as needed.
|
|
44
44
|
|
|
45
45
|
- `Body`: provide the ability of native Body Element and needs to contain the `<Root>` component internally. It also supports other elements as child elements at the same time, such as adding footers.
|
|
46
46
|
|
|
@@ -47,8 +47,8 @@ Modern.js provides some configs to modify the directory or filename, you can:
|
|
|
47
47
|
- Modify the filename through [output.filename](/configure/app/output/filename).
|
|
48
48
|
- Modify the output path of through [output.distPath](/configure/app/output/dist-path).
|
|
49
49
|
- Modify the license file through [output.legalComments](/configure/app/output/legal-comments).
|
|
50
|
-
- Remove Source Map file through [output.
|
|
51
|
-
- Remove the folder corresponding to the HTML files through [html.
|
|
50
|
+
- Remove Source Map file through [output.sourceMap](/configure/app/output/source-map).
|
|
51
|
+
- Remove the folder corresponding to the HTML files through [html.outputStructure](/configure/app/html/output-structure).
|
|
52
52
|
|
|
53
53
|
## Static Assets
|
|
54
54
|
|
|
@@ -112,7 +112,7 @@ export default {
|
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
html: {
|
|
115
|
-
|
|
115
|
+
outputStructure: 'flat',
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
118
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
["ssr", "streaming-ssr", "ssr-cache", "ssg", "before-render"]
|
|
1
|
+
["overview", "ssr", "streaming-ssr", "ssr-cache", "ssg", "rsc", "before-render"]
|
|
@@ -5,12 +5,12 @@ In certain scenarios, applications need to perform preprocessing operations befo
|
|
|
5
5
|
## Defining a Runtime Plugin
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import type {
|
|
8
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
9
9
|
|
|
10
|
-
const myRuntimePlugin = ():
|
|
10
|
+
const myRuntimePlugin = (): RuntimePlugin => ({
|
|
11
11
|
name: 'my-runtime-plugin',
|
|
12
|
-
setup:
|
|
13
|
-
api.onBeforeRender(
|
|
12
|
+
setup: api => {
|
|
13
|
+
api.onBeforeRender(context => {
|
|
14
14
|
// Logic to execute before rendering
|
|
15
15
|
console.log('Before rendering:', context);
|
|
16
16
|
});
|
|
@@ -35,23 +35,24 @@ export default defineRuntimeConfig({
|
|
|
35
35
|
|
|
36
36
|
## Use Case -- Global Data Injection
|
|
37
37
|
|
|
38
|
-
Through the `context` parameter of the `onBeforeRender` hook, you can inject global data into your application. Application components can access this data using the `
|
|
38
|
+
Through the `context` parameter of the `onBeforeRender` hook, you can inject global data into your application. Application components can access this data using the `use(RuntimeContext)` Hook.
|
|
39
39
|
|
|
40
40
|
:::info
|
|
41
41
|
|
|
42
42
|
This feature is particularly useful in the following scenarios:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
|
|
44
|
+
- Applications requiring page-level preliminary data
|
|
45
|
+
- Custom data injection workflows
|
|
46
|
+
- Framework migration scenarios (e.g., migrating from Next.js)
|
|
46
47
|
|
|
47
48
|
:::
|
|
48
49
|
|
|
49
50
|
**Defining a Data Injection Plugin**
|
|
50
51
|
|
|
51
52
|
```ts
|
|
52
|
-
import type {
|
|
53
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
53
54
|
|
|
54
|
-
const dataInjectionPlugin = ():
|
|
55
|
+
const dataInjectionPlugin = (): RuntimePlugin => ({
|
|
55
56
|
name: 'data-injection-plugin',
|
|
56
57
|
setup: api => {
|
|
57
58
|
api.onBeforeRender(context => {
|
|
@@ -67,10 +68,11 @@ export default dataInjectionPlugin;
|
|
|
67
68
|
**Using Injected Data in Components**
|
|
68
69
|
|
|
69
70
|
```tsx
|
|
70
|
-
import {
|
|
71
|
+
import { use } from 'react';
|
|
72
|
+
import { RuntimeContext } from '@modern-js/runtime';
|
|
71
73
|
|
|
72
74
|
export default function MyComponent() {
|
|
73
|
-
const context =
|
|
75
|
+
const context = use(RuntimeContext);
|
|
74
76
|
const { message } = context;
|
|
75
77
|
|
|
76
78
|
return <div>{message}</div>;
|
|
@@ -82,9 +84,9 @@ export default function MyComponent() {
|
|
|
82
84
|
In SSR scenarios, the browser can access data injected via `onBeforeRender` during server-side rendering. Developers can decide whether to re-fetch data on the browser side to override server data based on their requirements.
|
|
83
85
|
|
|
84
86
|
```ts
|
|
85
|
-
import type {
|
|
87
|
+
import type { RuntimePlugin } from '@modern-js/runtime';
|
|
86
88
|
|
|
87
|
-
const dataInjectionPlugin = ():
|
|
89
|
+
const dataInjectionPlugin = (): RuntimePlugin => ({
|
|
88
90
|
name: 'data-injection-plugin',
|
|
89
91
|
setup: api => {
|
|
90
92
|
api.onBeforeRender(context => {
|
|
@@ -104,12 +106,3 @@ const dataInjectionPlugin = (): RuntimePluginFuture => ({
|
|
|
104
106
|
|
|
105
107
|
export default dataInjectionPlugin;
|
|
106
108
|
```
|
|
107
|
-
|
|
108
|
-
## Compatibility Notes
|
|
109
|
-
|
|
110
|
-
In earlier versions of Modern.js, it was possible to add render preprocessing logic through the `init` hook in `routes/layout.tsx` and the `App.init` method. These approaches are still **supported**, but we **strongly recommend** implementing with Runtime plugins instead.
|
|
111
|
-
|
|
112
|
-
:::warning
|
|
113
|
-
|
|
114
|
-
In future versions, the `init` hook in `routes/layout.tsx` and the `App.init` method will be gradually **deprecated**. We recommend migrating to the Runtime plugin approach as soon as possible.
|
|
115
|
-
:::
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Rendering Mode Overview
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Rendering Mode Overview
|
|
6
|
+
|
|
7
|
+
Modern.js supports multiple rendering modes, and different rendering modes are suitable for different scenarios. Choosing the right rendering mode can significantly improve application performance and user experience.
|
|
8
|
+
|
|
9
|
+
## Rendering Mode Quick Reference
|
|
10
|
+
|
|
11
|
+
| Rendering Mode | Characteristics | Use Cases |
|
|
12
|
+
|----------------|-----------------|-----------|
|
|
13
|
+
| **CSR** | Executes JavaScript in the browser to render pages | Applications with strong interactivity and low SEO requirements |
|
|
14
|
+
| **SSR** | Pre-renders complete HTML pages on the server | Websites with high requirements for first-screen performance and SEO |
|
|
15
|
+
| **Streaming SSR** | Renders and returns progressively, displaying initial UI faster | Applications requiring faster first-screen perception speed (**Default SSR mode**) |
|
|
16
|
+
| **RSC** | Components render on the server, reducing client JS size; high cohesion between data and component logic, reducing state passing | Projects pursuing optimal performance and needing to reduce client-side code |
|
|
17
|
+
| **SSG** | Generates static pages at build time, can be cached by CDN | Websites with relatively static content, such as blogs and documentation sites |
|
|
18
|
+
|
|
19
|
+
## Performance Comparison
|
|
20
|
+
|
|
21
|
+
| Rendering Technology | Core Advantages | Main Bottlenecks |
|
|
22
|
+
|---------------------|-----------------|------------------|
|
|
23
|
+
| **SSR** | Server-side pre-rendering, beneficial for SEO | Must wait for all data to load before responding |
|
|
24
|
+
| **Streaming SSR** | Renders and returns progressively, faster first screen | JS bundle size is still large |
|
|
25
|
+
| **Streaming SSR + RSC** | Reduces client JS size | - |
|
|
26
|
+
|
|
27
|
+
## How to Choose
|
|
28
|
+
|
|
29
|
+
### Quick Decision Guide
|
|
30
|
+
|
|
31
|
+
- **Static Content + SEO Required** → **SSG**
|
|
32
|
+
- **SEO Required + First Screen Performance** → **Streaming SSR** (default)
|
|
33
|
+
- **Pursuing Optimal Performance** → **Streaming SSR + RSC**
|
|
34
|
+
- **CSR Project Gradual Optimization** → **CSR + RSC**
|
|
35
|
+
- **Highly Interactive + No SEO Needed** → **CSR**
|
|
36
|
+
|
|
37
|
+
### Combining Modes
|
|
38
|
+
|
|
39
|
+
Modern.js supports combining multiple rendering modes:
|
|
40
|
+
|
|
41
|
+
- **Streaming SSR + RSC**: Streaming rendering + reduced client-side code
|
|
42
|
+
- **SSG + SSR**: Some pages static, some pages dynamic
|
|
43
|
+
- **CSR + RSC**: Client-side rendering + partial Server Components
|
|
44
|
+
|
|
45
|
+
## Related Documentation
|
|
46
|
+
|
|
47
|
+
- [Server-Side Rendering (SSR)](/guides/basic-features/render/ssr)
|
|
48
|
+
- [Streaming Server-Side Rendering (Streaming SSR)](/guides/basic-features/render/streaming-ssr)
|
|
49
|
+
- [React Server Components (RSC)](/guides/basic-features/render/rsc)
|
|
50
|
+
- [Static Site Generation (SSG)](/guides/basic-features/render/ssg)
|
|
51
|
+
- [Rendering Cache](/guides/basic-features/render/ssr-cache)
|