vite-plugin-react-server 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -76
- package/bin/patch.mjs +27 -20
- package/dist/_virtual/dynamic-import-helper.js +24 -0
- package/dist/_virtual/dynamic-import-helper.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/package.json +24 -14
- package/dist/plugin/components.d.ts +1 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +18 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +42 -21
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getCondition.d.ts +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +2 -2
- package/dist/plugin/config/getCondition.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/index.d.ts +0 -1
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscover.js +128 -0
- package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +109 -77
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +0 -1
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +6 -8
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
- package/dist/plugin/config/resolveUrlOption.js +37 -0
- package/dist/plugin/config/resolveUrlOption.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -132
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy.d.ts +7 -0
- package/dist/plugin/copy.d.ts.map +1 -0
- package/dist/plugin/copy.js +30 -0
- package/dist/plugin/css-collector-elements.d.ts +4 -0
- package/dist/plugin/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/css-collector-elements.js +19 -0
- package/dist/plugin/css-collector-elements.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +2 -8
- package/dist/plugin/css-collector.d.ts.map +1 -1
- package/dist/plugin/css-collector.js +9 -36
- package/dist/plugin/css-collector.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts +3 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
- package/dist/plugin/helpers/cleanObject.js +47 -0
- package/dist/plugin/helpers/cleanObject.js.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js +44 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
- package/dist/plugin/helpers/createCssProps.d.ts +25 -0
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
- package/dist/plugin/helpers/createCssProps.js +57 -0
- package/dist/plugin/helpers/createCssProps.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createEventHandler.js +36 -0
- package/dist/plugin/helpers/createEventHandler.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +7 -13
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +54 -96
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +12 -26
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +105 -51
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
- package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
- package/dist/plugin/helpers/defaultFileWriter.js +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +30 -22
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.js +36 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +38 -32
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.d.ts +11 -0
- package/dist/plugin/helpers/metrics.d.ts.map +1 -0
- package/dist/plugin/helpers/metrics.js +35 -0
- package/dist/plugin/helpers/metrics.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +182 -0
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.js +14 -0
- package/dist/plugin/helpers/tryManifest.d.ts +5 -3
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +16 -7
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +2 -3
- package/dist/plugin/html.d.ts.map +1 -1
- package/dist/plugin/html.js +7 -1
- package/dist/plugin/html.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +98 -33
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts +57 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.development.js +81 -0
- package/dist/plugin/loader/css-loader.development.js.map +1 -0
- package/dist/plugin/loader/css-loader.production.d.ts +31 -0
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.production.js +45 -0
- package/dist/plugin/loader/css-loader.production.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +2 -0
- package/dist/plugin/loader/index.d.ts.map +1 -0
- package/dist/plugin/loader/index.js +1 -0
- package/dist/plugin/loader/plugin.d.ts +22 -0
- package/dist/plugin/loader/plugin.d.ts.map +1 -0
- package/dist/plugin/loader/plugin.js +27 -0
- package/dist/plugin/loader/react-loader.d.ts +3 -7
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +85 -30
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/loader/temporaryReferences.js +11 -0
- package/dist/plugin/loader/temporaryReferences.js.map +1 -0
- package/dist/plugin/moduleRefs.d.ts +7 -0
- package/dist/plugin/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/moduleRefs.js +17 -0
- package/dist/plugin/moduleRefs.js.map +1 -0
- package/dist/plugin/plugin.client.d.ts +3 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -0
- package/dist/plugin/plugin.client.js +19 -0
- package/dist/plugin/plugin.client.js.map +1 -0
- package/dist/plugin/plugin.d.ts +1 -5
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +3 -9
- package/dist/plugin/plugin.server.d.ts +3 -0
- package/dist/plugin/plugin.server.d.ts.map +1 -0
- package/dist/plugin/plugin.server.js +28 -0
- package/dist/plugin/plugin.server.js.map +1 -0
- package/dist/plugin/preserver/plugin.js +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +1 -2
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +1 -19
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +60 -219
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +27 -0
- package/dist/plugin/react-client/server.d.ts.map +1 -0
- package/dist/plugin/react-client/server.js +197 -0
- package/dist/plugin/react-client/server.js.map +1 -0
- package/dist/plugin/react-server/index.d.ts +1 -2
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +1 -21
- package/dist/plugin/react-server/plugin.d.ts +0 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +60 -186
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts +9 -0
- package/dist/plugin/react-server/server.d.ts.map +1 -0
- package/dist/plugin/react-server/server.js +120 -0
- package/dist/plugin/react-server/server.js.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
- package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectRscContent.js +49 -0
- package/dist/plugin/react-static/collectRscContent.js.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.js +67 -0
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
- package/dist/plugin/react-static/fileWriter.d.ts +23 -0
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
- package/dist/plugin/react-static/fileWriter.js +65 -0
- package/dist/plugin/react-static/fileWriter.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts +15 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +248 -149
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +3 -0
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPage.js +116 -0
- package/dist/plugin/react-static/renderPage.js.map +1 -0
- package/dist/plugin/react-static/renderPages.d.ts +3 -0
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPages.js +125 -0
- package/dist/plugin/react-static/renderPages.js.map +1 -0
- package/dist/plugin/react-static/renderStreams.d.ts +26 -0
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
- package/dist/plugin/react-static/renderStreams.js +27 -0
- package/dist/plugin/react-static/renderStreams.js.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
- package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
- package/dist/plugin/react-static/streamHandler.d.ts +2 -0
- package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
- package/dist/plugin/react-static/streamHandler.js +1 -0
- package/dist/plugin/react-static/types.d.ts +11 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/resolvePage.d.ts +26 -9
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +41 -39
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts +40 -7
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +100 -75
- package/dist/plugin/resolveProps.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 +1 -0
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/index.d.ts +2 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +2 -1
- package/dist/plugin/transformer/plugin.client.d.ts +4 -0
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.client.js +83 -0
- package/dist/plugin/transformer/plugin.client.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts +1 -27
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +3 -87
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +4 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +76 -0
- package/dist/plugin/transformer/plugin.server.js.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
- package/dist/plugin/types/css-tracking.d.ts +6 -0
- package/dist/plugin/types/css-tracking.d.ts.map +1 -0
- package/dist/plugin/types/css-tracking.js +1 -0
- package/dist/plugin/types.d.ts +372 -86
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/vendor.client.d.ts +4 -0
- package/dist/plugin/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor.client.js +16 -0
- package/dist/plugin/vendor.client.js.map +1 -0
- package/dist/plugin/vendor.server.d.ts +4 -0
- package/dist/plugin/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor.server.js +16 -0
- package/dist/plugin/vendor.server.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +25 -7
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +108 -33
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +3 -17
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +12 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +87 -84
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/types.d.ts +18 -0
- package/dist/plugin/worker/html/types.d.ts.map +1 -0
- package/dist/plugin/worker/html/types.js +1 -0
- package/dist/plugin/worker/registerLoaders.d.ts +9 -0
- package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
- package/dist/plugin/worker/registerLoaders.js +45 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handleRender.js +147 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +47 -112
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +73 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +40 -3
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +3 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
- package/dist/plugin/worker/sendMessage.js +48 -0
- package/dist/plugin/worker/types.d.ts +218 -76
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/plugin/components.ts +1 -1
- package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
- package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
- package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
- package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
- package/plugin/config/defaults.tsx +38 -29
- package/plugin/config/getCondition.ts +7 -3
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/index.ts +0 -1
- package/plugin/config/resolveAutoDiscover.ts +177 -0
- package/plugin/config/resolveOptions.ts +220 -118
- package/plugin/config/resolvePages.ts +5 -7
- package/plugin/config/resolveUrlOption.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +116 -166
- package/plugin/copy.ts +39 -0
- package/plugin/css-collector-elements.tsx +21 -0
- package/plugin/css-collector.tsx +20 -53
- package/plugin/helpers/cleanObject.ts +50 -0
- package/plugin/helpers/collectBundleManifestCss.ts +160 -0
- package/plugin/helpers/collectManifestCss.ts +61 -0
- package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
- package/plugin/helpers/createCssProps.tsx +85 -0
- package/plugin/helpers/createEventHandler.ts +44 -0
- package/plugin/helpers/createHandler.ts +57 -126
- package/plugin/helpers/createRscStream.tsx +156 -0
- package/plugin/helpers/defaultFileWriter.ts +0 -0
- package/plugin/helpers/getBundleManifest.ts +42 -37
- package/plugin/helpers/getRouteFiles.ts +47 -0
- package/plugin/helpers/inputNormalizer.ts +16 -10
- package/plugin/helpers/metrics.ts +64 -0
- package/plugin/helpers/resolvePageAndProps.ts +81 -0
- package/plugin/helpers/serializeUserOptions.ts +209 -0
- package/plugin/helpers/stashReturnValue.ts +16 -0
- package/plugin/helpers/tryManifest.ts +35 -18
- package/plugin/html.tsx +14 -3
- package/plugin/index.ts +5 -2
- package/plugin/loader/createBuildLoader.ts +152 -47
- package/plugin/loader/css-loader.development.ts +157 -0
- package/plugin/loader/css-loader.production.ts +86 -0
- package/plugin/loader/index.ts +1 -0
- package/plugin/loader/plugin.ts +33 -0
- package/plugin/loader/react-loader.ts +109 -41
- package/plugin/loader/temporaryReferences.ts +3 -0
- package/plugin/moduleRefs.ts +11 -0
- package/plugin/plugin.client.ts +12 -0
- package/plugin/plugin.server.ts +25 -0
- package/plugin/plugin.ts +5 -9
- package/plugin/preserver/plugin.ts +1 -1
- package/plugin/react-client/index.ts +1 -12
- package/plugin/react-client/plugin.ts +70 -259
- package/plugin/react-client/server.ts +276 -0
- package/plugin/react-server/index.ts +1 -14
- package/plugin/react-server/plugin.ts +69 -220
- package/plugin/react-server/server.ts +128 -0
- package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
- package/plugin/react-static/collectRscContent.ts +77 -0
- package/plugin/react-static/configurePreviewServer.ts +68 -0
- package/plugin/react-static/fileWriter.ts +103 -0
- package/plugin/react-static/plugin.ts +308 -181
- package/plugin/react-static/renderPage.ts +151 -0
- package/plugin/react-static/renderPages.ts +154 -0
- package/plugin/react-static/renderStreams.ts +48 -0
- package/plugin/react-static/rscToHtmlStream.ts +85 -0
- package/plugin/react-static/streamHandler.ts +0 -0
- package/plugin/react-static/types.ts +10 -0
- package/plugin/resolvePage.ts +67 -57
- package/plugin/resolveProps.ts +148 -104
- package/plugin/root.ts +1 -1
- package/plugin/transformer/index.ts +2 -1
- package/plugin/transformer/plugin.client.ts +109 -0
- package/plugin/transformer/plugin.server.ts +98 -0
- package/plugin/transformer/plugin.ts +2 -115
- package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
- package/plugin/types/css-tracking.ts +5 -0
- package/plugin/types/react-server-dom-esm.d.ts +54 -0
- package/plugin/types.ts +508 -97
- package/plugin/vendor.client.ts +12 -0
- package/plugin/vendor.server.ts +12 -0
- package/plugin/worker/createWorker.ts +158 -53
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
- package/plugin/worker/html/html-worker.development.tsx +5 -75
- package/plugin/worker/html/html-worker.production.tsx +18 -7
- package/plugin/worker/html/messageHandler.tsx +126 -0
- package/plugin/worker/html/types.ts +19 -0
- package/plugin/worker/registerLoaders.ts +54 -0
- package/plugin/worker/rsc/handleRender.ts +180 -0
- package/plugin/worker/rsc/messageHandler.tsx +58 -132
- package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
- package/plugin/worker/rsc/state.ts +79 -2
- package/plugin/worker/sendMessage.ts +49 -0
- package/plugin/worker/types.ts +299 -100
- package/scripts/check-react-version.mjs +60 -48
- package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
- package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
- package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
- package/tsconfig.json +7 -2
- package/dist/plugin/assertServerCondition.d.ts +0 -6
- package/dist/plugin/assertServerCondition.d.ts.map +0 -1
- package/dist/plugin/assertServerCondition.js +0 -13
- package/dist/plugin/checkFilesExist.d.ts +0 -3
- package/dist/plugin/checkFilesExist.d.ts.map +0 -1
- package/dist/plugin/checkFilesExist.js +0 -67
- package/dist/plugin/checkFilesExist.js.map +0 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
- package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
- package/dist/plugin/collect-manifest-client-files.js +0 -131
- package/dist/plugin/collect-manifest-client-files.js.map +0 -1
- package/dist/plugin/config/getWorkerPath.d.ts +0 -2
- package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
- package/dist/plugin/config/getWorkerPath.js +0 -4
- package/dist/plugin/copy-dir.d.ts +0 -4
- package/dist/plugin/copy-dir.d.ts.map +0 -1
- package/dist/plugin/copy-dir.js +0 -25
- package/dist/plugin/copy-dir.js.map +0 -1
- package/dist/plugin/css-collector-inline.d.ts +0 -10
- package/dist/plugin/css-collector-inline.d.ts.map +0 -1
- package/dist/plugin/css-collector-inline.js +0 -55
- package/dist/plugin/css-collector-inline.js.map +0 -1
- package/dist/plugin/loader/css-loader.d.ts +0 -16
- package/dist/plugin/loader/css-loader.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.js +0 -70
- package/dist/plugin/loader/css-loader.js.map +0 -1
- package/dist/plugin/react-client/index.js.map +0 -1
- package/dist/plugin/react-server/index.js.map +0 -1
- package/dist/plugin/worker/html/renderPages.d.ts +0 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
- package/dist/plugin/worker/html/renderPages.js +0 -241
- package/dist/plugin/worker/html/renderPages.js.map +0 -1
- package/plugin/assertServerCondition.ts +0 -12
- package/plugin/checkFilesExist.ts +0 -66
- package/plugin/collect-manifest-client-files.ts +0 -167
- package/plugin/config/getWorkerPath.ts +0 -5
- package/plugin/copy-dir.ts +0 -27
- package/plugin/css-collector-inline.tsx +0 -60
- package/plugin/helpers/createRscStream.ts +0 -109
- package/plugin/loader/css-loader.ts +0 -94
- package/plugin/worker/html/messageHandler.ts +0 -130
- package/plugin/worker/html/renderPages.ts +0 -293
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
|
@@ -1,74 +1,61 @@
|
|
|
1
|
-
import { join, dirname } from "node:path";
|
|
2
1
|
import { performance } from "node:perf_hooks";
|
|
3
|
-
import React from "react";
|
|
4
2
|
import {
|
|
5
|
-
createLogger,
|
|
6
3
|
type ResolvedConfig,
|
|
7
4
|
type UserConfig,
|
|
8
5
|
type ViteDevServer,
|
|
9
6
|
type Manifest,
|
|
10
7
|
type Plugin as VitePlugin,
|
|
11
8
|
} from "vite";
|
|
12
|
-
import { checkFilesExist } from "../checkFilesExist.js";
|
|
13
9
|
import { resolveOptions } from "../config/resolveOptions.js";
|
|
14
|
-
import { resolvePages } from "../config/resolvePages.js";
|
|
15
10
|
import { resolveUserConfig } from "../config/resolveUserConfig.js";
|
|
16
11
|
import type {
|
|
12
|
+
AutoDiscoveredFiles,
|
|
17
13
|
BuildTiming,
|
|
18
|
-
CheckFilesExistReturn,
|
|
19
|
-
CssContent,
|
|
20
14
|
ReactStreamPluginMeta,
|
|
21
15
|
ResolvedUserOptions,
|
|
22
16
|
} from "../types.js";
|
|
23
17
|
import { type StreamPluginOptions } from "../types.js";
|
|
24
|
-
import {
|
|
25
|
-
|
|
18
|
+
import {
|
|
19
|
+
resolveAutoDiscover
|
|
20
|
+
} from "../config/resolveAutoDiscover.js";
|
|
21
|
+
import { getCondition } from "../config/getCondition.js";
|
|
22
|
+
import { configureReactServer } from "./server.js";
|
|
23
|
+
import { configurePreviewServer } from "../react-static/configurePreviewServer.js";
|
|
26
24
|
import { getBundleManifest } from "../helpers/getBundleManifest.js";
|
|
27
|
-
import type { ServerResponse } from "node:http";
|
|
28
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
29
|
-
import { MIME_TYPES } from "../config/mimeTypes.js";
|
|
30
|
-
import { InlineCssCollector } from "../css-collector-inline.js";
|
|
31
|
-
import { CssCollector } from "../css-collector.js";
|
|
32
|
-
import { collectModuleGraphCss } from "../collect-manifest-client-files.js";
|
|
33
25
|
|
|
34
26
|
let resolvedConfig: ResolvedConfig | null = null;
|
|
35
|
-
let
|
|
36
|
-
let loader: ((id: string) => Promise<Record<string, any>>) | null = null;
|
|
27
|
+
let cwd: string;
|
|
37
28
|
|
|
29
|
+
if (getCondition() !== "react-server") {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"Condition mismatch, should be react-server but got " +
|
|
32
|
+
process.env["NODE_OPTIONS"]
|
|
33
|
+
);
|
|
34
|
+
}
|
|
38
35
|
export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
39
36
|
meta: ReactStreamPluginMeta;
|
|
40
|
-
addCssFile: (path: string) => void;
|
|
41
37
|
}> {
|
|
42
38
|
const timing: BuildTiming = {
|
|
43
39
|
start: performance.now(),
|
|
44
40
|
};
|
|
45
41
|
|
|
46
|
-
let
|
|
47
|
-
// let env: Awaited<ReturnType<typeof getEnv>>;
|
|
48
|
-
let cssModules = new Set<string>();
|
|
49
|
-
// let define: Record<string, string>;
|
|
50
|
-
let buildCssFiles = new Set<string>();
|
|
51
|
-
let root: string = process.cwd();
|
|
42
|
+
let autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
52
43
|
let userOptions: ResolvedUserOptions;
|
|
53
|
-
let resolvedPages: string[];
|
|
54
44
|
let serverManifest: Manifest = {};
|
|
55
45
|
|
|
56
|
-
const resolvedOptions = resolveOptions(options
|
|
46
|
+
const resolvedOptions = resolveOptions(options);
|
|
57
47
|
if (resolvedOptions.type === "error") {
|
|
58
48
|
throw resolvedOptions.error;
|
|
59
49
|
}
|
|
60
50
|
userOptions = resolvedOptions.userOptions;
|
|
51
|
+
cwd = process.cwd();
|
|
61
52
|
if (
|
|
62
|
-
userOptions.projectRoot !=
|
|
53
|
+
userOptions.projectRoot != cwd &&
|
|
63
54
|
typeof userOptions.projectRoot === "string" &&
|
|
64
|
-
userOptions.projectRoot !== process.cwd() &&
|
|
65
55
|
userOptions.projectRoot !== ""
|
|
66
56
|
) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"[vite:plugin-react-server] Root dir changed in plugin",
|
|
70
|
-
userOptions.projectRoot,
|
|
71
|
-
root
|
|
57
|
+
throw new Error(
|
|
58
|
+
"[RSC] Project root is not the current working directory, please set projectRoot in your config"
|
|
72
59
|
);
|
|
73
60
|
}
|
|
74
61
|
|
|
@@ -77,24 +64,15 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
77
64
|
enforce: "post",
|
|
78
65
|
api: {
|
|
79
66
|
meta: { timing },
|
|
80
|
-
addCssFile(path: string) {
|
|
81
|
-
buildCssFiles.add(path);
|
|
82
|
-
},
|
|
83
67
|
},
|
|
84
68
|
configResolved(_resolvedConfig) {
|
|
85
69
|
resolvedConfig = _resolvedConfig;
|
|
86
|
-
|
|
87
|
-
serverManifestPath = join(
|
|
88
|
-
userOptions.build.outDir,
|
|
89
|
-
userOptions.build.server,
|
|
90
|
-
".vite/manifest.json"
|
|
91
|
-
);
|
|
92
70
|
timing.configResolved = performance.now();
|
|
93
71
|
|
|
94
72
|
// Verify transformer runs first, preserver runs last
|
|
95
73
|
const plugins = resolvedConfig.plugins;
|
|
96
74
|
const transformerIndex = plugins.findIndex(
|
|
97
|
-
(p) => p.name === "vite:react-transform"
|
|
75
|
+
(p) => p.name === "vite:react-server-transform"
|
|
98
76
|
);
|
|
99
77
|
const preserverIndex = plugins.findIndex(
|
|
100
78
|
(p) => p.name === "vite-plugin-react-server:preserve-directives"
|
|
@@ -111,179 +89,44 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
111
89
|
},
|
|
112
90
|
|
|
113
91
|
async configurePreviewServer(server) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (typeof loader !== "function") {
|
|
118
|
-
loader = (id: string) => import(id);
|
|
119
|
-
}
|
|
120
|
-
const normalize = createInputNormalizer({
|
|
121
|
-
root,
|
|
122
|
-
removeExtension: false,
|
|
123
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
124
|
-
? userOptions.moduleBase
|
|
125
|
-
: undefined,
|
|
126
|
-
});
|
|
127
|
-
server.middlewares.use(async (req, res, next) => {
|
|
128
|
-
const [key, value] = normalize(req.url);
|
|
129
|
-
const fileRoot = key.startsWith("node_modules")
|
|
130
|
-
? root
|
|
131
|
-
: join(root, userOptions.build.outDir, userOptions.build.static);
|
|
132
|
-
try {
|
|
133
|
-
const filePath = join(fileRoot, value);
|
|
134
|
-
const stats = await stat(filePath);
|
|
135
|
-
|
|
136
|
-
if (stats.isFile()) {
|
|
137
|
-
const ext = value.slice(value.lastIndexOf("."));
|
|
138
|
-
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
139
|
-
res.setHeader("Content-Type", contentType);
|
|
140
|
-
const content = await readFile(filePath);
|
|
141
|
-
res.end(content);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
next();
|
|
145
|
-
} catch (error) {
|
|
146
|
-
console.log("Error serving static file:", error);
|
|
147
|
-
next();
|
|
148
|
-
}
|
|
92
|
+
await configurePreviewServer({
|
|
93
|
+
server,
|
|
94
|
+
userOptions,
|
|
149
95
|
});
|
|
150
96
|
},
|
|
151
97
|
async configureServer(server: ViteDevServer) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
typeof server.config.root === "string" &&
|
|
158
|
-
server.config.root !== process.cwd() &&
|
|
159
|
-
server.config.root !== ""
|
|
160
|
-
) {
|
|
161
|
-
console.log(
|
|
162
|
-
"[vite:plugin-react-server] Root dir changed in configureServer hook",
|
|
163
|
-
server.config.root,
|
|
164
|
-
root
|
|
165
|
-
);
|
|
166
|
-
root = server.config.root;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const activeStreams = new Set<ServerResponse>();
|
|
170
|
-
|
|
171
|
-
// Handle Vite server restarts
|
|
172
|
-
server.ws.on("restart", (path) => {
|
|
173
|
-
console.log(
|
|
174
|
-
"[vite-plugin-react-server] 🔧 Plugin changed, preparing for restart:",
|
|
175
|
-
path
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
// Close streams with restart message
|
|
179
|
-
for (const res of activeStreams) {
|
|
180
|
-
res.writeHead(503, {
|
|
181
|
-
"Content-Type": "text/x-component",
|
|
182
|
-
"Retry-After": "1",
|
|
183
|
-
});
|
|
184
|
-
res.end('{"error":"Server restarting..."}');
|
|
185
|
-
}
|
|
186
|
-
activeStreams.clear();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
server.middlewares.use(async (req, res, next) => {
|
|
190
|
-
if (req.headers.accept !== "text/x-component") return next();
|
|
191
|
-
if (typeof loader !== "function") {
|
|
192
|
-
loader = server.ssrLoadModule;
|
|
193
|
-
}
|
|
194
|
-
let route = req.url?.replace("/index.rsc", "");
|
|
195
|
-
if (!route || route === "") {
|
|
196
|
-
route = "/";
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
const handler = await createHandler({
|
|
200
|
-
root: root,
|
|
201
|
-
url:
|
|
202
|
-
typeof userOptions.moduleBaseURL === "string" &&
|
|
203
|
-
userOptions.moduleBaseURL !== ""
|
|
204
|
-
? new URL(route, userOptions.moduleBaseURL).href
|
|
205
|
-
: route,
|
|
206
|
-
route: route,
|
|
207
|
-
getCss: async (id) => {
|
|
208
|
-
const cssFiles = await collectModuleGraphCss({
|
|
209
|
-
moduleGraph: server.moduleGraph,
|
|
210
|
-
pagePath: id,
|
|
211
|
-
onCss: undefined,
|
|
212
|
-
})
|
|
213
|
-
if (userOptions.inlineCss) {
|
|
214
|
-
const InlineMap = new Map<string, CssContent>();
|
|
215
|
-
await Promise.all(Array.from(cssFiles.entries()).map(async ([file, fileUrl]) => {
|
|
216
|
-
const content = await server.ssrLoadModule(fileUrl + "?inline");
|
|
217
|
-
if (content) {
|
|
218
|
-
InlineMap.set(file, {
|
|
219
|
-
content: content['default'],
|
|
220
|
-
path: file,
|
|
221
|
-
type: "text/css",
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}));
|
|
225
|
-
return InlineMap;
|
|
226
|
-
}
|
|
227
|
-
return cssFiles;
|
|
228
|
-
},
|
|
229
|
-
cssFiles: [],
|
|
230
|
-
logger: createLogger(),
|
|
231
|
-
loader,
|
|
232
|
-
moduleBase: userOptions.moduleBase,
|
|
233
|
-
moduleBasePath: userOptions.moduleBasePath,
|
|
234
|
-
moduleBaseURL: userOptions.moduleBaseURL,
|
|
235
|
-
moduleRootPath: root,
|
|
236
|
-
pipableStreamOptions: userOptions.pipableStreamOptions,
|
|
237
|
-
Html: React.Fragment,
|
|
238
|
-
CssCollector: userOptions.inlineCss ? InlineCssCollector as any : CssCollector as any,
|
|
239
|
-
onCssFile: undefined,
|
|
240
|
-
inlineCss: userOptions.inlineCss,
|
|
241
|
-
propsPath: files.urlMap.get(route)?.props ?? route,
|
|
242
|
-
pagePath: files.urlMap.get(route)?.page ?? route,
|
|
243
|
-
pageExportName: userOptions.pageExportName,
|
|
244
|
-
propsExportName: userOptions.propsExportName,
|
|
245
|
-
});
|
|
246
|
-
if (handler.type === "success") {
|
|
247
|
-
handler.stream?.pipe(res);
|
|
248
|
-
}
|
|
249
|
-
activeStreams.add(res);
|
|
250
|
-
} finally {
|
|
251
|
-
res.on("close", () => {
|
|
252
|
-
activeStreams.delete(res);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
98
|
+
configureReactServer({
|
|
99
|
+
server,
|
|
100
|
+
autoDiscoveredFiles,
|
|
101
|
+
userOptions,
|
|
102
|
+
serverManifest,
|
|
255
103
|
});
|
|
256
104
|
},
|
|
257
105
|
async config(config, configEnv): Promise<UserConfig> {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
config.root,
|
|
267
|
-
root
|
|
268
|
-
);
|
|
269
|
-
root = config.root;
|
|
270
|
-
}
|
|
271
|
-
const resolvedPagesResult = await resolvePages(userOptions.build.pages);
|
|
272
|
-
if (resolvedPagesResult.type === "error") {
|
|
273
|
-
throw resolvedPagesResult.error;
|
|
106
|
+
const autoDiscoverResult = await resolveAutoDiscover({
|
|
107
|
+
config,
|
|
108
|
+
configEnv,
|
|
109
|
+
userOptions,
|
|
110
|
+
condition: "react-server",
|
|
111
|
+
});
|
|
112
|
+
if (autoDiscoverResult.type === "error") {
|
|
113
|
+
throw autoDiscoverResult.error;
|
|
274
114
|
}
|
|
275
|
-
|
|
276
|
-
files = await checkFilesExist(resolvedPages, userOptions, root);
|
|
115
|
+
autoDiscoveredFiles = autoDiscoverResult.autoDiscoveredFiles;
|
|
277
116
|
|
|
278
117
|
const resolvedConfig = resolveUserConfig({
|
|
279
|
-
|
|
118
|
+
condition: "react-server",
|
|
280
119
|
config,
|
|
281
120
|
configEnv,
|
|
282
121
|
userOptions,
|
|
283
|
-
|
|
122
|
+
autoDiscoveredFiles,
|
|
284
123
|
});
|
|
285
124
|
|
|
286
125
|
if (resolvedConfig.type === "error") {
|
|
126
|
+
console.error(
|
|
127
|
+
"[react-server-plugin] Failed to resolve config:",
|
|
128
|
+
resolvedConfig.error
|
|
129
|
+
);
|
|
287
130
|
throw resolvedConfig.error;
|
|
288
131
|
}
|
|
289
132
|
|
|
@@ -296,29 +139,35 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
296
139
|
console.log("Build already started");
|
|
297
140
|
}
|
|
298
141
|
},
|
|
299
|
-
handleHotUpdate({ file }) {
|
|
300
|
-
if (file.endsWith(".css")) {
|
|
301
|
-
cssModules.add(file);
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
142
|
async generateBundle(_options, bundle) {
|
|
305
|
-
if (!resolvedConfig) {
|
|
306
|
-
throw new Error("Resolved config not found");
|
|
307
|
-
}
|
|
308
|
-
|
|
309
143
|
// Create manifest entries for each chunk
|
|
310
|
-
serverManifest = getBundleManifest({
|
|
311
|
-
pluginContext: this,
|
|
144
|
+
serverManifest = getBundleManifest<false>({
|
|
312
145
|
bundle,
|
|
313
|
-
|
|
314
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot,
|
|
146
|
+
normalizer: userOptions.normalizer,
|
|
315
147
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
148
|
+
},
|
|
149
|
+
async handleHotUpdate({ file, server, read, timestamp, ...ctx }) {
|
|
150
|
+
try {
|
|
151
|
+
// Invalidate the module in Vite's cache for both client and SSR
|
|
152
|
+
if (server.moduleGraph) {
|
|
153
|
+
const mod = server.moduleGraph.getModuleById(file);
|
|
154
|
+
if (mod) {
|
|
155
|
+
// Invalidate the parent module which will handle both client and SSR
|
|
156
|
+
server.moduleGraph.invalidateModule(mod);
|
|
157
|
+
|
|
158
|
+
// Force a reload of the module
|
|
159
|
+
const newMod = await server.moduleGraph.ensureEntryFromUrl(file, false);
|
|
160
|
+
if (newMod) {
|
|
161
|
+
server.moduleGraph.invalidateModule(newMod);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Let Vite handle the HMR update
|
|
167
|
+
return ctx.modules;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error("[react-server] HMR Error:", error);
|
|
170
|
+
return ctx.modules;
|
|
322
171
|
}
|
|
323
172
|
},
|
|
324
173
|
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Manifest, ViteDevServer } from "vite";
|
|
2
|
+
import type { ServerResponse } from "http";
|
|
3
|
+
import type { AutoDiscoveredFiles, ResolvedUserOptions } from "../types.js";
|
|
4
|
+
import { createEventHandler } from "../helpers/createEventHandler.js";
|
|
5
|
+
import { collectViteModuleGraphCss } from "../helpers/collectViteModuleGraphCss.js";
|
|
6
|
+
import { resolvePageAndProps } from "../helpers/resolvePageAndProps.js";
|
|
7
|
+
import { createHandler } from "../helpers/createHandler.js";
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
export async function configureReactServer({
|
|
11
|
+
server,
|
|
12
|
+
autoDiscoveredFiles,
|
|
13
|
+
userOptions,
|
|
14
|
+
serverManifest,
|
|
15
|
+
}: {
|
|
16
|
+
server: ViteDevServer;
|
|
17
|
+
autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
18
|
+
userOptions: ResolvedUserOptions;
|
|
19
|
+
serverManifest: Manifest;
|
|
20
|
+
}) {
|
|
21
|
+
const activeStreams = new Set<ServerResponse>();
|
|
22
|
+
|
|
23
|
+
// Handle Vite server restarts
|
|
24
|
+
server.ws.on("restart", (path) => {
|
|
25
|
+
console.log(
|
|
26
|
+
"[vite-plugin-react-server] 🔧 Plugin changed, preparing for restart:",
|
|
27
|
+
path
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Close streams with restart message
|
|
31
|
+
for (const res of activeStreams) {
|
|
32
|
+
res.writeHead(503, {
|
|
33
|
+
"Content-Type": "text/x-component",
|
|
34
|
+
"Retry-After": "1",
|
|
35
|
+
});
|
|
36
|
+
res.end('{"error":"Server restarting..."}');
|
|
37
|
+
}
|
|
38
|
+
activeStreams.clear();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
server.middlewares.use(async (req, res, next) => {
|
|
42
|
+
try {
|
|
43
|
+
if (req.headers.accept !== "text/x-component") return next();
|
|
44
|
+
let route = req.url?.replace('/'+userOptions.build.rscOutputPath, "");
|
|
45
|
+
if (!route || route === "") {
|
|
46
|
+
route = "/";
|
|
47
|
+
}
|
|
48
|
+
if (!autoDiscoveredFiles.urlMap.has(route)) {
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
const routeFiles = autoDiscoveredFiles.urlMap.get(route)!;
|
|
52
|
+
const pagePath = routeFiles.page;
|
|
53
|
+
const propsPath = routeFiles.props;
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
Html: _UserHtmlComponent,
|
|
57
|
+
onEvent,
|
|
58
|
+
// remove these
|
|
59
|
+
moduleBaseURL,
|
|
60
|
+
...handlerUserOptions
|
|
61
|
+
} = userOptions;
|
|
62
|
+
// Create a unified event handler
|
|
63
|
+
await server.warmupRequest(pagePath);
|
|
64
|
+
const eventHandler = createEventHandler(onEvent);
|
|
65
|
+
const cssFilesResult = await collectViteModuleGraphCss({
|
|
66
|
+
moduleGraph: server.moduleGraph,
|
|
67
|
+
pagePath,
|
|
68
|
+
loader: (i)=>server.ssrLoadModule(i, {fixStacktrace: true}),
|
|
69
|
+
// explicitly set to empty string, because we let vite handle the resolving during development
|
|
70
|
+
moduleBaseURL: "",
|
|
71
|
+
moduleBasePath: userOptions.moduleBasePath,
|
|
72
|
+
moduleRootPath: userOptions.moduleRootPath,
|
|
73
|
+
projectRoot: userOptions.projectRoot,
|
|
74
|
+
css: userOptions.css,
|
|
75
|
+
parentUrl: pagePath,
|
|
76
|
+
});
|
|
77
|
+
if (cssFilesResult.type === "skip") {
|
|
78
|
+
return next();
|
|
79
|
+
}
|
|
80
|
+
if (cssFilesResult.type === "error") {
|
|
81
|
+
throw cssFilesResult.error;
|
|
82
|
+
}
|
|
83
|
+
const pageAndPropsResult = await resolvePageAndProps({
|
|
84
|
+
pagePath,
|
|
85
|
+
propsPath,
|
|
86
|
+
route,
|
|
87
|
+
loader: server.ssrLoadModule,
|
|
88
|
+
pageExportName: userOptions.pageExportName ?? "default",
|
|
89
|
+
propsExportName: userOptions.propsExportName ?? "default",
|
|
90
|
+
});
|
|
91
|
+
if (pageAndPropsResult.type === "error") {
|
|
92
|
+
throw pageAndPropsResult.error;
|
|
93
|
+
}
|
|
94
|
+
if (pageAndPropsResult.type === "skip") {
|
|
95
|
+
return next();
|
|
96
|
+
}
|
|
97
|
+
const { PageComponent, pageProps } = pageAndPropsResult;
|
|
98
|
+
// Create the headless RSC stream directly
|
|
99
|
+
const rscResult = await createHandler({
|
|
100
|
+
...handlerUserOptions,
|
|
101
|
+
PageComponent: PageComponent,
|
|
102
|
+
pageProps: pageProps,
|
|
103
|
+
logger: server.config.logger,
|
|
104
|
+
loader: server.ssrLoadModule,
|
|
105
|
+
Html: React.Fragment,
|
|
106
|
+
onEvent: eventHandler,
|
|
107
|
+
manifest: serverManifest,
|
|
108
|
+
worker: server as any,
|
|
109
|
+
route,
|
|
110
|
+
pagePath,
|
|
111
|
+
propsPath,
|
|
112
|
+
cssFiles: cssFilesResult.cssFiles ?? new Map(),
|
|
113
|
+
// explicitly set to empty string, because we let vite handle the resolving during development
|
|
114
|
+
moduleBaseURL: "",
|
|
115
|
+
globalCss: new Map(),
|
|
116
|
+
});
|
|
117
|
+
if (rscResult.type === "success") {
|
|
118
|
+
rscResult.stream!.pipe(res);
|
|
119
|
+
}
|
|
120
|
+
activeStreams.add(res);
|
|
121
|
+
res.on("close", () => {
|
|
122
|
+
activeStreams.delete(res);
|
|
123
|
+
});
|
|
124
|
+
} catch (error) {
|
|
125
|
+
res.end();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rscHandler.ts
|
|
3
|
+
*
|
|
4
|
+
* PURPOSE: Handles collecting HTML content from the htmlCompact stream
|
|
5
|
+
*
|
|
6
|
+
* This module:
|
|
7
|
+
* 1. Collects HTML content from the rscFull stream (which includes <html> and <body> tags)
|
|
8
|
+
* 2. Returns the complete HTML content when the stream is done
|
|
9
|
+
* 3. Provides a clean interface for HTML handling
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { PassThrough, Transform } from "node:stream";
|
|
13
|
+
import type { CreateHandlerOptions, StreamMetrics } from "../types.js";
|
|
14
|
+
import { createStreamMetrics } from "../helpers/metrics.js";
|
|
15
|
+
import { createRscToHtmlStream } from "./rscToHtmlStream.js";
|
|
16
|
+
import { fileWriter } from "./fileWriter.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Collects RSC content from the rscFull stream
|
|
20
|
+
*
|
|
21
|
+
* @param rscFull The stream containing the RSC content
|
|
22
|
+
* @returns A promise that resolves with the complete RSC content
|
|
23
|
+
*/
|
|
24
|
+
export async function collectHtmlWorkerContent(
|
|
25
|
+
rscStream: PassThrough,
|
|
26
|
+
handlerOptions: CreateHandlerOptions
|
|
27
|
+
): Promise<{ stream: PassThrough; metrics: StreamMetrics }> {
|
|
28
|
+
const metrics = createStreamMetrics();
|
|
29
|
+
const startTime = performance.now();
|
|
30
|
+
|
|
31
|
+
// Create RSC to HTML transform stream
|
|
32
|
+
const rscToHtmlStream = createRscToHtmlStream({
|
|
33
|
+
worker: handlerOptions.worker,
|
|
34
|
+
route: handlerOptions.route,
|
|
35
|
+
moduleRootPath: handlerOptions.moduleRootPath,
|
|
36
|
+
moduleBaseURL: handlerOptions.moduleBaseURL,
|
|
37
|
+
pipeableStreamOptions: handlerOptions.pipeableStreamOptions,
|
|
38
|
+
build: handlerOptions.build,
|
|
39
|
+
cssFiles: handlerOptions.cssFiles,
|
|
40
|
+
projectRoot: handlerOptions.projectRoot,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Create transform stream to handle HTML chunks and file writing
|
|
44
|
+
const htmlTransform = new Transform({
|
|
45
|
+
transform(chunk, _encoding, callback) {
|
|
46
|
+
metrics.chunks++;
|
|
47
|
+
callback(null, chunk);
|
|
48
|
+
},
|
|
49
|
+
flush(callback) {
|
|
50
|
+
metrics.duration = Date.now() - startTime;
|
|
51
|
+
callback();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
let isComplete = false;
|
|
56
|
+
|
|
57
|
+
// Create a promise that resolves when the route is complete
|
|
58
|
+
const routeComplete = new Promise<void>((resolve, reject) => {
|
|
59
|
+
const messageHandler = (msg: any) => {
|
|
60
|
+
switch (msg.type) {
|
|
61
|
+
case "HTML_CHUNK":
|
|
62
|
+
if (!isComplete) {
|
|
63
|
+
htmlTransform.write(msg.chunk);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "HTML_COMPLETE":
|
|
67
|
+
isComplete = true;
|
|
68
|
+
// End the transform stream
|
|
69
|
+
htmlTransform.end();
|
|
70
|
+
// Send cleanup message to worker
|
|
71
|
+
handlerOptions.worker.postMessage({
|
|
72
|
+
type: "CLEANUP",
|
|
73
|
+
id: handlerOptions.route,
|
|
74
|
+
});
|
|
75
|
+
break;
|
|
76
|
+
case "CLEANUP_COMPLETE":
|
|
77
|
+
resolve();
|
|
78
|
+
break;
|
|
79
|
+
case "ERROR":
|
|
80
|
+
handlerOptions.worker.removeListener("message", messageHandler);
|
|
81
|
+
reject(msg.error);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
handlerOptions.worker.on("message", messageHandler);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
// Set up event handler to capture content length
|
|
90
|
+
if (handlerOptions.onEvent) {
|
|
91
|
+
const originalOnEvent = handlerOptions.onEvent;
|
|
92
|
+
handlerOptions.onEvent = (event) => {
|
|
93
|
+
if (event.type === "file.write.done" && event.data.fileType === "html") {
|
|
94
|
+
metrics.bytes = event.data.content.length;
|
|
95
|
+
}
|
|
96
|
+
originalOnEvent(event);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Pipe RSC through transform to HTML
|
|
101
|
+
rscStream.pipe(rscToHtmlStream);
|
|
102
|
+
|
|
103
|
+
// Set up file writing using fileWriter
|
|
104
|
+
const writePromise = fileWriter(htmlTransform, "html", handlerOptions);
|
|
105
|
+
|
|
106
|
+
// Wait for route to complete
|
|
107
|
+
await routeComplete;
|
|
108
|
+
|
|
109
|
+
// Wait for file writing to complete
|
|
110
|
+
await writePromise;
|
|
111
|
+
|
|
112
|
+
rscToHtmlStream.destroy();
|
|
113
|
+
|
|
114
|
+
return { stream: rscStream, metrics };
|
|
115
|
+
} catch (error) {
|
|
116
|
+
// Clean up streams on error
|
|
117
|
+
rscToHtmlStream.destroy();
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|