vite-plugin-react-server 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -27
- package/dist/index.js.map +1 -1
- package/dist/package.json +34 -14
- package/dist/plugin/{css-collector-elements.d.ts → components/css-collector-elements.d.ts} +1 -1
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/components/css-collector-elements.js.map +1 -0
- package/dist/plugin/{css-collector.d.ts → components/css-collector.d.ts} +1 -1
- package/dist/plugin/components/css-collector.d.ts.map +1 -0
- package/dist/plugin/components/css-collector.js.map +1 -0
- package/dist/plugin/components/html.d.ts +4 -0
- package/dist/plugin/components/html.d.ts.map +1 -0
- package/dist/plugin/components/html.js +17 -0
- package/dist/plugin/components/html.js.map +1 -0
- package/dist/plugin/components/index.d.ts +5 -0
- package/dist/plugin/components/index.d.ts.map +1 -0
- package/dist/plugin/components.js +9 -3
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/autoDiscover/index.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/index.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/index.js +8 -0
- package/dist/plugin/config/{resolveAutoDiscover.d.ts → autoDiscover/resolveAutoDiscover.d.ts} +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/{resolveAutoDiscover.js → autoDiscover/resolveAutoDiscover.js} +10 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +10 -10
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +6 -4
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +8 -4
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/index.d.ts +1 -0
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +1 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts +2 -0
- package/dist/plugin/config/resolveDevServerConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.d.ts +13 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -0
- package/dist/plugin/config/resolveEnv.js +120 -0
- package/dist/plugin/config/resolveEnv.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +34 -11
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -1
- package/dist/plugin/config/resolveUrlOption.js +1 -2
- package/dist/plugin/config/resolveUrlOption.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -69
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/config.js +17 -0
- package/dist/plugin/config.js.map +1 -0
- package/dist/plugin/env/index.d.ts +2 -0
- package/dist/plugin/env/index.d.ts.map +1 -0
- package/dist/plugin/env/index.js +1 -0
- package/dist/plugin/env/plugin.d.ts +30 -0
- package/dist/plugin/env/plugin.d.ts.map +1 -0
- package/dist/plugin/env/plugin.js +64 -0
- package/dist/plugin/env.js +45 -0
- package/dist/plugin/env.js.map +1 -0
- package/dist/plugin/error/toError.d.ts +6 -0
- package/dist/plugin/error/toError.d.ts.map +1 -0
- package/dist/plugin/error/toError.js +19 -0
- package/dist/plugin/error/toError.js.map +1 -0
- package/dist/plugin/file-preserver/plugin.d.ts +19 -0
- package/dist/plugin/file-preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/file-preserver/plugin.js +108 -0
- package/dist/plugin/file-preserver.js +96 -0
- package/dist/plugin/file-preserver.js.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +10 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createEventHandler.d.ts +1 -1
- package/dist/plugin/helpers/createRscStream.js +1 -1
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/formatMetrics.d.ts +3 -1
- package/dist/plugin/helpers/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/helpers/formatMetrics.js +22 -7
- package/dist/plugin/helpers/formatMetrics.js.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +2 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
- package/dist/plugin/helpers/index.d.ts +24 -0
- package/dist/plugin/helpers/index.d.ts.map +1 -0
- package/dist/plugin/helpers/index.js +31 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +34 -9
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.js +26 -2
- package/dist/plugin/helpers/metrics.js.map +1 -1
- package/dist/plugin/helpers/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleRefs.js.map +1 -0
- package/dist/plugin/helpers/requestInfo.d.ts +26 -0
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -0
- package/dist/plugin/helpers/requestInfo.js +66 -0
- package/dist/plugin/helpers/requestInfo.js.map +1 -0
- package/dist/plugin/helpers/requestToRoute.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -0
- package/dist/plugin/{resolvePage.js → helpers/resolvePage.js} +19 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js +7 -4
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -0
- package/dist/plugin/{resolveProps.js → helpers/resolveProps.js} +9 -6
- package/dist/plugin/helpers/resolveProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.js +19 -13
- package/dist/plugin/helpers/stashReturnValue.js.map +1 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +0 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/helpers.js +27 -0
- package/dist/plugin/helpers.js.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +1 -1
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -7
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/css-loader.production.js.map +1 -1
- package/dist/plugin/loader/env-loader.development.d.ts +12 -0
- package/dist/plugin/loader/env-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/env-loader.development.js +60 -0
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +1 -8
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts +6 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.js +21 -3
- package/dist/plugin/metrics/formatMetrics.js.map +1 -1
- package/dist/plugin/metrics.js +1 -1
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -0
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +1 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +3 -0
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/process-env.d.ts +14 -0
- package/dist/plugin/process-env.d.ts.map +1 -0
- package/dist/plugin/process-env.js +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +11 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.js +47 -0
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -0
- package/dist/plugin/react-client/createWorkerStream.d.ts +9 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +102 -70
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +19 -0
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js +47 -0
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +19 -5
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +6 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +13 -5
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +2 -13
- package/dist/plugin/react-client/server.d.ts.map +1 -1
- package/dist/plugin/react-client/server.js +123 -121
- package/dist/plugin/react-client/server.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +18 -8
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts.map +1 -1
- package/dist/plugin/react-server/server.js +37 -23
- package/dist/plugin/react-server/server.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +9 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +58 -54
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts +1 -1
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -1
- package/dist/plugin/react-static/fileWriter.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +21 -23
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +3 -2
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +3 -12
- package/dist/plugin/transformer/plugin.client.js.map +1 -1
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +17 -24
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +1 -10
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +40 -38
- package/dist/plugin/types.d.ts +60 -15
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.js +3 -17
- package/dist/plugin/utils/callServer.js.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +2 -0
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -0
- package/dist/plugin/utils/createCallServer.js +28 -0
- package/dist/plugin/utils/createCallServer.js.map +1 -0
- package/dist/plugin/utils/createReactFetcher.d.ts +3 -1
- package/dist/plugin/utils/createReactFetcher.d.ts.map +1 -1
- package/dist/plugin/utils/createReactFetcher.js +11 -11
- package/dist/plugin/utils/createReactFetcher.js.map +1 -1
- package/dist/plugin/utils/env.d.ts +2 -0
- package/dist/plugin/utils/env.d.ts.map +1 -0
- package/dist/plugin/utils/env.js +9 -0
- package/dist/plugin/utils/env.js.map +1 -0
- package/dist/plugin/utils/envUrls.d.ts +9 -0
- package/dist/plugin/utils/envUrls.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.js +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts +7 -0
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -0
- package/dist/plugin/utils/envUrls.node.js +11 -0
- package/dist/plugin/utils/envUrls.node.js.map +1 -0
- package/dist/plugin/utils/index.d.ts +2 -1
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +2 -1
- package/dist/plugin/utils/moduleBaseURL.d.ts +3 -0
- package/dist/plugin/utils/moduleBaseURL.d.ts.map +1 -0
- package/dist/plugin/utils/moduleBaseURL.js +4 -0
- package/dist/plugin/utils/urls.d.ts +130 -0
- package/dist/plugin/utils/urls.d.ts.map +1 -0
- package/dist/plugin/utils/urls.js +87 -0
- package/dist/plugin/utils/urls.js.map +1 -0
- package/dist/plugin/utils.js +2 -1
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/vendor/index.d.ts +2 -0
- package/dist/plugin/vendor/index.d.ts.map +1 -0
- package/dist/plugin/vendor/index.js +1 -0
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.client.js.map +1 -0
- package/dist/plugin/vendor/vendor.d.ts +2 -0
- package/dist/plugin/vendor/vendor.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.js +15 -0
- package/dist/plugin/vendor/vendor.js.map +1 -0
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor/vendor.server.js.map +1 -0
- package/dist/plugin/vendor.js +7 -0
- package/dist/plugin/vendor.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +3 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +37 -23
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +4 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -7
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +4 -4
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +42 -16
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +16 -5
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.js +45 -43
- package/dist/plugin/worker/sendMessage.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +32 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -14
- package/plugin/{css-collector-elements.tsx → components/css-collector-elements.tsx} +1 -1
- package/plugin/{css-collector.tsx → components/css-collector.tsx} +1 -1
- package/plugin/{html.tsx → components/html.tsx} +1 -3
- package/{dist/plugin/components.d.ts → plugin/components/index.ts} +1 -1
- package/plugin/config/autoDiscover/index.ts +10 -0
- package/plugin/config/{resolveAutoDiscover.ts → autoDiscover/resolveAutoDiscover.ts} +16 -12
- package/plugin/config/autoDiscover/resolveBuildPages.ts +10 -11
- package/plugin/config/defaults.tsx +6 -4
- package/plugin/config/index.ts +1 -1
- package/plugin/config/resolveEnv.ts +187 -0
- package/plugin/config/resolveOptions.ts +60 -27
- package/plugin/config/resolveUrlOption.ts +2 -7
- package/plugin/config/resolveUserConfig.ts +145 -98
- package/plugin/env/index.ts +1 -0
- package/plugin/env/plugin.ts +78 -0
- package/plugin/error/toError.ts +19 -0
- package/plugin/file-preserver/plugin.ts +117 -0
- package/plugin/helpers/createCssProps.tsx +14 -6
- package/plugin/helpers/createRscStream.tsx +1 -1
- package/plugin/helpers/formatMetrics.ts +2 -2
- package/plugin/helpers/getRouteFiles.ts +3 -1
- package/plugin/helpers/index.ts +38 -0
- package/plugin/helpers/inputNormalizer.ts +66 -17
- package/plugin/helpers/requestInfo.ts +91 -0
- package/plugin/{resolvePage.ts → helpers/resolvePage.ts} +19 -4
- package/plugin/helpers/resolvePageAndProps.ts +7 -4
- package/plugin/{resolveProps.ts → helpers/resolveProps.ts} +8 -6
- package/plugin/helpers/serializeUserOptions.ts +1 -1
- package/plugin/helpers/tryManifest.ts +0 -1
- package/plugin/loader/createBuildLoader.ts +1 -1
- package/plugin/loader/css-loader.development.ts +2 -8
- package/plugin/loader/env-loader.development.ts +84 -0
- package/plugin/loader/react-loader.ts +1 -10
- package/plugin/metrics/formatMetrics.ts +29 -4
- package/plugin/plugin.client.ts +2 -0
- package/plugin/plugin.server.ts +3 -0
- package/plugin/plugin.ts +1 -3
- package/plugin/preserver/plugin.ts +1 -0
- package/plugin/process-env.ts +13 -0
- package/plugin/react-client/createMessageHandlers.ts +49 -0
- package/plugin/react-client/createWorkerStream.ts +130 -83
- package/plugin/react-client/handleWorkerRscStream.ts +57 -0
- package/plugin/react-client/plugin.ts +30 -17
- package/plugin/react-client/restartWorker.ts +15 -7
- package/plugin/react-client/server.ts +129 -164
- package/plugin/react-server/plugin.ts +26 -13
- package/plugin/react-server/server.ts +40 -35
- package/plugin/react-static/collectHtmlWorkerContent.ts +13 -1
- package/plugin/react-static/configurePreviewServer.ts +75 -62
- package/plugin/react-static/fileWriter.ts +1 -1
- package/plugin/react-static/plugin.ts +23 -30
- package/plugin/root.ts +7 -1
- package/plugin/transformer/plugin.client.ts +4 -12
- package/plugin/transformer/plugin.server.ts +18 -25
- package/plugin/transformer/upgradeCssModuleCode.ts +39 -39
- package/plugin/types/env.d.ts +7 -0
- package/plugin/types.ts +80 -29
- package/plugin/utils/callServer.ts +3 -24
- package/plugin/utils/createCallServer.ts +26 -0
- package/plugin/utils/createReactFetcher.ts +14 -12
- package/plugin/utils/env.ts +1 -0
- package/plugin/utils/envUrls.node.ts +19 -0
- package/plugin/utils/envUrls.ts +8 -0
- package/plugin/utils/index.ts +2 -1
- package/plugin/utils/moduleBaseURL.ts +7 -0
- package/plugin/utils/urls.ts +217 -0
- package/plugin/vendor/index.ts +1 -0
- package/plugin/vendor/vendor.ts +6 -0
- package/plugin/worker/createWorker.ts +41 -30
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +4 -1
- package/plugin/worker/html/html-worker.development.tsx +2 -1
- package/plugin/worker/html/html-worker.production.tsx +2 -1
- package/plugin/worker/rsc/handleRender.ts +6 -12
- package/plugin/worker/rsc/messageHandler.tsx +53 -20
- package/plugin/worker/rsc/rsc-worker.development.ts +23 -9
- package/plugin/worker/rsc/rsc-worker.production.ts +23 -7
- package/plugin/worker/types.ts +35 -4
- package/dist/plugin/components.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +0 -1
- package/dist/plugin/config/resolveAutoDiscover.js.map +0 -1
- package/dist/plugin/copy.d.ts +0 -7
- package/dist/plugin/copy.d.ts.map +0 -1
- package/dist/plugin/copy.js +0 -30
- package/dist/plugin/css-collector-elements.d.ts.map +0 -1
- package/dist/plugin/css-collector-elements.js.map +0 -1
- package/dist/plugin/css-collector.d.ts.map +0 -1
- package/dist/plugin/css-collector.js.map +0 -1
- package/dist/plugin/getCondition.d.ts +0 -2
- package/dist/plugin/getCondition.d.ts.map +0 -1
- package/dist/plugin/html.d.ts +0 -4
- package/dist/plugin/html.d.ts.map +0 -1
- package/dist/plugin/html.js +0 -18
- package/dist/plugin/html.js.map +0 -1
- package/dist/plugin/manifest.d.ts +0 -6
- package/dist/plugin/manifest.d.ts.map +0 -1
- package/dist/plugin/manifest.js +0 -13
- package/dist/plugin/moduleRefs.d.ts.map +0 -1
- package/dist/plugin/moduleRefs.js.map +0 -1
- package/dist/plugin/resolvePage.d.ts.map +0 -1
- package/dist/plugin/resolvePage.js.map +0 -1
- package/dist/plugin/resolveProps.d.ts.map +0 -1
- package/dist/plugin/resolveProps.js.map +0 -1
- package/dist/plugin/utils/pageURL.d.ts +0 -2
- package/dist/plugin/utils/pageURL.d.ts.map +0 -1
- package/dist/plugin/utils/pageURL.js +0 -21
- package/dist/plugin/utils/pageURL.js.map +0 -1
- package/dist/plugin/vendor.client.d.ts.map +0 -1
- package/dist/plugin/vendor.client.js.map +0 -1
- package/dist/plugin/vendor.server.d.ts.map +0 -1
- package/dist/plugin/vendor.server.js.map +0 -1
- package/plugin/copy.ts +0 -39
- package/plugin/manifest.ts +0 -24
- package/plugin/utils/pageURL.ts +0 -28
- /package/dist/plugin/{css-collector-elements.js → components/css-collector-elements.js} +0 -0
- /package/dist/plugin/{css-collector.js → components/css-collector.js} +0 -0
- /package/{plugin/components.ts → dist/plugin/components/index.js} +0 -0
- /package/dist/plugin/{getCondition.js → config/resolveDevServerConfig.js} +0 -0
- /package/dist/plugin/{moduleRefs.d.ts → helpers/moduleRefs.d.ts} +0 -0
- /package/dist/plugin/{moduleRefs.js → helpers/moduleRefs.js} +0 -0
- /package/dist/plugin/{resolvePage.d.ts → helpers/resolvePage.d.ts} +0 -0
- /package/dist/plugin/{resolveProps.d.ts → helpers/resolveProps.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.d.ts → vendor/vendor.client.d.ts} +0 -0
- /package/dist/plugin/{vendor.client.js → vendor/vendor.client.js} +0 -0
- /package/dist/plugin/{vendor.server.d.ts → vendor/vendor.server.d.ts} +0 -0
- /package/dist/plugin/{vendor.server.js → vendor/vendor.server.js} +0 -0
- /package/plugin/{getCondition.ts → config/resolveDevServerConfig.tsx} +0 -0
- /package/plugin/{moduleRefs.ts → helpers/moduleRefs.ts} +0 -0
- /package/plugin/{vendor.client.ts → vendor/vendor.client.ts} +0 -0
- /package/plugin/{vendor.server.ts → vendor/vendor.server.ts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ViteDevServer } from "vite";
|
|
2
2
|
import type {
|
|
3
3
|
AutoDiscoveredFiles,
|
|
4
4
|
RenderMetrics,
|
|
@@ -6,75 +6,16 @@ import type {
|
|
|
6
6
|
ResolvedUserOptions,
|
|
7
7
|
StreamMetrics,
|
|
8
8
|
} from "../types.js";
|
|
9
|
-
import type
|
|
10
|
-
|
|
11
|
-
} from "../
|
|
12
|
-
import type { Worker as NodeWorker } from "node:worker_threads";
|
|
13
|
-
import { MessageChannel } from "node:worker_threads";
|
|
14
|
-
import {
|
|
15
|
-
serializedOptions,
|
|
16
|
-
} from "../helpers/serializeUserOptions.js";
|
|
17
|
-
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
18
|
-
import { requestToRoute } from "../helpers/requestToRoute.js";
|
|
9
|
+
import { MessageChannel, type Worker } from "node:worker_threads";
|
|
10
|
+
import { serializedOptions } from "../helpers/serializeUserOptions.js";
|
|
11
|
+
import { requestInfo } from "../helpers/requestInfo.js";
|
|
19
12
|
import { performance } from "node:perf_hooks";
|
|
20
|
-
import { createWorkerStream } from "./createWorkerStream.js";
|
|
21
13
|
import { restartWorker } from "./restartWorker.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @param worker - The worker thread
|
|
29
|
-
* @param message - The RSC render message
|
|
30
|
-
* @returns A ReadableStream that yields RSC chunks
|
|
31
|
-
*/
|
|
32
|
-
export function handleWorkerRscStream(
|
|
33
|
-
worker: NodeWorker,
|
|
34
|
-
message: Omit<RscRenderMessage, "type" | "id">,
|
|
35
|
-
logger: Logger,
|
|
36
|
-
onMetrics?: (metrics: StreamMetrics) => void
|
|
37
|
-
): ReadableStream<Uint8Array> {
|
|
38
|
-
// Create a ReadableStream from the async generator
|
|
39
|
-
return new ReadableStream<Uint8Array>({
|
|
40
|
-
async start(controller) {
|
|
41
|
-
try {
|
|
42
|
-
for await (const chunk of createWorkerStream(
|
|
43
|
-
worker,
|
|
44
|
-
message,
|
|
45
|
-
logger,
|
|
46
|
-
onMetrics
|
|
47
|
-
)) {
|
|
48
|
-
controller.enqueue(chunk);
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
const err =
|
|
52
|
-
error instanceof Error
|
|
53
|
-
? error
|
|
54
|
-
: typeof error === "string"
|
|
55
|
-
? new Error(error)
|
|
56
|
-
: typeof error === "object" && error != null
|
|
57
|
-
? {
|
|
58
|
-
message:
|
|
59
|
-
"message" in error ? String(error.message) : "Unknown error",
|
|
60
|
-
stack: "stack" in error ? String(error.stack) : "",
|
|
61
|
-
name: "name" in error ? String(error.name) : "Error",
|
|
62
|
-
}
|
|
63
|
-
: {
|
|
64
|
-
message: "Unknown error",
|
|
65
|
-
stack: "",
|
|
66
|
-
name: "Error",
|
|
67
|
-
};
|
|
68
|
-
logger.error(err.message, {
|
|
69
|
-
error: err,
|
|
70
|
-
});
|
|
71
|
-
controller.error(err);
|
|
72
|
-
} finally {
|
|
73
|
-
controller.close();
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
}
|
|
14
|
+
import { handleWorkerRscStream } from "./handleWorkerRscStream.js";
|
|
15
|
+
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
16
|
+
import type { RscWorkerInputMessage } from "../worker/types.js";
|
|
17
|
+
import { Readable } from "node:stream";
|
|
18
|
+
import { ReadableStream } from "node:stream/web";
|
|
78
19
|
|
|
79
20
|
/**
|
|
80
21
|
* Configures the worker request handler.
|
|
@@ -99,95 +40,77 @@ export async function configureWorkerRequestHandler({
|
|
|
99
40
|
// remove these
|
|
100
41
|
projectRoot: _projectRoot,
|
|
101
42
|
moduleBaseURL: _moduleBaseURL,
|
|
102
|
-
moduleBasePath: _moduleBasePath,
|
|
103
43
|
...handlerUserOptions
|
|
104
44
|
} = _userOptions;
|
|
105
45
|
const handlerOptions = Object.assign({}, handlerUserOptions, {
|
|
106
|
-
moduleBaseURL:
|
|
107
|
-
|
|
108
|
-
? `${server.config.server.https ? "https" : "http"}://${
|
|
109
|
-
server.config.server.host
|
|
110
|
-
}:${server.config.server.port}`
|
|
111
|
-
: _moduleBaseURL,
|
|
112
|
-
moduleBasePath:
|
|
113
|
-
server.config.base === "/"
|
|
114
|
-
? ""
|
|
115
|
-
: server.config.base.endsWith("/")
|
|
116
|
-
? server.config.base.slice(0, -1)
|
|
117
|
-
: server.config.base,
|
|
46
|
+
moduleBaseURL: server.config.base,
|
|
47
|
+
moduleBasePath: server.config.base,
|
|
118
48
|
projectRoot: server.config.root,
|
|
119
49
|
});
|
|
120
50
|
|
|
121
51
|
// Start the worker
|
|
122
|
-
|
|
52
|
+
let currentWorker: Worker | null = null;
|
|
53
|
+
const logger = server.config.logger;
|
|
54
|
+
|
|
55
|
+
// Handle server restarts
|
|
56
|
+
server.ws.on("restart", async () => {
|
|
57
|
+
logger.info("[react-client] Server restarting, shutting down worker...");
|
|
58
|
+
if (currentWorker) {
|
|
59
|
+
currentWorker.postMessage({
|
|
60
|
+
type: "SHUTDOWN",
|
|
61
|
+
id: "*",
|
|
62
|
+
} satisfies RscWorkerInputMessage);
|
|
63
|
+
await new Promise((resolve, reject) => {
|
|
64
|
+
currentWorker?.on("message", (message) => {
|
|
65
|
+
if (message.type === "SHUTDOWN_COMPLETE") {
|
|
66
|
+
resolve(true);
|
|
67
|
+
} else {
|
|
68
|
+
reject("Did not receive SHUTDOWN_COMPLETE");
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
currentWorker.removeAllListeners();
|
|
73
|
+
currentWorker = null;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
123
76
|
|
|
124
77
|
// Create the request handler
|
|
125
78
|
const handler: RequestHandler = async (req, res, next) => {
|
|
126
|
-
if (!req.url
|
|
127
|
-
|
|
128
|
-
if (!currentWorker) {
|
|
129
|
-
server.config.logger.error("[react-client] No worker available");
|
|
130
|
-
return next();
|
|
131
|
-
}
|
|
79
|
+
if (!req.url) return next();
|
|
80
|
+
if (handlerOptions.verbose) logger.info(`Received request: ${req.url}`);
|
|
132
81
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
if (!route) {
|
|
139
|
-
return next();
|
|
140
|
-
}
|
|
141
|
-
// in the case of the no build.pages and a async Page and or props userOption, we need to await those
|
|
142
|
-
// if they are already autoDiscovered then the promise will resolve immediately
|
|
143
|
-
const routeFiles = await getRouteFiles(
|
|
144
|
-
route,
|
|
145
|
-
autoDiscoveredFiles,
|
|
146
|
-
handlerOptions
|
|
147
|
-
);
|
|
148
|
-
if (routeFiles.type === "error") {
|
|
149
|
-
server.config.logger.error(
|
|
150
|
-
`[react-client] Error fetching route files for ${route}`,
|
|
151
|
-
{
|
|
152
|
-
error: routeFiles.error,
|
|
153
|
-
timestamp: true,
|
|
154
|
-
environment: "server",
|
|
155
|
-
}
|
|
156
|
-
);
|
|
157
|
-
return next();
|
|
158
|
-
}
|
|
159
|
-
const { page, props } = routeFiles;
|
|
82
|
+
const info = requestInfo(req, handlerOptions, "");
|
|
83
|
+
if (!info.isRscRequest) return next();
|
|
84
|
+
if (handlerOptions.verbose)
|
|
85
|
+
logger.info(`Request info: ${JSON.stringify(info)}`);
|
|
160
86
|
|
|
87
|
+
const routeFiles = await getRouteFiles(
|
|
88
|
+
info.route,
|
|
89
|
+
autoDiscoveredFiles,
|
|
90
|
+
handlerOptions
|
|
91
|
+
);
|
|
92
|
+
if (routeFiles.type === "error") {
|
|
93
|
+
logger.error(routeFiles.error.message);
|
|
94
|
+
return next();
|
|
95
|
+
}
|
|
96
|
+
const pagePath = routeFiles.page;
|
|
97
|
+
const propsPath = routeFiles.props;
|
|
98
|
+
try {
|
|
161
99
|
// Set up response headers for streaming
|
|
162
|
-
res.setHeader("Content-Type",
|
|
100
|
+
res.setHeader("Content-Type", info.contentType);
|
|
163
101
|
res.setHeader("Transfer-Encoding", "chunked");
|
|
164
102
|
res.setHeader("Connection", "keep-alive");
|
|
103
|
+
|
|
165
104
|
const serializedUserOptions = serializedOptions(
|
|
166
105
|
handlerOptions,
|
|
167
106
|
autoDiscoveredFiles
|
|
168
107
|
);
|
|
169
|
-
const
|
|
170
|
-
const stream = handleWorkerRscStream(
|
|
171
|
-
currentWorker,
|
|
172
|
-
{
|
|
173
|
-
...serializedUserOptions,
|
|
174
|
-
// we make the worker stream aware of the route, pagePath, propsPath
|
|
175
|
-
route,
|
|
176
|
-
pagePath: page,
|
|
177
|
-
propsPath: props,
|
|
178
|
-
// override these at all times to ensure the settings will work for the dev server
|
|
179
|
-
projectRoot: server.config.root,
|
|
180
|
-
build: serializedUserOptions.build,
|
|
181
|
-
manifest: autoDiscoveredFiles.staticManifest,
|
|
182
|
-
cssFiles: new Map(),
|
|
183
|
-
globalCss: new Map(),
|
|
184
|
-
},
|
|
185
|
-
server.config.logger,
|
|
108
|
+
const userOnMetrics =
|
|
186
109
|
typeof onMetrics === "function"
|
|
187
|
-
? (metrics) => {
|
|
110
|
+
? (metrics: StreamMetrics) => {
|
|
188
111
|
const elapsedTime = performance.now() - startTime;
|
|
189
112
|
const formattedMetrics = {
|
|
190
|
-
route,
|
|
113
|
+
route: info.route,
|
|
191
114
|
htmlSize: 0,
|
|
192
115
|
rscSize: metrics.bytes,
|
|
193
116
|
processingTime: elapsedTime,
|
|
@@ -196,52 +119,94 @@ export async function configureWorkerRequestHandler({
|
|
|
196
119
|
memoryUsage: process.memoryUsage(),
|
|
197
120
|
streamMetrics: {
|
|
198
121
|
...metrics,
|
|
199
|
-
duration: elapsedTime
|
|
122
|
+
duration: elapsedTime,
|
|
200
123
|
},
|
|
201
124
|
htmlSizes: new Map(),
|
|
202
|
-
rscSizes: new Map([[route, metrics.bytes]]),
|
|
125
|
+
rscSizes: new Map([[info.route, metrics.bytes]]),
|
|
203
126
|
} satisfies RenderMetrics;
|
|
204
127
|
onMetrics(formattedMetrics);
|
|
205
128
|
}
|
|
206
|
-
:
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
129
|
+
: () => {};
|
|
130
|
+
const startTime = performance.now();
|
|
131
|
+
if (!currentWorker) {
|
|
132
|
+
currentWorker = await restartWorker({
|
|
133
|
+
server,
|
|
134
|
+
autoDiscoveredFiles,
|
|
135
|
+
userOptions: serializedUserOptions,
|
|
136
|
+
hmrChannel,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const stream = handleWorkerRscStream({
|
|
140
|
+
worker: currentWorker!,
|
|
141
|
+
message: {
|
|
142
|
+
...serializedUserOptions,
|
|
143
|
+
// we make the worker stream aware of the route, pagePath, propsPath
|
|
144
|
+
route: info.route,
|
|
145
|
+
pagePath: pagePath,
|
|
146
|
+
propsPath: propsPath,
|
|
147
|
+
// override these at all times to ensure the settings will work for the dev server
|
|
148
|
+
projectRoot: server.config.root,
|
|
149
|
+
build: serializedUserOptions.build,
|
|
150
|
+
manifest: autoDiscoveredFiles.staticManifest,
|
|
151
|
+
cssFiles: new Map(),
|
|
152
|
+
globalCss: new Map(),
|
|
216
153
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
154
|
+
logger,
|
|
155
|
+
handlers: {
|
|
156
|
+
onMetrics: userOnMetrics,
|
|
157
|
+
onHmrAccept: () => {
|
|
158
|
+
// TODO: implement
|
|
159
|
+
// console.log("onHmrAccept", routes);
|
|
160
|
+
},
|
|
161
|
+
onHmrUpdate: () => {
|
|
162
|
+
// TODO: implement
|
|
163
|
+
// console.log("onHmrUpdate", routes);
|
|
164
|
+
},
|
|
227
165
|
},
|
|
166
|
+
verbose: handlerOptions.verbose,
|
|
228
167
|
});
|
|
229
|
-
let timeout: NodeJS.Timeout;
|
|
230
168
|
|
|
231
169
|
// Pipe the stream to the response
|
|
232
|
-
|
|
170
|
+
if (res.writable) {
|
|
171
|
+
Readable.fromWeb(stream as unknown as ReadableStream).pipe(res);
|
|
172
|
+
}
|
|
233
173
|
// wait for timeout
|
|
234
|
-
timeout = setTimeout(() => {
|
|
235
|
-
server.config.logger.error("RSC render timeout");
|
|
236
|
-
res.end();
|
|
237
|
-
}, 5000);
|
|
238
174
|
} catch (error) {
|
|
239
175
|
if (error instanceof Error) {
|
|
240
|
-
server.config.logger.error(error.message, {
|
|
176
|
+
server.config.logger.error(error.message + (error.stack ?? ""), {
|
|
241
177
|
error,
|
|
242
178
|
});
|
|
243
179
|
}
|
|
244
180
|
}
|
|
181
|
+
let timeout: NodeJS.Timeout;
|
|
182
|
+
try {
|
|
183
|
+
await new Promise((reject) => {
|
|
184
|
+
timeout = setTimeout(() => {
|
|
185
|
+
clearTimeout(timeout);
|
|
186
|
+
reject(new Error("RSC Render timeout"));
|
|
187
|
+
}, 5000);
|
|
188
|
+
});
|
|
189
|
+
} catch {
|
|
190
|
+
if (currentWorker) {
|
|
191
|
+
currentWorker.postMessage({
|
|
192
|
+
type: "SHUTDOWN",
|
|
193
|
+
id: "*",
|
|
194
|
+
} satisfies RscWorkerInputMessage);
|
|
195
|
+
await new Promise((resolve, reject) => {
|
|
196
|
+
currentWorker?.on("message", (message) => {
|
|
197
|
+
if (message.type === "SHUTDOWN_COMPLETE") {
|
|
198
|
+
resolve(true);
|
|
199
|
+
} else {
|
|
200
|
+
reject("Dit not receive SHUTDOWN_COMPLETE");
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
currentWorker.removeAllListeners();
|
|
205
|
+
}
|
|
206
|
+
server.config.logger.error("RSC render timeout.");
|
|
207
|
+
clearTimeout(timeout!);
|
|
208
|
+
res.end();
|
|
209
|
+
}
|
|
245
210
|
};
|
|
246
211
|
// attach handler to the server
|
|
247
212
|
server.middlewares.use(handler);
|
|
@@ -17,14 +17,13 @@ import type {
|
|
|
17
17
|
import { type StreamPluginOptions } from "../types.js";
|
|
18
18
|
import {
|
|
19
19
|
resolveAutoDiscover
|
|
20
|
-
} from "../config/resolveAutoDiscover.js";
|
|
20
|
+
} from "../config/autoDiscover/resolveAutoDiscover.js";
|
|
21
21
|
import { getCondition } from "../config/getCondition.js";
|
|
22
22
|
import { configureReactServer } from "./server.js";
|
|
23
23
|
import { configurePreviewServer } from "../react-static/configurePreviewServer.js";
|
|
24
24
|
import { getBundleManifest } from "../helpers/getBundleManifest.js";
|
|
25
25
|
|
|
26
26
|
let resolvedConfig: ResolvedConfig | null = null;
|
|
27
|
-
let cwd: string;
|
|
28
27
|
|
|
29
28
|
if (getCondition() !== "react-server") {
|
|
30
29
|
throw new Error(
|
|
@@ -48,25 +47,27 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
48
47
|
throw resolvedOptions.error;
|
|
49
48
|
}
|
|
50
49
|
userOptions = resolvedOptions.userOptions;
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
userOptions.projectRoot != cwd &&
|
|
54
|
-
typeof userOptions.projectRoot === "string" &&
|
|
55
|
-
userOptions.projectRoot !== ""
|
|
56
|
-
) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"[RSC] Project root is not the current working directory, please set projectRoot in your config"
|
|
59
|
-
);
|
|
60
|
-
}
|
|
50
|
+
|
|
61
51
|
|
|
62
52
|
return {
|
|
63
53
|
name: "vite:react-stream-server",
|
|
64
54
|
enforce: "post",
|
|
65
55
|
api: {
|
|
66
56
|
meta: { timing },
|
|
67
|
-
},
|
|
57
|
+
},
|
|
68
58
|
configResolved(_resolvedConfig) {
|
|
69
59
|
resolvedConfig = _resolvedConfig;
|
|
60
|
+
if (
|
|
61
|
+
userOptions.projectRoot != resolvedConfig.root &&
|
|
62
|
+
typeof userOptions.projectRoot === "string" &&
|
|
63
|
+
userOptions.projectRoot !== ""
|
|
64
|
+
) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
"[RSC] Project root is not the current working directory, please set projectRoot in your config.\n" +
|
|
67
|
+
" projectRoot: " + userOptions.projectRoot + "\n" +
|
|
68
|
+
" resolvedConfig.root: " + resolvedConfig.root
|
|
69
|
+
);
|
|
70
|
+
}
|
|
70
71
|
timing.configResolved = performance.now();
|
|
71
72
|
|
|
72
73
|
// Verify transformer runs first, preserver runs last
|
|
@@ -132,6 +133,18 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
132
133
|
|
|
133
134
|
return resolvedConfig.userConfig;
|
|
134
135
|
},
|
|
136
|
+
async writeBundle(options, bundle) {
|
|
137
|
+
if (userOptions.onEvent) {
|
|
138
|
+
userOptions.onEvent({
|
|
139
|
+
type: "build.writeBundle.server",
|
|
140
|
+
data: {
|
|
141
|
+
pages: Array.from(autoDiscoveredFiles?.urlMap.keys() ?? []),
|
|
142
|
+
options,
|
|
143
|
+
bundle,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
},
|
|
135
148
|
async buildStart() {
|
|
136
149
|
if (!timing.buildStart) {
|
|
137
150
|
timing.buildStart = performance.now();
|
|
@@ -6,6 +6,9 @@ import { collectViteModuleGraphCss } from "../helpers/collectViteModuleGraphCss.
|
|
|
6
6
|
import { resolvePageAndProps } from "../helpers/resolvePageAndProps.js";
|
|
7
7
|
import { createHandler } from "../helpers/createHandler.js";
|
|
8
8
|
import React from "react";
|
|
9
|
+
import { requestInfo } from "../helpers/requestInfo.js";
|
|
10
|
+
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
11
|
+
import { toError } from "../error/toError.js";
|
|
9
12
|
|
|
10
13
|
export async function configureReactServer({
|
|
11
14
|
server,
|
|
@@ -19,32 +22,19 @@ export async function configureReactServer({
|
|
|
19
22
|
serverManifest: Manifest;
|
|
20
23
|
}) {
|
|
21
24
|
const activeStreams = new Set<ServerResponse>();
|
|
22
|
-
|
|
23
25
|
const {
|
|
24
26
|
Html: _UserHtmlComponent,
|
|
25
27
|
onEvent,
|
|
26
28
|
// remove these
|
|
27
29
|
moduleBaseURL: _moduleBaseURL,
|
|
28
|
-
moduleBasePath: _moduleBasePath,
|
|
29
30
|
projectRoot: _projectRoot,
|
|
30
31
|
...handlerUserOptions
|
|
31
32
|
} = _userOptions;
|
|
32
|
-
|
|
33
33
|
const handlerOptions = Object.assign({}, handlerUserOptions, {
|
|
34
|
-
moduleBaseURL:
|
|
35
|
-
typeof server.config.server.host === "string"
|
|
36
|
-
? `${server.config.server.https ? "https" : "http"}://${
|
|
37
|
-
server.config.server.host
|
|
38
|
-
}:${server.config.server.port}`
|
|
39
|
-
: _moduleBaseURL,
|
|
40
|
-
moduleBasePath:
|
|
41
|
-
server.config.base === "/"
|
|
42
|
-
? ""
|
|
43
|
-
: server.config.base.endsWith("/")
|
|
44
|
-
? server.config.base.slice(0, -1)
|
|
45
|
-
: server.config.base,
|
|
34
|
+
moduleBaseURL: server.config.base,
|
|
46
35
|
projectRoot: server.config.root,
|
|
47
36
|
});
|
|
37
|
+
|
|
48
38
|
// Handle Vite server restarts
|
|
49
39
|
server.ws.on("restart", (path) => {
|
|
50
40
|
server.config.logger.info(
|
|
@@ -55,33 +45,32 @@ export async function configureReactServer({
|
|
|
55
45
|
// Close streams with restart message
|
|
56
46
|
for (const res of activeStreams) {
|
|
57
47
|
res.writeHead(503, {
|
|
58
|
-
"Content-Type": "text/x-component",
|
|
48
|
+
"Content-Type": "text/x-component; charset=utf-8",
|
|
59
49
|
"Retry-After": "1",
|
|
60
50
|
});
|
|
61
|
-
res.end(
|
|
51
|
+
res.end(
|
|
52
|
+
`0:E{"digest":"","name":"Error","message":"Server restarting...","stack":"","env":"Server"}`
|
|
53
|
+
);
|
|
62
54
|
}
|
|
63
55
|
activeStreams.clear();
|
|
64
56
|
});
|
|
65
57
|
|
|
66
58
|
server.middlewares.use(async (req, res, next) => {
|
|
59
|
+
if (!req.url) {
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
const info = requestInfo(req, handlerOptions, "");
|
|
63
|
+
if (!info.isRscRequest) return next();
|
|
67
64
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!route || route === "") {
|
|
76
|
-
route = "/";
|
|
77
|
-
}
|
|
78
|
-
if(!route.startsWith("/")) {
|
|
79
|
-
route = "/" + route;
|
|
80
|
-
}
|
|
81
|
-
if (!autoDiscoveredFiles.urlMap.has(route)) {
|
|
65
|
+
const routeFiles = await getRouteFiles(
|
|
66
|
+
info.route,
|
|
67
|
+
autoDiscoveredFiles,
|
|
68
|
+
handlerOptions
|
|
69
|
+
);
|
|
70
|
+
if (routeFiles.type === "error") {
|
|
71
|
+
server.config.logger.error(routeFiles.error.message);
|
|
82
72
|
return next();
|
|
83
73
|
}
|
|
84
|
-
const routeFiles = autoDiscoveredFiles.urlMap.get(route)!;
|
|
85
74
|
const pagePath = routeFiles.page;
|
|
86
75
|
const propsPath = routeFiles.props;
|
|
87
76
|
|
|
@@ -89,7 +78,7 @@ export async function configureReactServer({
|
|
|
89
78
|
const pageAndPropsResult = await resolvePageAndProps({
|
|
90
79
|
pagePath,
|
|
91
80
|
propsPath,
|
|
92
|
-
route,
|
|
81
|
+
route: info.route,
|
|
93
82
|
loader: server.ssrLoadModule,
|
|
94
83
|
pageExportName: handlerOptions.pageExportName ?? "default",
|
|
95
84
|
propsExportName: handlerOptions.propsExportName ?? "default",
|
|
@@ -129,14 +118,16 @@ export async function configureReactServer({
|
|
|
129
118
|
Html: React.Fragment,
|
|
130
119
|
onEvent: eventHandler,
|
|
131
120
|
manifest: serverManifest,
|
|
132
|
-
|
|
133
|
-
route,
|
|
121
|
+
server,
|
|
122
|
+
route: info.route,
|
|
134
123
|
pagePath,
|
|
135
124
|
propsPath,
|
|
136
125
|
cssFiles: cssFilesResult.cssFiles ?? new Map(),
|
|
137
126
|
globalCss: new Map(),
|
|
138
127
|
});
|
|
139
128
|
if (rscResult.type === "success") {
|
|
129
|
+
// set headers
|
|
130
|
+
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
140
131
|
rscResult.stream!.pipe(res);
|
|
141
132
|
}
|
|
142
133
|
activeStreams.add(res);
|
|
@@ -144,7 +135,21 @@ export async function configureReactServer({
|
|
|
144
135
|
activeStreams.delete(res);
|
|
145
136
|
});
|
|
146
137
|
} catch (error) {
|
|
138
|
+
server.config.logger.error(toError(error).message);
|
|
147
139
|
res.end();
|
|
148
140
|
}
|
|
149
141
|
});
|
|
142
|
+
// Listen for when the server actually starts
|
|
143
|
+
server.httpServer?.once("listening", () => {
|
|
144
|
+
const address = server.httpServer?.address();
|
|
145
|
+
if (address && typeof address !== "string") {
|
|
146
|
+
const port = address.port;
|
|
147
|
+
const host = server.config.server.host ?? "localhost";
|
|
148
|
+
const protocol = server.config.server.https ? "https" : "http";
|
|
149
|
+
handlerOptions.publicOrigin = `${protocol}://${host}:${port}`;
|
|
150
|
+
if (handlerOptions.publicOrigin !== process.env.VITE_PUBLIC_ORIGIN) {
|
|
151
|
+
process.env.VITE_PUBLIC_ORIGIN = handlerOptions.publicOrigin;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
150
155
|
}
|
|
@@ -25,6 +25,9 @@ export async function collectHtmlWorkerContent(
|
|
|
25
25
|
rscStream: PassThrough,
|
|
26
26
|
handlerOptions: CreateHandlerOptions
|
|
27
27
|
): Promise<{ stream: PassThrough; metrics: StreamMetrics }> {
|
|
28
|
+
if (!handlerOptions.worker) {
|
|
29
|
+
throw new Error("Worker is not a valid worker");
|
|
30
|
+
}
|
|
28
31
|
const metrics = createStreamMetrics();
|
|
29
32
|
const startTime = performance.now();
|
|
30
33
|
|
|
@@ -56,7 +59,13 @@ export async function collectHtmlWorkerContent(
|
|
|
56
59
|
|
|
57
60
|
// Create a promise that resolves when the route is complete
|
|
58
61
|
const routeComplete = new Promise<void>((resolve, reject) => {
|
|
62
|
+
if (!handlerOptions.worker) {
|
|
63
|
+
throw new Error("Worker is not a valid worker");
|
|
64
|
+
}
|
|
59
65
|
const messageHandler = (msg: any) => {
|
|
66
|
+
if (!handlerOptions.worker) {
|
|
67
|
+
throw new Error("Worker is not a valid worker");
|
|
68
|
+
}
|
|
60
69
|
switch (msg.type) {
|
|
61
70
|
case "HTML_CHUNK":
|
|
62
71
|
if (!isComplete) {
|
|
@@ -90,7 +99,10 @@ export async function collectHtmlWorkerContent(
|
|
|
90
99
|
if (handlerOptions.onEvent) {
|
|
91
100
|
const originalOnEvent = handlerOptions.onEvent;
|
|
92
101
|
handlerOptions.onEvent = (event) => {
|
|
93
|
-
if (
|
|
102
|
+
if (
|
|
103
|
+
event.type === "file.write.done" &&
|
|
104
|
+
event.data.fileType === "html"
|
|
105
|
+
) {
|
|
94
106
|
metrics.bytes = event.data.content.length;
|
|
95
107
|
}
|
|
96
108
|
originalOnEvent(event);
|