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,109 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { renderToPipeableStream } from "react-server-dom-esm/server.node";
|
|
4
|
-
import type { PipeableStreamOptions } from "../worker/types.js";
|
|
5
|
-
import type { Logger } from "vite";
|
|
6
|
-
import type {
|
|
7
|
-
CreateHandlerOptions,
|
|
8
|
-
CssCollectorProps,
|
|
9
|
-
CssContent,
|
|
10
|
-
InlineCssCollectorProps,
|
|
11
|
-
} from "../types.js";
|
|
12
|
-
|
|
13
|
-
export function createRscStream<InlineCSS extends boolean = true>({
|
|
14
|
-
Html,
|
|
15
|
-
Page,
|
|
16
|
-
props,
|
|
17
|
-
loader = (id) => import(id).then((m) => m.default),
|
|
18
|
-
moduleRootPath,
|
|
19
|
-
moduleBasePath,
|
|
20
|
-
moduleBaseURL,
|
|
21
|
-
logger,
|
|
22
|
-
cssFiles = [],
|
|
23
|
-
route,
|
|
24
|
-
url,
|
|
25
|
-
pipableStreamOptions,
|
|
26
|
-
htmlProps,
|
|
27
|
-
inlineCss = true as InlineCSS,
|
|
28
|
-
CssCollector,
|
|
29
|
-
root,
|
|
30
|
-
}: {
|
|
31
|
-
Html: CreateHandlerOptions["Html"];
|
|
32
|
-
Page: React.ComponentType<any>;
|
|
33
|
-
loader: (id: string) => Promise<any>;
|
|
34
|
-
props: any;
|
|
35
|
-
moduleBase: string;
|
|
36
|
-
moduleRootPath: string;
|
|
37
|
-
moduleBasePath: string;
|
|
38
|
-
moduleBaseURL: string;
|
|
39
|
-
logger: Logger;
|
|
40
|
-
route: string;
|
|
41
|
-
url: string;
|
|
42
|
-
pipableStreamOptions?: PipeableStreamOptions;
|
|
43
|
-
htmlProps?: any;
|
|
44
|
-
root: string;
|
|
45
|
-
inlineCss?: InlineCSS;
|
|
46
|
-
cssFiles?: (string | CssContent)[];
|
|
47
|
-
} & (InlineCSS extends true
|
|
48
|
-
? {
|
|
49
|
-
CssCollector: React.FC<InlineCssCollectorProps>;
|
|
50
|
-
}
|
|
51
|
-
: {
|
|
52
|
-
CssCollector: React.FC<CssCollectorProps>;
|
|
53
|
-
})) {
|
|
54
|
-
const htmlIsFragment = Html == React.Fragment;
|
|
55
|
-
if (!htmlIsFragment) {
|
|
56
|
-
if (!htmlProps) {
|
|
57
|
-
htmlProps = {};
|
|
58
|
-
}
|
|
59
|
-
if (!("moduleBaseURL" in htmlProps)) {
|
|
60
|
-
htmlProps["moduleBaseURL"] = moduleBaseURL;
|
|
61
|
-
}
|
|
62
|
-
if (!("moduleBasePath" in htmlProps)) {
|
|
63
|
-
htmlProps["moduleBasePath"] = moduleBasePath;
|
|
64
|
-
}
|
|
65
|
-
if (!("moduleRootPath" in htmlProps)) {
|
|
66
|
-
htmlProps["moduleRootPath"] = moduleRootPath;
|
|
67
|
-
}
|
|
68
|
-
if (!("url" in htmlProps)) {
|
|
69
|
-
htmlProps["url"] = url;
|
|
70
|
-
}
|
|
71
|
-
if (!("route" in htmlProps)) {
|
|
72
|
-
htmlProps["route"] = route;
|
|
73
|
-
}
|
|
74
|
-
if (!("pageProps" in htmlProps)) {
|
|
75
|
-
htmlProps["pageProps"] = props;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const withCss = React.createElement(
|
|
79
|
-
CssCollector as any,
|
|
80
|
-
(inlineCss === true
|
|
81
|
-
? {
|
|
82
|
-
cssFiles: cssFiles,
|
|
83
|
-
route,
|
|
84
|
-
moduleBaseURL,
|
|
85
|
-
moduleBasePath,
|
|
86
|
-
moduleRootPath,
|
|
87
|
-
root,
|
|
88
|
-
loader,
|
|
89
|
-
}
|
|
90
|
-
: { cssFiles: cssFiles, route, moduleBaseURL }) as any,
|
|
91
|
-
React.createElement(Page, props)
|
|
92
|
-
);
|
|
93
|
-
// Otherwise wrap with Html component
|
|
94
|
-
const content = htmlIsFragment
|
|
95
|
-
? withCss
|
|
96
|
-
: React.createElement(Html, htmlProps, withCss);
|
|
97
|
-
try {
|
|
98
|
-
return renderToPipeableStream(
|
|
99
|
-
content,
|
|
100
|
-
moduleBasePath,
|
|
101
|
-
pipableStreamOptions
|
|
102
|
-
);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
logger.error(`Failed to create stream for ${route}.`, {
|
|
105
|
-
error: error as Error,
|
|
106
|
-
});
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import { basename } from 'path';
|
|
3
|
-
import postcss from 'postcss';
|
|
4
|
-
import type { MessagePort } from 'node:worker_threads';
|
|
5
|
-
import type { CssFileMessage } from '../worker/types.js';
|
|
6
|
-
import type { LoadHookContext } from 'node:module';
|
|
7
|
-
|
|
8
|
-
type LoaderContext = {
|
|
9
|
-
data?: { port: MessagePort };
|
|
10
|
-
};
|
|
11
|
-
// Store port globally for CSS loader
|
|
12
|
-
let cssLoaderPort: MessagePort | undefined;
|
|
13
|
-
|
|
14
|
-
// Initialize hook
|
|
15
|
-
export async function initialize(data: { port: MessagePort }) {
|
|
16
|
-
cssLoaderPort = data.port; // Store port
|
|
17
|
-
data.port.postMessage({ type: 'INITIALIZED' });
|
|
18
|
-
data.port.unref();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// CSS file tracking per page
|
|
22
|
-
const cssFilesByPage = new Map<string, Set<string>>();
|
|
23
|
-
|
|
24
|
-
export function setCurrentPage(page: string | null) {
|
|
25
|
-
if (page && !cssFilesByPage.has(page)) {
|
|
26
|
-
cssFilesByPage.set(page, new Set());
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function getCssFilesForPage(page: string): string[] {
|
|
31
|
-
return Array.from(cssFilesByPage.get(page) || []);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Modify the CSS handling in the load function
|
|
35
|
-
export async function load(url: string, context: LoadHookContext & LoaderContext, defaultLoad: any) {
|
|
36
|
-
// Handle CSS files
|
|
37
|
-
if(url.endsWith(".css")) {
|
|
38
|
-
const source = await readFile(new URL(url), 'utf-8');
|
|
39
|
-
|
|
40
|
-
// Process CSS with PostCSS
|
|
41
|
-
const result = await postcss().process(source, {
|
|
42
|
-
from: url,
|
|
43
|
-
to: url,
|
|
44
|
-
map: {
|
|
45
|
-
inline: false,
|
|
46
|
-
annotation: false
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Generate both transformed CSS and class mappings
|
|
51
|
-
const moduleName = basename(url, '.css').replace('.', '_');
|
|
52
|
-
const classes: Record<string, string> = {};
|
|
53
|
-
|
|
54
|
-
// Transform selectors
|
|
55
|
-
result.root.walkRules(rule => {
|
|
56
|
-
const selector = rule.selector.replace('.', '');
|
|
57
|
-
const className = `${moduleName}_${selector}`;
|
|
58
|
-
classes[selector] = className;
|
|
59
|
-
rule.selector = `.${className}`;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Get transformed CSS using root.toString()
|
|
63
|
-
const transformedCss = result.root.toString();
|
|
64
|
-
|
|
65
|
-
// Send processed CSS to worker
|
|
66
|
-
if (cssLoaderPort) {
|
|
67
|
-
cssLoaderPort.postMessage({
|
|
68
|
-
type: 'CSS_FILE',
|
|
69
|
-
id: url,
|
|
70
|
-
cssFile: transformedCss
|
|
71
|
-
} satisfies CssFileMessage);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Return CSS module
|
|
75
|
-
const moduleSource = `
|
|
76
|
-
const styles = ${JSON.stringify(classes)};
|
|
77
|
-
export default styles;
|
|
78
|
-
export const css = ${JSON.stringify(transformedCss)};
|
|
79
|
-
`;
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
format: 'module',
|
|
83
|
-
source: moduleSource,
|
|
84
|
-
shortCircuit: true
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return defaultLoad(url, context, defaultLoad);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function resolve(specifier: string, context: any, defaultResolve: any) {
|
|
91
|
-
return defaultResolve(specifier, context, defaultResolve);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from "node:stream";
|
|
2
|
-
import { parentPort } from "node:worker_threads";
|
|
3
|
-
import type { HtmlRenderState, HtmlWorkerMessage } from "../types.js";
|
|
4
|
-
import * as ReactDOMServer from "react-dom/server";
|
|
5
|
-
import React from "react";
|
|
6
|
-
import {
|
|
7
|
-
createFromNodeStream,
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
} from "react-server-dom-esm/client.node";
|
|
10
|
-
|
|
11
|
-
// Track active renders and streams
|
|
12
|
-
const activeRenders = new Map<string, HtmlRenderState>();
|
|
13
|
-
const htmlContent = new Map<string, string>();
|
|
14
|
-
const htmlPromises = new Map<string, Promise<string>>();
|
|
15
|
-
export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
16
|
-
try {
|
|
17
|
-
switch (message.type) {
|
|
18
|
-
case "RSC_CHUNK": {
|
|
19
|
-
const { id, chunk, moduleRootPath, moduleBaseURL, htmlOutputPath, pipableStreamOptions } = message;
|
|
20
|
-
|
|
21
|
-
const render = activeRenders.get(id);
|
|
22
|
-
if (!render) {
|
|
23
|
-
activeRenders.set(id, {
|
|
24
|
-
chunks: [chunk],
|
|
25
|
-
id,
|
|
26
|
-
complete: false,
|
|
27
|
-
rendered: false,
|
|
28
|
-
moduleRootPath,
|
|
29
|
-
moduleBaseURL,
|
|
30
|
-
outDir: '',
|
|
31
|
-
htmlOutputPath: htmlOutputPath,
|
|
32
|
-
pipableStreamOptions: pipableStreamOptions,
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
render.chunks = [...render.chunks, chunk];
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
case "RSC_END": {
|
|
41
|
-
const { id } = message;
|
|
42
|
-
const render = activeRenders.get(id);
|
|
43
|
-
if (!render) {
|
|
44
|
-
throw new Error(`No render state found for ${id}`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Mark this render as complete
|
|
48
|
-
render.complete = true;
|
|
49
|
-
|
|
50
|
-
// Create a PassThrough stream to handle the chunks
|
|
51
|
-
const rscStream = new PassThrough();
|
|
52
|
-
|
|
53
|
-
// Write all chunks to the stream
|
|
54
|
-
for (const chunk of render.chunks) {
|
|
55
|
-
rscStream.write(chunk);
|
|
56
|
-
}
|
|
57
|
-
rscStream.end();
|
|
58
|
-
|
|
59
|
-
// Create React elements from stream
|
|
60
|
-
const reactElements = await createFromNodeStream(
|
|
61
|
-
rscStream,
|
|
62
|
-
render.moduleRootPath,
|
|
63
|
-
render.moduleBaseURL
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
// Create a promise that resolves when HTML is complete
|
|
67
|
-
const htmlPromise = new Promise<string>((resolve) => {
|
|
68
|
-
const collectStream = new PassThrough();
|
|
69
|
-
let html = '';
|
|
70
|
-
|
|
71
|
-
collectStream.on("data", (chunk) => {
|
|
72
|
-
html += chunk.toString();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
collectStream.on("end", () => {
|
|
76
|
-
resolve(html);
|
|
77
|
-
render.rendered = true;
|
|
78
|
-
parentPort?.postMessage({
|
|
79
|
-
type: "ALL_READY",
|
|
80
|
-
id,
|
|
81
|
-
html,
|
|
82
|
-
outputPath: render.htmlOutputPath,
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
// Render to pipeable stream
|
|
86
|
-
const stream = ReactDOMServer.renderToPipeableStream(
|
|
87
|
-
reactElements as React.ReactNode,
|
|
88
|
-
{
|
|
89
|
-
...render.pipableStreamOptions,
|
|
90
|
-
// Calculate relative paths based on route depth
|
|
91
|
-
bootstrapModules: render.pipableStreamOptions?.bootstrapModules?.map(path => {
|
|
92
|
-
if (!path) return path;
|
|
93
|
-
if(render.moduleBaseURL && render.moduleBaseURL !== '') {
|
|
94
|
-
return new URL(path, render.moduleBaseURL).toString();
|
|
95
|
-
}
|
|
96
|
-
const depth = id.split('/').filter(Boolean).length;
|
|
97
|
-
const prefix = depth > 0 ? '../'.repeat(depth) : '/';
|
|
98
|
-
return path.startsWith('/') ? prefix + path.slice(1) : prefix + path;
|
|
99
|
-
}),
|
|
100
|
-
onShellReady() {
|
|
101
|
-
parentPort?.postMessage({ type: "SHELL_READY", id });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// Pipe to collection stream
|
|
107
|
-
stream.pipe(collectStream);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
htmlPromises.set(id, htmlPromise);
|
|
111
|
-
|
|
112
|
-
// Clean up resources
|
|
113
|
-
rscStream.destroy();
|
|
114
|
-
activeRenders.delete(id);
|
|
115
|
-
htmlContent.delete(id);
|
|
116
|
-
htmlPromises.delete(id);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
case "SHUTDOWN": {
|
|
121
|
-
console.log('Received shutdown signal');
|
|
122
|
-
parentPort?.close();
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error('Error in messageHandler:', error);
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
import { Transform } from "node:stream";
|
|
4
|
-
import type { Worker } from "node:worker_threads";
|
|
5
|
-
import { createHandler } from "../../helpers/createHandler.js";
|
|
6
|
-
import type {
|
|
7
|
-
CheckFilesExistReturn,
|
|
8
|
-
CreateHandlerOptions,
|
|
9
|
-
PageData,
|
|
10
|
-
} from "../../types.js";
|
|
11
|
-
import type { HtmlWorkerResponse } from "../types.js";
|
|
12
|
-
import { type Manifest, type IndexHtmlTransformHook, createLogger } from "vite";
|
|
13
|
-
import React from "react";
|
|
14
|
-
import { collectManifestClientFiles } from "../../collect-manifest-client-files.js";
|
|
15
|
-
|
|
16
|
-
type RenderPagesOptions<T = any> = Omit<CreateHandlerOptions<T>, "url" | "route" | "getCss" | "propsPath" | "pagePath"> & {
|
|
17
|
-
clientManifest: Manifest;
|
|
18
|
-
serverManifest: Manifest;
|
|
19
|
-
worker: Worker;
|
|
20
|
-
loader: (id: string) => Promise<Record<string, any>>;
|
|
21
|
-
onCssFile?: (url: string, parentUrl: string) => void;
|
|
22
|
-
onClientJSFile?: (url: string, parentUrl: string) => void;
|
|
23
|
-
onPage?: (pageData: PageData) => Promise<void>;
|
|
24
|
-
clientCss?: string[];
|
|
25
|
-
transformIndexHtml: IndexHtmlTransformHook;
|
|
26
|
-
outDir: string;
|
|
27
|
-
htmlOutputPath: string;
|
|
28
|
-
server?: any;
|
|
29
|
-
bundle?: any;
|
|
30
|
-
chunk?: any;
|
|
31
|
-
originalUrl?: string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export async function renderPages<T = any>(
|
|
35
|
-
routes: string[],
|
|
36
|
-
files: CheckFilesExistReturn,
|
|
37
|
-
options: RenderPagesOptions<T>
|
|
38
|
-
) {
|
|
39
|
-
const failedRoutes = new Map<string, Error>();
|
|
40
|
-
const completedRoutes = new Set<string>();
|
|
41
|
-
const clientCss = options.clientCss ?? [];
|
|
42
|
-
const partialPageData = new Map<string, Partial<PageData>>();
|
|
43
|
-
const moduleRootPath =
|
|
44
|
-
options.moduleBasePath !== "" &&
|
|
45
|
-
!options.moduleRootPath.endsWith(options.moduleBasePath)
|
|
46
|
-
? join(options.moduleRootPath, options.moduleBasePath)
|
|
47
|
-
: options.moduleRootPath;
|
|
48
|
-
const mergeAndSendPageData = async (route: string, resolve: () => void) => {
|
|
49
|
-
const partial = partialPageData.get(route);
|
|
50
|
-
if (!partial?.html || !partial.rsc) {
|
|
51
|
-
return; // Wait for both parts
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const pageData: PageData = {
|
|
55
|
-
route,
|
|
56
|
-
html: partial.html,
|
|
57
|
-
rsc: partial.rsc,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Write HTML file
|
|
61
|
-
let routeHtmlPath =
|
|
62
|
-
route === "/"
|
|
63
|
-
? options.htmlOutputPath
|
|
64
|
-
: options.htmlOutputPath.replace(
|
|
65
|
-
"index.html",
|
|
66
|
-
join(route, "index.html")
|
|
67
|
-
);
|
|
68
|
-
if (routeHtmlPath.startsWith("/")) {
|
|
69
|
-
routeHtmlPath = routeHtmlPath.slice(1);
|
|
70
|
-
}
|
|
71
|
-
const routeRscPath = routeHtmlPath.slice(0, -5) + ".rsc";
|
|
72
|
-
await mkdir(dirname(routeHtmlPath), { recursive: true });
|
|
73
|
-
await writeFile(routeRscPath, partial.rsc.content);
|
|
74
|
-
await writeFile(routeHtmlPath, partial.html.raw);
|
|
75
|
-
|
|
76
|
-
await options.onPage?.(pageData);
|
|
77
|
-
completedRoutes.add(route);
|
|
78
|
-
if (completedRoutes.size === routes.length) {
|
|
79
|
-
resolve();
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
// Set up worker message handling
|
|
85
|
-
const allRoutesComplete = new Promise<void>((resolve, reject) => {
|
|
86
|
-
options.worker.on("message", async (msg: HtmlWorkerResponse) => {
|
|
87
|
-
switch (msg.type) {
|
|
88
|
-
case "ALL_READY": {
|
|
89
|
-
const { id, html } = msg;
|
|
90
|
-
try {
|
|
91
|
-
const partial = partialPageData.get(id) || { route: id };
|
|
92
|
-
|
|
93
|
-
partial.html = {
|
|
94
|
-
raw: html,
|
|
95
|
-
transformed:
|
|
96
|
-
typeof options.transformIndexHtml === "function"
|
|
97
|
-
? String(await options.transformIndexHtml(id, {
|
|
98
|
-
path: id,
|
|
99
|
-
filename: join(id, "index.html"),
|
|
100
|
-
}) || "")
|
|
101
|
-
: "", // Will be set by main thread transform
|
|
102
|
-
assets: [],
|
|
103
|
-
};
|
|
104
|
-
partialPageData.set(id, partial);
|
|
105
|
-
await mergeAndSendPageData(id, resolve);
|
|
106
|
-
} catch (error) {
|
|
107
|
-
failedRoutes.set(id, error as Error);
|
|
108
|
-
reject(error);
|
|
109
|
-
}
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case "ERROR": {
|
|
113
|
-
console.error("Worker error for route:", msg.id, msg.error);
|
|
114
|
-
failedRoutes.set(msg.id, new Error(msg.error));
|
|
115
|
-
reject(new Error(msg.error));
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// Process routes sequentially
|
|
123
|
-
for (const route of routes) {
|
|
124
|
-
const routeFiles = files.urlMap.get(route);
|
|
125
|
-
if (!routeFiles) {
|
|
126
|
-
console.error("No files found for route:", route);
|
|
127
|
-
failedRoutes.set(route, new Error(`No files found for ${route}`));
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (options.pipableStreamOptions?.importMap?.imports) {
|
|
132
|
-
for (let [, value] of Object.entries(
|
|
133
|
-
options.pipableStreamOptions?.importMap?.imports
|
|
134
|
-
)) {
|
|
135
|
-
options.onClientJSFile?.(value, route);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const getCss = async (id: string) => {
|
|
139
|
-
const cssFiles = collectManifestClientFiles({
|
|
140
|
-
manifest: options.serverManifest,
|
|
141
|
-
root: options.root,
|
|
142
|
-
pagePath: id,
|
|
143
|
-
}).cssFiles;
|
|
144
|
-
return cssFiles;
|
|
145
|
-
}
|
|
146
|
-
const pagePath = files.urlMap.get(route)?.page;
|
|
147
|
-
const propsPath = files.urlMap.get(route)?.props;
|
|
148
|
-
if(!pagePath){
|
|
149
|
-
throw new Error(`No page path found for ${route}`);
|
|
150
|
-
}
|
|
151
|
-
// Create handler for pure RSC output
|
|
152
|
-
const rscResult = await createHandler({
|
|
153
|
-
root: options.root,
|
|
154
|
-
url: route,
|
|
155
|
-
route: route,
|
|
156
|
-
getCss: getCss,
|
|
157
|
-
loader: options.loader,
|
|
158
|
-
cssFiles: clientCss,
|
|
159
|
-
moduleBase: options.moduleBase,
|
|
160
|
-
moduleBasePath: options.moduleBasePath,
|
|
161
|
-
moduleRootPath: moduleRootPath,
|
|
162
|
-
moduleBaseURL: options.moduleBaseURL,
|
|
163
|
-
pipableStreamOptions: options.pipableStreamOptions ?? {},
|
|
164
|
-
inlineCss: options.inlineCss,
|
|
165
|
-
Html: React.Fragment,
|
|
166
|
-
CssCollector: options.CssCollector,
|
|
167
|
-
pagePath: pagePath,
|
|
168
|
-
propsPath: propsPath,
|
|
169
|
-
pageExportName: options.pageExportName,
|
|
170
|
-
propsExportName: options.propsExportName,
|
|
171
|
-
logger: createLogger(),
|
|
172
|
-
});
|
|
173
|
-
// Create handler for HTML output
|
|
174
|
-
const htmlResult = await createHandler({
|
|
175
|
-
root: options.root,
|
|
176
|
-
url: route,
|
|
177
|
-
route: route,
|
|
178
|
-
getCss: getCss,
|
|
179
|
-
loader: options.loader,
|
|
180
|
-
cssFiles: clientCss,
|
|
181
|
-
moduleBase: options.moduleBase,
|
|
182
|
-
moduleBasePath: options.moduleBasePath,
|
|
183
|
-
moduleRootPath: moduleRootPath,
|
|
184
|
-
moduleBaseURL: options.moduleBaseURL,
|
|
185
|
-
pipableStreamOptions: options.pipableStreamOptions,
|
|
186
|
-
inlineCss: options.inlineCss,
|
|
187
|
-
Html: options.Html,
|
|
188
|
-
CssCollector: options.CssCollector,
|
|
189
|
-
pagePath: pagePath,
|
|
190
|
-
propsPath: propsPath,
|
|
191
|
-
pageExportName: options.pageExportName,
|
|
192
|
-
propsExportName: options.propsExportName,
|
|
193
|
-
logger: createLogger(),
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
if (rscResult.type !== "success" || htmlResult.type !== "success") {
|
|
197
|
-
if (rscResult.type !== "success") {
|
|
198
|
-
if (rscResult.type !== "skip") {
|
|
199
|
-
console.error("Handler failed for route:", route, rscResult.error);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (htmlResult.type !== "success") {
|
|
203
|
-
if (htmlResult.type !== "skip") {
|
|
204
|
-
console.error("Handler failed for route:", route, htmlResult.error);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
failedRoutes.set(route, new Error(`Handler failed for ${route}`));
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Process both streams
|
|
212
|
-
await Promise.all([
|
|
213
|
-
// Handle RSC stream
|
|
214
|
-
new Promise<void>((resolve, reject) => {
|
|
215
|
-
const chunks: Buffer[] = [];
|
|
216
|
-
const rscTransform = new Transform({
|
|
217
|
-
transform(chunk, _encoding, callback) {
|
|
218
|
-
try {
|
|
219
|
-
if (chunk) {
|
|
220
|
-
chunks.push(Buffer.from(chunk));
|
|
221
|
-
callback(null, chunk);
|
|
222
|
-
}
|
|
223
|
-
} catch (error) {
|
|
224
|
-
callback(error as Error);
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
async flush(callback) {
|
|
228
|
-
try {
|
|
229
|
-
const rscContent = Buffer.concat(chunks).toString("utf-8");
|
|
230
|
-
|
|
231
|
-
// Update partial page data with raw RSC content
|
|
232
|
-
const partial = partialPageData.get(route) || { route };
|
|
233
|
-
partial.rsc = {
|
|
234
|
-
modules: [], // Will be parsed by the client
|
|
235
|
-
content: rscContent,
|
|
236
|
-
};
|
|
237
|
-
partialPageData.set(route, partial);
|
|
238
|
-
await mergeAndSendPageData(route, resolve);
|
|
239
|
-
|
|
240
|
-
callback();
|
|
241
|
-
resolve();
|
|
242
|
-
} catch (error) {
|
|
243
|
-
callback(error as Error);
|
|
244
|
-
reject(error);
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
rscResult.stream.pipe(rscTransform);
|
|
250
|
-
}),
|
|
251
|
-
|
|
252
|
-
// Send HTML stream to worker
|
|
253
|
-
new Promise<void>((resolve) => {
|
|
254
|
-
const htmlTransform = new Transform({
|
|
255
|
-
transform(chunk, _encoding, callback) {
|
|
256
|
-
try {
|
|
257
|
-
options.worker.postMessage({
|
|
258
|
-
type: "RSC_CHUNK",
|
|
259
|
-
id: route,
|
|
260
|
-
chunk: chunk.toString(),
|
|
261
|
-
moduleRootPath: moduleRootPath,
|
|
262
|
-
moduleBaseURL: options.moduleBaseURL,
|
|
263
|
-
htmlOutputPath: options.htmlOutputPath,
|
|
264
|
-
pipableStreamOptions: options.pipableStreamOptions,
|
|
265
|
-
});
|
|
266
|
-
callback(null, chunk);
|
|
267
|
-
} catch (error) {
|
|
268
|
-
callback(error as Error);
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
flush(callback) {
|
|
272
|
-
options.worker.postMessage({
|
|
273
|
-
type: "RSC_END",
|
|
274
|
-
id: route,
|
|
275
|
-
});
|
|
276
|
-
callback();
|
|
277
|
-
resolve();
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
htmlResult.stream.pipe(htmlTransform);
|
|
282
|
-
}),
|
|
283
|
-
]);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
await allRoutesComplete;
|
|
287
|
-
} catch (error) {
|
|
288
|
-
console.error("Render error:", error);
|
|
289
|
-
throw error;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return { failedRoutes, completedRoutes };
|
|
293
|
-
}
|