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,41 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Plugin } from "vite";
|
|
2
2
|
import type {
|
|
3
|
-
|
|
3
|
+
AutoDiscoveredFiles,
|
|
4
4
|
ResolvedUserConfig,
|
|
5
5
|
ResolvedUserOptions,
|
|
6
6
|
StreamPluginOptions,
|
|
7
7
|
} from "../types.js";
|
|
8
8
|
import { resolveOptions } from "../config/resolveOptions.js";
|
|
9
9
|
import { resolveUserConfig } from "../config/resolveUserConfig.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { resolvePages } from "../config/resolvePages.js";
|
|
15
|
-
import { createInputNormalizer } from "../helpers/inputNormalizer.js";
|
|
16
|
-
import { createWorker } from "../worker/createWorker.js";
|
|
17
|
-
import type { Worker } from "node:worker_threads";
|
|
18
|
-
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
19
|
-
import type {
|
|
20
|
-
RscRenderMessage,
|
|
21
|
-
RscWorkerMessage,
|
|
22
|
-
RscWorkerResponse,
|
|
23
|
-
} from "../worker/types.js";
|
|
24
|
-
import { MIME_TYPES } from "../config/mimeTypes.js";
|
|
25
|
-
|
|
10
|
+
import { resolveAutoDiscover } from "../config/resolveAutoDiscover.js";
|
|
11
|
+
import { configureWorkerRequestHandler } from "./server.js";
|
|
12
|
+
import { configurePreviewServer } from "../react-static/configurePreviewServer.js";
|
|
13
|
+
import { MessageChannel } from "node:worker_threads";
|
|
26
14
|
|
|
27
15
|
let userOptions: ResolvedUserOptions;
|
|
28
16
|
let userConfig: ResolvedUserConfig;
|
|
29
|
-
let clientManifest: Manifest = {};
|
|
30
|
-
let resolvedConfig: ResolvedConfig;
|
|
31
17
|
let root: string;
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
let worker: Worker;
|
|
35
|
-
let files: CheckFilesExistReturn;
|
|
18
|
+
let autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
19
|
+
let hmrChannel: MessageChannel | null = null;
|
|
36
20
|
|
|
37
21
|
export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
38
|
-
const resolvedOptions = resolveOptions(options
|
|
22
|
+
const resolvedOptions = resolveOptions(options);
|
|
39
23
|
if (resolvedOptions.type === "error") {
|
|
40
24
|
throw resolvedOptions.error;
|
|
41
25
|
}
|
|
@@ -53,39 +37,25 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
53
37
|
config.root !== ""
|
|
54
38
|
) {
|
|
55
39
|
root = config.root;
|
|
56
|
-
console.log("[vite:react-client] Root updated:", root);
|
|
57
|
-
}
|
|
58
|
-
if (configEnv.command === "serve" && !configEnv.isPreview && !worker) {
|
|
59
|
-
worker = await createWorker({
|
|
60
|
-
projectRoot: root,
|
|
61
|
-
workerPath: userOptions.rscWorkerPath,
|
|
62
|
-
reverseCondition: true,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const pages = await resolvePages(userOptions.build.pages);
|
|
66
|
-
if (pages.type === "error") {
|
|
67
|
-
throw pages.error;
|
|
68
40
|
}
|
|
69
41
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
urlMap: new Map(),
|
|
79
|
-
errors: [],
|
|
80
|
-
};
|
|
42
|
+
const autoDiscoverResult = await resolveAutoDiscover({
|
|
43
|
+
config,
|
|
44
|
+
configEnv,
|
|
45
|
+
userOptions,
|
|
46
|
+
condition: "react-client",
|
|
47
|
+
});
|
|
48
|
+
if (autoDiscoverResult.type === "error") {
|
|
49
|
+
throw autoDiscoverResult.error;
|
|
81
50
|
}
|
|
51
|
+
autoDiscoveredFiles = autoDiscoverResult.autoDiscoveredFiles;
|
|
82
52
|
|
|
83
53
|
const resolvedConfig = resolveUserConfig({
|
|
84
|
-
|
|
54
|
+
condition: "react-client",
|
|
85
55
|
config,
|
|
86
56
|
configEnv,
|
|
87
57
|
userOptions,
|
|
88
|
-
|
|
58
|
+
autoDiscoveredFiles,
|
|
89
59
|
});
|
|
90
60
|
|
|
91
61
|
if (resolvedConfig.type === "error") {
|
|
@@ -96,225 +66,66 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
96
66
|
return userConfig;
|
|
97
67
|
},
|
|
98
68
|
|
|
99
|
-
configResolved(config) {
|
|
100
|
-
resolvedConfig = config;
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
async generateBundle(_options, bundle) {
|
|
104
|
-
// Create manifest entries for each chunk
|
|
105
|
-
clientManifest = getBundleManifest({
|
|
106
|
-
pluginContext: this,
|
|
107
|
-
bundle,
|
|
108
|
-
moduleBase: userOptions.moduleBase,
|
|
109
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Write manifest immediately after generation
|
|
113
|
-
const manifestPath = join(
|
|
114
|
-
root,
|
|
115
|
-
resolvedConfig.environments["client"].build.outDir as string,
|
|
116
|
-
resolvedConfig.environments["client"].build.manifest as string
|
|
117
|
-
);
|
|
118
|
-
await mkdir(dirname(manifestPath), { recursive: true });
|
|
119
|
-
|
|
120
|
-
return await writeFile(
|
|
121
|
-
manifestPath,
|
|
122
|
-
JSON.stringify(clientManifest, null, 2)
|
|
123
|
-
);
|
|
124
|
-
},
|
|
125
|
-
|
|
126
69
|
async configurePreviewServer(server) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (typeof loader !== "function") {
|
|
131
|
-
loader = (id: string) => import(id);
|
|
132
|
-
}
|
|
133
|
-
const normalize = createInputNormalizer({
|
|
134
|
-
root,
|
|
135
|
-
removeExtension: false,
|
|
136
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
137
|
-
? userOptions.moduleBase
|
|
138
|
-
: undefined,
|
|
139
|
-
});
|
|
140
|
-
server.middlewares.use(async (req, res, next) => {
|
|
141
|
-
const [key, value] = normalize(req.url);
|
|
142
|
-
const fileRoot = key.startsWith("node_modules")
|
|
143
|
-
? root
|
|
144
|
-
: join(root, userOptions.build.outDir, userOptions.build.static);
|
|
145
|
-
try {
|
|
146
|
-
const filePath = join(fileRoot, value);
|
|
147
|
-
const stats = await stat(filePath);
|
|
148
|
-
|
|
149
|
-
if (stats.isFile()) {
|
|
150
|
-
const ext = value.slice(value.lastIndexOf('.'));
|
|
151
|
-
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
|
152
|
-
res.setHeader('Content-Type', contentType);
|
|
153
|
-
const content = await readFile(filePath);
|
|
154
|
-
res.end(content);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
next();
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.log("Error serving static file:", error);
|
|
160
|
-
next();
|
|
161
|
-
}
|
|
70
|
+
await configurePreviewServer({
|
|
71
|
+
server,
|
|
72
|
+
userOptions,
|
|
162
73
|
});
|
|
163
74
|
},
|
|
164
75
|
// setup dev server
|
|
165
76
|
async configureServer(server) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
condition: "react-client",
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
const normalize = createInputNormalizer({
|
|
177
|
-
root,
|
|
178
|
-
removeExtension: false,
|
|
179
|
-
preserveModulesRoot: userOptions.build.preserveModulesRoot
|
|
180
|
-
? userOptions.moduleBase
|
|
181
|
-
: undefined,
|
|
77
|
+
// Create HMR message channel
|
|
78
|
+
hmrChannel = new MessageChannel();
|
|
79
|
+
await configureWorkerRequestHandler({
|
|
80
|
+
server,
|
|
81
|
+
autoDiscoveredFiles,
|
|
82
|
+
userOptions,
|
|
83
|
+
hmrChannel,
|
|
182
84
|
});
|
|
183
|
-
|
|
184
|
-
if (!req.url) {
|
|
185
|
-
next();
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (
|
|
189
|
-
req.url.endsWith(".rsc") ||
|
|
190
|
-
req.headers.accept?.includes("text/x-component")
|
|
191
|
-
) {
|
|
192
|
-
try {
|
|
193
|
-
const path = req.url?.includes("index.rsc")
|
|
194
|
-
? req.url.replace("index.rsc", "")
|
|
195
|
-
: req.url?.replace(".rsc", "");
|
|
196
|
-
let [key, value] = normalize(path);
|
|
197
|
-
|
|
198
|
-
let pageImport = DEFAULT_CONFIG.PAGE as string;
|
|
199
|
-
let propsImport = DEFAULT_CONFIG.PROPS as string;
|
|
200
|
-
// PAGE
|
|
201
|
-
// no trailing slash
|
|
202
|
-
const pathNoTrailing = path?.replace(/\/$/, '');
|
|
203
|
-
if (files.urlMap.has(req.url)) {
|
|
204
|
-
pageImport = files.urlMap.get(req.url)!.page;
|
|
205
|
-
propsImport = files.urlMap.get(req.url)!.props;
|
|
206
|
-
} else if (files.urlMap.has(pathNoTrailing)) {
|
|
207
|
-
pageImport = files.urlMap.get(pathNoTrailing)!.page;
|
|
208
|
-
propsImport = files.urlMap.get(pathNoTrailing)!.props;
|
|
209
|
-
} else if (files.urlMap.has(path)) {
|
|
210
|
-
pageImport = files.urlMap.get(path)!.page;
|
|
211
|
-
propsImport = files.urlMap.get(path)!.props;
|
|
212
|
-
} else if (files.urlMap.has(value)) {
|
|
213
|
-
pageImport = files.urlMap.get(value)!.page;
|
|
214
|
-
propsImport = files.urlMap.get(value)!.props;
|
|
215
|
-
} else if (files.urlMap.has(key)) {
|
|
216
|
-
pageImport = files.urlMap.get(key)!.page;
|
|
217
|
-
propsImport = files.urlMap.get(key)!.props;
|
|
218
|
-
} else {
|
|
219
|
-
console.warn(`Page/props import not found for any of the following (in order of priority): ${[req.url, pathNoTrailing, path, value, key].filter(Boolean).join(', ')} available pages:${Array.from(files.urlMap.keys()).join(', ')}`);
|
|
220
|
-
}
|
|
221
|
-
// Set headers early
|
|
222
|
-
res.setHeader("Content-Type", "text/x-component");
|
|
223
|
-
res.setHeader("Transfer-Encoding", "chunked");
|
|
224
|
-
res.setHeader("Connection", "keep-alive");
|
|
225
|
-
|
|
226
|
-
let hasError = false;
|
|
227
|
-
const timeout = setTimeout(() => {
|
|
228
|
-
if (!hasError) {
|
|
229
|
-
hasError = true;
|
|
230
|
-
res.statusCode = 500;
|
|
231
|
-
res.end("RSC render timeout");
|
|
232
|
-
}
|
|
233
|
-
}, 5000);
|
|
234
|
-
|
|
235
|
-
const messageHandler = (
|
|
236
|
-
message: RscWorkerMessage | RscWorkerResponse
|
|
237
|
-
) => {
|
|
238
|
-
try {
|
|
239
|
-
switch (message.type) {
|
|
240
|
-
case "RSC_CHUNK":
|
|
241
|
-
// Write chunk directly to response
|
|
242
|
-
if (!hasError) {
|
|
243
|
-
res.write(message.chunk);
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
|
|
247
|
-
case "RSC_END":
|
|
248
|
-
clearTimeout(timeout);
|
|
249
|
-
if (!hasError) {
|
|
250
|
-
res.end();
|
|
251
|
-
}
|
|
252
|
-
worker.off("message", messageHandler);
|
|
253
|
-
break;
|
|
254
|
-
|
|
255
|
-
case "ERROR":
|
|
256
|
-
clearTimeout(timeout);
|
|
257
|
-
if (!hasError) {
|
|
258
|
-
hasError = true;
|
|
259
|
-
res.statusCode = 500;
|
|
260
|
-
res.end(message.error);
|
|
261
|
-
}
|
|
262
|
-
worker.off("message", messageHandler);
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
} catch (error) {
|
|
266
|
-
clearTimeout(timeout);
|
|
267
|
-
if (!hasError) {
|
|
268
|
-
hasError = true;
|
|
269
|
-
res.statusCode = 500;
|
|
270
|
-
res.end(
|
|
271
|
-
error instanceof Error ? error.message : String(error)
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
worker.off("message", messageHandler);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
85
|
+
},
|
|
277
86
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
87
|
+
async handleHotUpdate({ file, server, read, timestamp, ...ctx }) {
|
|
88
|
+
try {
|
|
89
|
+
// Check if the file is a page or props file
|
|
90
|
+
const isPageFile = userOptions.autoDiscover.modulePattern(file);
|
|
91
|
+
if (!isPageFile) return;
|
|
92
|
+
|
|
93
|
+
// Get the route for this file
|
|
94
|
+
const [, value] = userOptions.normalizer(file);
|
|
95
|
+
|
|
96
|
+
// Find all routes affected by this file change
|
|
97
|
+
const affectedRoutes = autoDiscoveredFiles.routeMap.get(value) || [];
|
|
98
|
+
|
|
99
|
+
// Send HMR update directly to worker through MessageChannel
|
|
100
|
+
if (hmrChannel?.port1) {
|
|
101
|
+
hmrChannel.port1.postMessage({
|
|
102
|
+
type: 'HMR_UPDATE',
|
|
103
|
+
path: file,
|
|
104
|
+
timestamp,
|
|
105
|
+
routes: affectedRoutes
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Trigger a full page refresh for affected routes
|
|
109
|
+
for (const route of affectedRoutes) {
|
|
110
|
+
server.ws.send({
|
|
111
|
+
type: 'full-reload',
|
|
112
|
+
path: route
|
|
287
113
|
});
|
|
288
|
-
worker.postMessage({
|
|
289
|
-
type: "RSC_RENDER",
|
|
290
|
-
id: value,
|
|
291
|
-
pageImport,
|
|
292
|
-
propsImport,
|
|
293
|
-
url: req.url ?? "/",
|
|
294
|
-
pageExportName:
|
|
295
|
-
userOptions.pageExportName ?? DEFAULT_CONFIG.PAGE_EXPORT_NAME,
|
|
296
|
-
propsExportName:
|
|
297
|
-
userOptions.propsExportName ?? DEFAULT_CONFIG.PROPS_EXPORT_NAME,
|
|
298
|
-
outDir: userOptions.build.outDir,
|
|
299
|
-
projectRoot: root,
|
|
300
|
-
moduleRootPath:
|
|
301
|
-
userOptions.build.preserveModulesRoot === true
|
|
302
|
-
? userOptions.moduleBase
|
|
303
|
-
: "",
|
|
304
|
-
moduleBaseURL: userOptions.moduleBaseURL,
|
|
305
|
-
moduleBasePath: userOptions.moduleBasePath,
|
|
306
|
-
moduleBase: userOptions.moduleBase,
|
|
307
|
-
pipableStreamOptions: userOptions.pipableStreamOptions,
|
|
308
|
-
cssFiles: []
|
|
309
|
-
} satisfies RscRenderMessage);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
res.statusCode = 500;
|
|
312
|
-
res.end(error instanceof Error ? error.message : String(error));
|
|
313
114
|
}
|
|
314
|
-
} else {
|
|
315
|
-
next();
|
|
316
115
|
}
|
|
317
|
-
|
|
116
|
+
|
|
117
|
+
// Let Vite handle the HMR update
|
|
118
|
+
return ctx.modules;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (hmrChannel?.port1) {
|
|
121
|
+
hmrChannel.port1.postMessage({
|
|
122
|
+
type: 'HMR_ERROR',
|
|
123
|
+
path: file,
|
|
124
|
+
error: error instanceof Error ? error.message : String(error)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return ctx.modules;
|
|
128
|
+
}
|
|
318
129
|
},
|
|
319
130
|
};
|
|
320
131
|
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import type { ViteDevServer } from "vite";
|
|
2
|
+
import type {
|
|
3
|
+
AutoDiscoveredFiles,
|
|
4
|
+
RequestHandler,
|
|
5
|
+
ResolvedUserOptions,
|
|
6
|
+
} from "../types.js";
|
|
7
|
+
import type {
|
|
8
|
+
RscWorkerOutputMessage,
|
|
9
|
+
RscRenderMessage,
|
|
10
|
+
} from "../worker/types.js";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import type { Worker as NodeWorker } from "node:worker_threads";
|
|
13
|
+
import { MessageChannel } from "node:worker_threads";
|
|
14
|
+
import {
|
|
15
|
+
serializedDevServerConfig,
|
|
16
|
+
serializedOptions,
|
|
17
|
+
} from "../helpers/serializeUserOptions.js";
|
|
18
|
+
import { createWorker } from "../worker/createWorker.js";
|
|
19
|
+
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
20
|
+
|
|
21
|
+
let currentWorker: NodeWorker | null = null;
|
|
22
|
+
let isRestarting = false;
|
|
23
|
+
|
|
24
|
+
async function restartWorker(
|
|
25
|
+
server: ViteDevServer,
|
|
26
|
+
autoDiscoveredFiles: AutoDiscoveredFiles,
|
|
27
|
+
userOptions: ResolvedUserOptions,
|
|
28
|
+
hmrChannel: MessageChannel
|
|
29
|
+
) {
|
|
30
|
+
if (isRestarting) return;
|
|
31
|
+
isRestarting = true;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
// Terminate the current worker if it exists
|
|
35
|
+
if (currentWorker) {
|
|
36
|
+
currentWorker.terminate();
|
|
37
|
+
currentWorker = null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const workerResult = await createWorker({
|
|
41
|
+
projectRoot: server.config.root,
|
|
42
|
+
workerPath: userOptions.rscWorkerPath,
|
|
43
|
+
reverseCondition: "react-server",
|
|
44
|
+
currentCondition: "react-client",
|
|
45
|
+
workerData: {
|
|
46
|
+
hmrPort: hmrChannel.port2,
|
|
47
|
+
resolvedConfig: serializedDevServerConfig(server.config),
|
|
48
|
+
userOptions: serializedOptions(userOptions, autoDiscoveredFiles),
|
|
49
|
+
},
|
|
50
|
+
transferList: [hmrChannel.port2],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (workerResult.type === "success") {
|
|
54
|
+
currentWorker = workerResult.worker;
|
|
55
|
+
} else if (workerResult.type === "error") {
|
|
56
|
+
server.config.logger.error("Failed to start rsc-worker", {
|
|
57
|
+
error: workerResult.error,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
isRestarting = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Creates an async generator that yields RSC chunks from the worker.
|
|
67
|
+
* Handles both module requests and RSC streaming.
|
|
68
|
+
*
|
|
69
|
+
* @param worker - The worker thread
|
|
70
|
+
* @param server - The Vite dev server
|
|
71
|
+
* @param message - The RSC render message
|
|
72
|
+
* @param rscWorkerLoaderPort - Optional loader port for module loading
|
|
73
|
+
* @returns An async generator that yields RSC chunks
|
|
74
|
+
*/
|
|
75
|
+
async function* createWorkerStream(
|
|
76
|
+
worker: NodeWorker,
|
|
77
|
+
message: Omit<RscRenderMessage, "type" | "id">
|
|
78
|
+
): AsyncGenerator<Uint8Array, void, unknown> {
|
|
79
|
+
let messageHandler: (message: RscWorkerOutputMessage) => void;
|
|
80
|
+
let cleanup: () => void = () => {};
|
|
81
|
+
|
|
82
|
+
// First yield: wait for initial message and handle module requests
|
|
83
|
+
yield await new Promise<Uint8Array>((resolve) => {
|
|
84
|
+
messageHandler = (message: RscWorkerOutputMessage) => {
|
|
85
|
+
if (message.type === "RSC_CHUNK") {
|
|
86
|
+
resolve(message.chunk);
|
|
87
|
+
}
|
|
88
|
+
if (message.type === "ERROR") {
|
|
89
|
+
resolve(new Uint8Array());
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
cleanup = () => {
|
|
94
|
+
worker.off("message", messageHandler);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
worker.on("message", messageHandler);
|
|
98
|
+
|
|
99
|
+
// Send the render message to start the RSC stream
|
|
100
|
+
worker.postMessage({
|
|
101
|
+
type: "RSC_RENDER",
|
|
102
|
+
id: message.route,
|
|
103
|
+
...message,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Subsequent yields: handle RSC chunks until stream ends
|
|
108
|
+
while (true) {
|
|
109
|
+
const chunk = await new Promise<Uint8Array>((resolve) => {
|
|
110
|
+
messageHandler = (message: RscWorkerOutputMessage) => {
|
|
111
|
+
if (message.type === "RSC_END") {
|
|
112
|
+
cleanup();
|
|
113
|
+
resolve(new Uint8Array());
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (message.type === "RSC_CHUNK") {
|
|
117
|
+
resolve(message.chunk);
|
|
118
|
+
}
|
|
119
|
+
if (message.type === "ERROR") {
|
|
120
|
+
cleanup();
|
|
121
|
+
resolve(new Uint8Array());
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
worker.once("message", messageHandler);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
if (chunk.length === 0) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
yield chunk;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Handles the RSC stream from the worker.
|
|
137
|
+
* Creates a ReadableStream that pipes RSC chunks to the response.
|
|
138
|
+
*
|
|
139
|
+
* @param worker - The worker thread
|
|
140
|
+
* @param message - The RSC render message
|
|
141
|
+
* @returns A ReadableStream that yields RSC chunks
|
|
142
|
+
*/
|
|
143
|
+
export function handleWorkerRscStream(
|
|
144
|
+
worker: NodeWorker,
|
|
145
|
+
message: Omit<RscRenderMessage, "type" | "id">
|
|
146
|
+
): ReadableStream<Uint8Array> {
|
|
147
|
+
// Create a ReadableStream from the async generator
|
|
148
|
+
return new ReadableStream<Uint8Array>({
|
|
149
|
+
async start(controller) {
|
|
150
|
+
try {
|
|
151
|
+
for await (const chunk of createWorkerStream(worker, message)) {
|
|
152
|
+
controller.enqueue(chunk);
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
controller.error(error);
|
|
156
|
+
} finally {
|
|
157
|
+
controller.close();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Configures the worker request handler.
|
|
165
|
+
* @param server - The Vite dev server
|
|
166
|
+
* @param autoDiscoveredFiles - The auto discovered files
|
|
167
|
+
* @param userOptions - The user options
|
|
168
|
+
*/
|
|
169
|
+
export async function configureWorkerRequestHandler({
|
|
170
|
+
server,
|
|
171
|
+
autoDiscoveredFiles,
|
|
172
|
+
userOptions,
|
|
173
|
+
hmrChannel,
|
|
174
|
+
}: {
|
|
175
|
+
server: ViteDevServer;
|
|
176
|
+
autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
177
|
+
userOptions: ResolvedUserOptions;
|
|
178
|
+
hmrChannel: MessageChannel;
|
|
179
|
+
}) {
|
|
180
|
+
if(server.config.root !== userOptions.projectRoot) {
|
|
181
|
+
server.config.logger.error("[react-client] Project root mismatch", {
|
|
182
|
+
error: new Error(`Server root ${server.config.root} does not match user options root ${userOptions.projectRoot}`)
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Start the worker
|
|
188
|
+
await restartWorker(server, autoDiscoveredFiles, userOptions, hmrChannel);
|
|
189
|
+
|
|
190
|
+
// Create the request handler
|
|
191
|
+
const handler: RequestHandler = async (req, res, next) => {
|
|
192
|
+
if (!req.url || req.headers.accept !== "text/x-component") return next();
|
|
193
|
+
try {
|
|
194
|
+
if (!currentWorker) {
|
|
195
|
+
server.config.logger.error("[react-client] No worker available");
|
|
196
|
+
return next();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Get the route from the request
|
|
200
|
+
let route = req.url;
|
|
201
|
+
if (!route || route === "") route = "/";
|
|
202
|
+
// in the case of the no build.pages and a async Page and or props userOption, we need to await those
|
|
203
|
+
// if they are already autoDiscovered then the promise will resolve immediately
|
|
204
|
+
const routeFiles = await getRouteFiles(
|
|
205
|
+
route,
|
|
206
|
+
autoDiscoveredFiles,
|
|
207
|
+
userOptions
|
|
208
|
+
);
|
|
209
|
+
if (routeFiles.type === "error") {
|
|
210
|
+
server.config.logger.error("[react-client] Error getting route files", {
|
|
211
|
+
error: routeFiles.error,
|
|
212
|
+
});
|
|
213
|
+
return next();
|
|
214
|
+
}
|
|
215
|
+
const { page, props } = routeFiles;
|
|
216
|
+
|
|
217
|
+
// Set up response headers for streaming
|
|
218
|
+
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
219
|
+
res.setHeader("Transfer-Encoding", "chunked");
|
|
220
|
+
res.setHeader("Connection", "keep-alive");
|
|
221
|
+
let timeout = setTimeout(() => {
|
|
222
|
+
server.config.logger.error("[react-client] RSC render timeout");
|
|
223
|
+
res.end();
|
|
224
|
+
}, 5000);
|
|
225
|
+
const serializedUserOptions = serializedOptions(
|
|
226
|
+
userOptions,
|
|
227
|
+
autoDiscoveredFiles
|
|
228
|
+
);
|
|
229
|
+
const stream = handleWorkerRscStream(currentWorker, {
|
|
230
|
+
...serializedUserOptions,
|
|
231
|
+
// we make the worker stream aware of the route, pagePath, propsPath
|
|
232
|
+
route,
|
|
233
|
+
pagePath: page,
|
|
234
|
+
propsPath: props,
|
|
235
|
+
// override these at all times to ensure the settings will work for the dev server
|
|
236
|
+
projectRoot: server.config.root,
|
|
237
|
+
moduleRootPath: join(server.config.root, userOptions.moduleBase),
|
|
238
|
+
moduleBaseURL: "",
|
|
239
|
+
moduleBasePath: "",
|
|
240
|
+
build: serializedUserOptions.build,
|
|
241
|
+
manifest: autoDiscoveredFiles.staticManifest,
|
|
242
|
+
cssFiles: new Map(),
|
|
243
|
+
globalCss: new Map(),
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// Pipe the stream to the response
|
|
247
|
+
stream.pipeTo(
|
|
248
|
+
new WritableStream({
|
|
249
|
+
write(chunk) {
|
|
250
|
+
res.write(chunk);
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
close() {
|
|
254
|
+
clearTimeout(timeout);
|
|
255
|
+
res.end();
|
|
256
|
+
},
|
|
257
|
+
abort() {
|
|
258
|
+
clearTimeout(timeout);
|
|
259
|
+
// Restart worker on error
|
|
260
|
+
restartWorker(server, autoDiscoveredFiles, userOptions, hmrChannel);
|
|
261
|
+
res.end();
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (error instanceof Error) {
|
|
267
|
+
server.config.logger.error("[react-client] Error handling request", {
|
|
268
|
+
error,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
// attach handler to the server
|
|
274
|
+
server.middlewares.use(handler);
|
|
275
|
+
// done
|
|
276
|
+
}
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { reactStaticPlugin } from "../react-static/plugin.js";
|
|
3
|
-
import { reactTransformPlugin } from "../transformer/plugin.js";
|
|
4
|
-
import type { StreamPluginOptions } from "../types.js";
|
|
5
|
-
import { reactServerPlugin } from "./plugin.js";
|
|
6
|
-
|
|
7
|
-
export function vitePluginReactServer(options = {} as StreamPluginOptions): import("vite").Plugin[] {
|
|
8
|
-
return [
|
|
9
|
-
reactTransformPlugin(options),
|
|
10
|
-
reactServerPlugin(options),
|
|
11
|
-
reactStaticPlugin(options),
|
|
12
|
-
reactPreservePlugin(options),
|
|
13
|
-
];
|
|
14
|
-
}
|
|
1
|
+
export { reactServerPlugin } from "./plugin.js";
|