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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { workerData } from "node:worker_threads";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const projectRoot = workerData?.projectRoot || process.cwd();
|
|
6
|
+
const nodeRequire = createRequire(join(projectRoot, "package.json"));
|
|
7
|
+
|
|
8
|
+
// Import ReactDOM from the project's node_modules
|
|
9
|
+
const ReactDOMServer = nodeRequire("react-dom/server");
|
|
10
|
+
const React = nodeRequire("react");
|
|
11
|
+
|
|
12
|
+
export { ReactDOMServer, React };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { workerData } from "node:worker_threads";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const projectRoot = workerData?.projectRoot || process.env["npm_config_local_prefix"] || process.cwd();
|
|
6
|
+
const nodeRequire = createRequire(join(projectRoot, "package.json"));
|
|
7
|
+
|
|
8
|
+
// Import ReactDOM from the project's node_modules
|
|
9
|
+
const ReactDOMServer = nodeRequire("react-server-dom-esm/server");
|
|
10
|
+
const React = nodeRequire("react");
|
|
11
|
+
|
|
12
|
+
export { ReactDOMServer, React };
|
|
@@ -1,83 +1,188 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Worker,
|
|
3
|
+
type ResourceLimits,
|
|
4
|
+
type TransferListItem
|
|
5
|
+
} from "node:worker_threads";
|
|
2
6
|
import { getMode, getNodePath } from "../config/getPaths.js";
|
|
3
7
|
import { getCondition } from "../config/getCondition.js";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { pluginRoot } from "../root.js";
|
|
10
|
+
import * as React from "react";
|
|
4
11
|
|
|
5
|
-
type CreateWorkerOptions = {
|
|
12
|
+
export type CreateWorkerOptions = {
|
|
6
13
|
projectRoot?: string;
|
|
7
|
-
|
|
14
|
+
currentCondition?: "react-server" | "react-client";
|
|
8
15
|
nodePath?: string;
|
|
9
|
-
nodeOptions?: string;
|
|
16
|
+
nodeOptions?: string[];
|
|
10
17
|
mode?: "production" | "development";
|
|
11
|
-
reverseCondition?:
|
|
18
|
+
reverseCondition?: string;
|
|
12
19
|
maxListeners?: number;
|
|
13
|
-
workerPath
|
|
20
|
+
workerPath?: string;
|
|
14
21
|
resourceLimits?: ResourceLimits;
|
|
15
22
|
typescript?: boolean;
|
|
23
|
+
htmlChunkSize?: number; // Size of HTML chunks in bytes
|
|
24
|
+
workerData?: any;
|
|
25
|
+
transferList?: TransferListItem[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type CreateWorkerSuccess = {
|
|
29
|
+
type: "success";
|
|
30
|
+
workerPath: string;
|
|
31
|
+
worker: Worker;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type CreateWorkerError = {
|
|
35
|
+
type: "error";
|
|
36
|
+
workerPath: string;
|
|
37
|
+
error: Error;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type CreateWorkerSkip = {
|
|
41
|
+
type: "skip";
|
|
42
|
+
reason: string;
|
|
43
|
+
workerPath: string;
|
|
16
44
|
};
|
|
17
45
|
|
|
18
|
-
export async function createWorker(
|
|
46
|
+
export async function createWorker(
|
|
47
|
+
options: CreateWorkerOptions
|
|
48
|
+
): Promise<CreateWorkerSuccess | CreateWorkerError | CreateWorkerSkip> {
|
|
19
49
|
const {
|
|
20
50
|
projectRoot = process.cwd(),
|
|
21
51
|
nodePath = getNodePath(projectRoot),
|
|
22
|
-
|
|
23
|
-
reverseCondition =
|
|
52
|
+
currentCondition = getCondition(),
|
|
53
|
+
reverseCondition = currentCondition === "react-server"
|
|
54
|
+
? "react-client"
|
|
55
|
+
: "react-server",
|
|
24
56
|
maxListeners = 100,
|
|
25
57
|
mode = getMode(),
|
|
26
58
|
workerPath,
|
|
27
59
|
resourceLimits = {
|
|
28
|
-
maxOldGenerationSizeMb:
|
|
29
|
-
maxYoungGenerationSizeMb:
|
|
60
|
+
maxOldGenerationSizeMb: 128,
|
|
61
|
+
maxYoungGenerationSizeMb: 64,
|
|
30
62
|
},
|
|
63
|
+
htmlChunkSize = 8 * 1024,
|
|
64
|
+
transferList = []
|
|
31
65
|
} = options;
|
|
66
|
+
let workerPathWithDefault =
|
|
67
|
+
typeof workerPath === "string" ? workerPath : undefined;
|
|
68
|
+
if (!workerPathWithDefault) {
|
|
69
|
+
if (currentCondition === "react-server") {
|
|
70
|
+
workerPathWithDefault = join(pluginRoot, `worker/rsc`);
|
|
71
|
+
} else {
|
|
72
|
+
workerPathWithDefault = join(pluginRoot, `worker/html`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!workerPathWithDefault.startsWith("/")) {
|
|
76
|
+
workerPathWithDefault = join("./", workerPathWithDefault);
|
|
77
|
+
}
|
|
78
|
+
// Ensure worker uses the same React version
|
|
79
|
+
const workerData = {
|
|
80
|
+
...options.workerData,
|
|
81
|
+
importMeta: {
|
|
82
|
+
env: {
|
|
83
|
+
DEV: mode === 'development' ? 'true' : 'false',
|
|
84
|
+
MODE: mode,
|
|
85
|
+
PROD: mode === 'production' ? 'true' : 'false',
|
|
86
|
+
SSR: true,
|
|
87
|
+
BASE_URL: '/',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
reactVersion: React.version,
|
|
91
|
+
};
|
|
32
92
|
|
|
33
|
-
|
|
34
|
-
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
35
|
-
const nodeEnv = isTestEnv ? "development" : mode;
|
|
93
|
+
try {
|
|
36
94
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
// Ensure consistent NODE_ENV between main thread and worker
|
|
96
|
+
const isTestEnv =
|
|
97
|
+
process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
98
|
+
const nodeEnv = isTestEnv ? "test" : mode;
|
|
99
|
+
|
|
100
|
+
const env = {
|
|
101
|
+
...process.env,
|
|
102
|
+
BASE_URL: '/',
|
|
103
|
+
VITE_DEV: mode === 'development' ? '1' : '0',
|
|
104
|
+
VITE_MODE: mode,
|
|
105
|
+
VITE_PROD: mode === 'production' ? '1' : '0',
|
|
106
|
+
VITE_SSR: 'true',
|
|
107
|
+
VITE_BASE_URL: '/',
|
|
108
|
+
NODE_ENV: nodeEnv,
|
|
109
|
+
NODE_PATH: nodePath,
|
|
110
|
+
NODE_OPTIONS: process.env["NODE_OPTIONS"]?.includes(reverseCondition)
|
|
111
|
+
? process.env["NODE_OPTIONS"]
|
|
112
|
+
: process.env["NODE_OPTIONS"]?.includes(currentCondition)
|
|
113
|
+
? process.env["NODE_OPTIONS"]?.replace(
|
|
114
|
+
currentCondition,
|
|
115
|
+
reverseCondition
|
|
116
|
+
)
|
|
117
|
+
: `${
|
|
118
|
+
process.env["NODE_OPTIONS"] ?? ""
|
|
119
|
+
} --conditions ${reverseCondition}`,
|
|
120
|
+
HTML_CHUNK_SIZE: htmlChunkSize.toString(),
|
|
121
|
+
};
|
|
53
122
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
workerPath.startsWith("/") ? workerPath : './' + workerPath,
|
|
57
|
-
{
|
|
123
|
+
// Create worker with proper environment and loaders
|
|
124
|
+
const worker = new Worker(workerPathWithDefault, {
|
|
58
125
|
env,
|
|
59
126
|
resourceLimits,
|
|
60
|
-
|
|
61
|
-
|
|
127
|
+
workerData,
|
|
128
|
+
transferList,
|
|
129
|
+
});
|
|
62
130
|
|
|
63
|
-
|
|
131
|
+
worker.setMaxListeners(maxListeners);
|
|
64
132
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
133
|
+
// Wait for worker to be ready
|
|
134
|
+
return await new Promise<CreateWorkerSuccess | CreateWorkerSkip>(
|
|
135
|
+
(resolve, reject) => {
|
|
136
|
+
const timeout = setTimeout(() => {
|
|
137
|
+
reject({ type: "error", error: new Error("Worker ready timeout") });
|
|
138
|
+
}, 5000);
|
|
70
139
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
140
|
+
worker.once("message", (msg) => {
|
|
141
|
+
if (msg.type === "READY") {
|
|
142
|
+
clearTimeout(timeout);
|
|
143
|
+
if(msg.env !== nodeEnv) {
|
|
144
|
+
reject({
|
|
145
|
+
type: "error",
|
|
146
|
+
error: new Error(`Worker environment mismatch: ${msg.env} !== ${nodeEnv}`),
|
|
147
|
+
workerPath: workerPathWithDefault,
|
|
148
|
+
} satisfies CreateWorkerError);
|
|
149
|
+
}
|
|
150
|
+
resolve({
|
|
151
|
+
type: "success",
|
|
152
|
+
worker,
|
|
153
|
+
workerPath: workerPathWithDefault,
|
|
154
|
+
} satisfies CreateWorkerSuccess);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
77
157
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
158
|
+
worker.once("exit", (code) => {
|
|
159
|
+
clearTimeout(timeout);
|
|
160
|
+
worker.removeAllListeners();
|
|
161
|
+
if (code === 0) {
|
|
162
|
+
resolve({
|
|
163
|
+
type: "skip",
|
|
164
|
+
reason: "Worker exited with code 0",
|
|
165
|
+
workerPath: workerPathWithDefault,
|
|
166
|
+
} satisfies CreateWorkerSkip);
|
|
167
|
+
} else {
|
|
168
|
+
reject({
|
|
169
|
+
type: "error",
|
|
170
|
+
error: new Error(`Worker exited with code ${code}`),
|
|
171
|
+
workerPath: workerPathWithDefault,
|
|
172
|
+
} satisfies CreateWorkerError);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof Error) {
|
|
179
|
+
return {
|
|
180
|
+
type: "error",
|
|
181
|
+
workerPath: workerPathWithDefault,
|
|
182
|
+
error: error,
|
|
183
|
+
} satisfies CreateWorkerError;
|
|
184
|
+
}
|
|
185
|
+
return error as CreateWorkerError;
|
|
186
|
+
}
|
|
83
187
|
}
|
|
188
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { HtmlWorkerRenderState } from "./types.js";
|
|
2
|
+
import { PassThrough } from "stream";
|
|
3
|
+
import { workerData } from "node:worker_threads";
|
|
4
|
+
import type { AllReadyMessage, SerializeableRenderToPipeableStreamOptions } from "../types.js";
|
|
5
|
+
import { type ErrorInfo } from "react";
|
|
6
|
+
import { createFromNodeStream } from "react-server-dom-esm/client.node";
|
|
7
|
+
import { Transform } from "node:stream";
|
|
8
|
+
import type { HtmlWorkerOutputMessage } from "../types.js";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import type { StreamMetrics } from "../../types.js";
|
|
11
|
+
import { ReactDOMServer } from "../../vendor.client.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const createMetrics = (): StreamMetrics => {
|
|
15
|
+
return {
|
|
16
|
+
chunks: 0,
|
|
17
|
+
bytes: 0,
|
|
18
|
+
backpressureCount: 0,
|
|
19
|
+
drainCount: 0,
|
|
20
|
+
errorCount: 0,
|
|
21
|
+
duration: 0,
|
|
22
|
+
startTime: 0,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export function createHtmlWorkerRenderState(
|
|
26
|
+
{
|
|
27
|
+
projectRoot = workerData.userOptions.projectRoot,
|
|
28
|
+
moduleRootPath = workerData.userOptions.moduleRootPath,
|
|
29
|
+
moduleBaseURL = workerData.userOptions.moduleBaseURL,
|
|
30
|
+
pipeableStreamOptions = workerData.userOptions.pipeableStreamOptions,
|
|
31
|
+
id = workerData.id,
|
|
32
|
+
}: {
|
|
33
|
+
projectRoot?: string;
|
|
34
|
+
moduleRootPath?: string;
|
|
35
|
+
moduleBaseURL?: string;
|
|
36
|
+
pipeableStreamOptions?: SerializeableRenderToPipeableStreamOptions;
|
|
37
|
+
id?: string;
|
|
38
|
+
},
|
|
39
|
+
sendMessage: (msg: HtmlWorkerOutputMessage) => void,
|
|
40
|
+
rscStream = new PassThrough()
|
|
41
|
+
): HtmlWorkerRenderState {
|
|
42
|
+
if (typeof moduleRootPath !== "string") {
|
|
43
|
+
throw new Error("moduleRootPath is required");
|
|
44
|
+
} else if (!moduleRootPath.startsWith(projectRoot)) {
|
|
45
|
+
moduleRootPath = join(projectRoot, moduleRootPath);
|
|
46
|
+
}
|
|
47
|
+
const elements = createFromNodeStream(rscStream, moduleRootPath, moduleBaseURL);
|
|
48
|
+
const metrics = createMetrics();
|
|
49
|
+
const htmlTransform = new Transform({
|
|
50
|
+
transform(chunk, encoding, callback) {
|
|
51
|
+
metrics.chunks++;
|
|
52
|
+
metrics.bytes += chunk.length;
|
|
53
|
+
|
|
54
|
+
// Send HTML chunks
|
|
55
|
+
sendMessage({
|
|
56
|
+
type: "HTML_CHUNK",
|
|
57
|
+
id: id,
|
|
58
|
+
chunk: chunk,
|
|
59
|
+
encoding,
|
|
60
|
+
} satisfies HtmlWorkerOutputMessage);
|
|
61
|
+
callback();
|
|
62
|
+
},
|
|
63
|
+
flush(callback) {
|
|
64
|
+
sendMessage({
|
|
65
|
+
type: "HTML_COMPLETE",
|
|
66
|
+
id,
|
|
67
|
+
success: true,
|
|
68
|
+
metrics: metrics,
|
|
69
|
+
});
|
|
70
|
+
callback();
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
const stream = ReactDOMServer.renderToPipeableStream(elements, {
|
|
74
|
+
...pipeableStreamOptions,
|
|
75
|
+
onAllReady: () => {
|
|
76
|
+
rscStream.end();
|
|
77
|
+
sendMessage({
|
|
78
|
+
type: "ALL_READY",
|
|
79
|
+
id,
|
|
80
|
+
} satisfies AllReadyMessage);
|
|
81
|
+
},
|
|
82
|
+
onError: (error: unknown, errorInfo: ErrorInfo) => {
|
|
83
|
+
sendMessage({
|
|
84
|
+
type: "ERROR",
|
|
85
|
+
id,
|
|
86
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
87
|
+
errorInfo: errorInfo,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
onShellReady: () => {
|
|
91
|
+
sendMessage({
|
|
92
|
+
type: "SHELL_READY",
|
|
93
|
+
id,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
onShellError: (error: unknown) => {
|
|
97
|
+
sendMessage({
|
|
98
|
+
type: "SHELL_ERROR",
|
|
99
|
+
id,
|
|
100
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
stream.pipe(htmlTransform);
|
|
105
|
+
return {
|
|
106
|
+
rscStream: rscStream,
|
|
107
|
+
metrics,
|
|
108
|
+
isReady: false,
|
|
109
|
+
htmlTransform: htmlTransform,
|
|
110
|
+
stream: stream,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -1,95 +1,25 @@
|
|
|
1
|
-
// no offical types for node:module available yet (23.7.0)
|
|
2
|
-
declare module "node:module" {
|
|
3
|
-
export interface ImportAttributes {
|
|
4
|
-
[key: string]: string | undefined;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface ResolveHookContext {
|
|
8
|
-
conditions: string[];
|
|
9
|
-
parentURL: string | undefined;
|
|
10
|
-
importAttributes: ImportAttributes;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface LoadHookContext {
|
|
14
|
-
conditions: string[];
|
|
15
|
-
format: ModuleFormat | null | undefined;
|
|
16
|
-
importAttributes: ImportAttributes;
|
|
17
|
-
shortCircuit?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ResolveResult {
|
|
21
|
-
url: string;
|
|
22
|
-
shortCircuit: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface LoadResult {
|
|
26
|
-
format: string;
|
|
27
|
-
source: string | SharedArrayBuffer | Uint8Array;
|
|
28
|
-
shortCircuit: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface HooksAPI {
|
|
32
|
-
resolve?: (
|
|
33
|
-
specifier: string,
|
|
34
|
-
context: ResolveHookContext,
|
|
35
|
-
nextResolve: (
|
|
36
|
-
specifier: string,
|
|
37
|
-
context: ResolveHookContext
|
|
38
|
-
) => ResolveResult
|
|
39
|
-
) => ResolveResult;
|
|
40
|
-
|
|
41
|
-
load?: (
|
|
42
|
-
url: string,
|
|
43
|
-
context: LoadHookContext,
|
|
44
|
-
nextLoad: (url: string, context: LoadHookContext) => LoadResult
|
|
45
|
-
) => LoadResult;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function registerHooks(hooks: HooksAPI): void;
|
|
49
|
-
}
|
|
50
1
|
import { join } from "node:path";
|
|
51
|
-
import { pluginRoot } from "../../root.js";
|
|
52
2
|
import { messageHandler } from "./messageHandler.js";
|
|
53
|
-
import { parentPort } from "node:worker_threads";
|
|
3
|
+
import { MessageChannel, parentPort } from "node:worker_threads";
|
|
4
|
+
import { pluginRoot } from "../../root.js";
|
|
54
5
|
import { register } from "node:module";
|
|
55
|
-
import { register as registerTsx } from "tsx/esm/api";
|
|
56
|
-
import { MessageChannel } from "node:worker_threads";
|
|
57
|
-
|
|
58
|
-
if (!parentPort) throw new Error("This module must be run as a worker");
|
|
59
6
|
|
|
60
7
|
// Create channels for each loader
|
|
61
|
-
const reactLoaderChannel = new MessageChannel();
|
|
62
8
|
const cssLoaderChannel = new MessageChannel();
|
|
63
|
-
|
|
64
|
-
// Listen for messages from loaders
|
|
65
|
-
reactLoaderChannel.port2.on("message", messageHandler);
|
|
66
9
|
cssLoaderChannel.port2.on("message", messageHandler);
|
|
67
10
|
|
|
68
|
-
const
|
|
69
|
-
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.js");
|
|
70
|
-
|
|
71
|
-
// Register react-loader
|
|
72
|
-
register(loaderPath, {
|
|
73
|
-
parentURL: pluginRoot,
|
|
74
|
-
data: { port: reactLoaderChannel.port1 },
|
|
75
|
-
transferList: [reactLoaderChannel.port1],
|
|
76
|
-
});
|
|
11
|
+
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
|
|
77
12
|
register(cssLoaderPath, {
|
|
78
13
|
parentURL: pluginRoot,
|
|
79
14
|
data: { port: cssLoaderChannel.port1 },
|
|
80
15
|
transferList: [cssLoaderChannel.port1],
|
|
81
16
|
});
|
|
82
17
|
|
|
83
|
-
|
|
84
|
-
registerTsx();
|
|
18
|
+
|
|
85
19
|
// Signal ready with environment
|
|
86
20
|
parentPort?.on("message", messageHandler);
|
|
87
21
|
parentPort?.postMessage({
|
|
88
22
|
type: "READY",
|
|
89
23
|
env: process.env["NODE_ENV"],
|
|
90
24
|
pid: process.pid,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (process.env["NODE_ENV"] !== "development") {
|
|
94
|
-
throw new Error("This module must be run in development mode");
|
|
95
|
-
}
|
|
25
|
+
});
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
1
2
|
import { messageHandler } from "./messageHandler.js";
|
|
2
|
-
import { parentPort } from "node:worker_threads";
|
|
3
|
+
import { MessageChannel, parentPort } from "node:worker_threads";
|
|
4
|
+
import { pluginRoot } from "../../root.js";
|
|
5
|
+
import { register } from "node:module";
|
|
6
|
+
|
|
7
|
+
// Create channels for each loader
|
|
8
|
+
const cssLoaderChannel = new MessageChannel();
|
|
9
|
+
|
|
10
|
+
cssLoaderChannel.port2.on("message", messageHandler);
|
|
11
|
+
|
|
12
|
+
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.production.js");
|
|
13
|
+
|
|
14
|
+
register(cssLoaderPath, {
|
|
15
|
+
parentURL: pluginRoot,
|
|
16
|
+
data: { port: cssLoaderChannel.port1 },
|
|
17
|
+
transferList: [cssLoaderChannel.port1],
|
|
18
|
+
});
|
|
3
19
|
|
|
4
|
-
if (!parentPort) throw new Error("This module must be run as a worker");
|
|
5
20
|
|
|
6
21
|
// Signal ready with environment
|
|
7
22
|
parentPort?.on("message", messageHandler);
|
|
@@ -9,8 +24,4 @@ parentPort?.postMessage({
|
|
|
9
24
|
type: "READY",
|
|
10
25
|
env: process.env["NODE_ENV"],
|
|
11
26
|
pid: process.pid,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
15
|
-
throw new Error("This module must be run in development mode");
|
|
16
|
-
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { parentPort } from "node:worker_threads";
|
|
2
|
+
import type {
|
|
3
|
+
HtmlWorkerInputMessage,
|
|
4
|
+
HtmlWorkerOutputMessage,
|
|
5
|
+
} from "../types.js";
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import * as ReactDOMServer from "react-dom/server.node";
|
|
8
|
+
import type { HtmlWorkerRenderState } from "./types.js";
|
|
9
|
+
import { createHtmlWorkerRenderState } from "./createHtmlWorkerRenderState.js";
|
|
10
|
+
|
|
11
|
+
// Track active renders
|
|
12
|
+
const activeRenders = new Map<string, HtmlWorkerRenderState>();
|
|
13
|
+
|
|
14
|
+
function sendMessage(msg: HtmlWorkerOutputMessage) {
|
|
15
|
+
// Send the original message
|
|
16
|
+
if ("error" in msg && msg.error instanceof Error) {
|
|
17
|
+
parentPort?.postMessage({
|
|
18
|
+
...msg,
|
|
19
|
+
error: {
|
|
20
|
+
message: msg.error.message,
|
|
21
|
+
stack: msg.error.stack,
|
|
22
|
+
name: msg.error.name,
|
|
23
|
+
cause: msg.error.cause,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
parentPort?.postMessage(msg);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function cleanup(id: string) {
|
|
32
|
+
const renderState = activeRenders.get(id);
|
|
33
|
+
if (renderState) {
|
|
34
|
+
renderState.rscStream.destroy();
|
|
35
|
+
renderState.htmlTransform?.destroy();
|
|
36
|
+
activeRenders.delete(id);
|
|
37
|
+
|
|
38
|
+
sendMessage({
|
|
39
|
+
type: "CLEANUP_COMPLETE",
|
|
40
|
+
id,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function messageHandler(msg: HtmlWorkerInputMessage) {
|
|
46
|
+
const { type, id } = msg;
|
|
47
|
+
try {
|
|
48
|
+
switch (type) {
|
|
49
|
+
case "ROUTE_READY": {
|
|
50
|
+
let renderState = activeRenders.get(id);
|
|
51
|
+
if (!renderState) {
|
|
52
|
+
renderState = createHtmlWorkerRenderState(msg, sendMessage);
|
|
53
|
+
|
|
54
|
+
activeRenders.set(id, renderState);
|
|
55
|
+
} else {
|
|
56
|
+
throw new Error("Render state already exists");
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case "RSC_CHUNK": {
|
|
61
|
+
let renderState = activeRenders.get(id);
|
|
62
|
+
if (!renderState) {
|
|
63
|
+
throw new Error(`No render state found for id: ${id}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
// Write RSC chunk to the RSC stream
|
|
68
|
+
renderState.rscStream.write(msg.chunk);
|
|
69
|
+
sendMessage({
|
|
70
|
+
type: "CHUNK_PROCESSED",
|
|
71
|
+
id,
|
|
72
|
+
success: true,
|
|
73
|
+
});
|
|
74
|
+
} catch (error: any) {
|
|
75
|
+
sendMessage({
|
|
76
|
+
type: "ERROR",
|
|
77
|
+
id,
|
|
78
|
+
error: `Error writing chunk: ${error.message}`,
|
|
79
|
+
});
|
|
80
|
+
cleanup(id);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "RSC_END": {
|
|
85
|
+
const renderState = activeRenders.get(id);
|
|
86
|
+
if (!renderState) {
|
|
87
|
+
sendMessage({
|
|
88
|
+
type: "ERROR",
|
|
89
|
+
id,
|
|
90
|
+
error: "No render state found",
|
|
91
|
+
});
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Pipe the rendered content to the HTML stream
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "CLEANUP": {
|
|
99
|
+
cleanup(id);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "SHUTDOWN": {
|
|
103
|
+
// If id is "*", clean up all render states
|
|
104
|
+
if (id === "*") {
|
|
105
|
+
for (const [renderId] of activeRenders) {
|
|
106
|
+
cleanup(renderId);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
cleanup(id);
|
|
110
|
+
}
|
|
111
|
+
// Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
|
|
112
|
+
sendMessage({
|
|
113
|
+
type: "SHUTDOWN_COMPLETE",
|
|
114
|
+
id,
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
sendMessage({
|
|
121
|
+
type: "ERROR",
|
|
122
|
+
id,
|
|
123
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PassThrough, Transform } from "stream";
|
|
2
|
+
import type { StreamMetrics } from "../../types.js";
|
|
3
|
+
|
|
4
|
+
export type HtmlWorkerStreamMetrics = {
|
|
5
|
+
totalChunksReceived: number;
|
|
6
|
+
totalBytesReceived: number;
|
|
7
|
+
totalChunksProcessed: number;
|
|
8
|
+
totalBytesProcessed: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface HtmlWorkerRenderState {
|
|
12
|
+
rscStream: PassThrough;
|
|
13
|
+
metrics: StreamMetrics;
|
|
14
|
+
isReady: boolean;
|
|
15
|
+
htmlTransform: Transform;
|
|
16
|
+
stream: ReactDOMServer.PipeableStream;
|
|
17
|
+
abort?: () => void;
|
|
18
|
+
shellReady?: boolean;
|
|
19
|
+
}
|