vite-plugin-react-server 0.3.3 → 0.3.5
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 +113 -222
- package/bin/patch.mjs +84 -0
- package/dist/_virtual/sourcemap-codec.umd.js +11 -0
- package/dist/_virtual/sourcemap-codec.umd.js.map +1 -0
- package/dist/_virtual/sourcemap-codec.umd2.js +9 -0
- package/dist/_virtual/sourcemap-codec.umd2.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -3
- package/dist/index.js.map +1 -1
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js +457 -0
- package/dist/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js.map +1 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js +1283 -0
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +1 -0
- package/dist/package.json +131 -0
- package/dist/plugin/assertServerCondition.d.ts.map +1 -0
- package/dist/plugin/assertServerCondition.js +15 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts +3 -0
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createClientBuildConfig.js +14 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts +12 -0
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createServerBuildConfig.js +40 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts +5 -0
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +1 -0
- package/dist/plugin/build/createSharedBuildConfig.js +28 -0
- package/dist/plugin/build/mergeInputs.d.ts +9 -0
- package/dist/plugin/build/mergeInputs.d.ts.map +1 -0
- package/dist/plugin/build/mergeInputs.js +56 -0
- package/dist/plugin/checkFilesExist.d.ts +3 -0
- package/dist/plugin/checkFilesExist.d.ts.map +1 -0
- package/dist/plugin/checkFilesExist.js +78 -0
- package/dist/plugin/checkFilesExist.js.map +1 -0
- package/dist/{collect-css-manifest.d.ts → plugin/collect-css-manifest.d.ts} +2 -2
- package/dist/plugin/collect-css-manifest.d.ts.map +1 -0
- package/dist/{src → plugin}/collect-css-manifest.js +8 -5
- package/dist/plugin/collect-css-manifest.js.map +1 -0
- package/dist/plugin/components.d.ts.map +1 -0
- package/dist/{src → plugin}/components.js +9 -4
- package/dist/plugin/components.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +51 -0
- package/dist/plugin/config/defaults.d.ts.map +1 -0
- package/dist/plugin/config/defaults.js +52 -0
- package/dist/plugin/config/defaults.js.map +1 -0
- package/dist/plugin/config/getCondition.d.ts +2 -0
- package/dist/plugin/config/getCondition.d.ts.map +1 -0
- package/dist/plugin/config/getCondition.js +11 -0
- package/dist/plugin/config/getCondition.js.map +1 -0
- package/dist/plugin/config/getPaths.d.ts +5 -0
- package/dist/plugin/config/getPaths.d.ts.map +1 -0
- package/dist/plugin/config/getPaths.js +21 -0
- package/dist/plugin/config/getPaths.js.map +1 -0
- package/dist/plugin/config/getWorkerPath.d.ts +2 -0
- package/dist/plugin/config/getWorkerPath.d.ts.map +1 -0
- package/dist/plugin/config/getWorkerPath.js +4 -0
- package/dist/plugin/config/index.d.ts +8 -0
- package/dist/plugin/config/index.d.ts.map +1 -0
- package/dist/plugin/config/index.js +7 -0
- package/dist/plugin/config/moduleIdDefault.d.ts +8 -0
- package/dist/plugin/config/moduleIdDefault.d.ts.map +1 -0
- package/dist/plugin/config/moduleIdDefault.js +23 -0
- package/dist/plugin/config/moduleIdDefault.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +9 -0
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -0
- package/dist/plugin/config/resolveOptions.js +56 -0
- package/dist/plugin/config/resolveOptions.js.map +1 -0
- package/dist/plugin/config/resolvePages.d.ts +9 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -0
- package/dist/plugin/config/resolvePages.js +38 -0
- package/dist/plugin/config/resolvePages.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +18 -0
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -0
- package/dist/plugin/config/resolveUserConfig.js +84 -0
- package/dist/plugin/config/resolveUserConfig.js.map +1 -0
- package/dist/plugin/copy-dir.d.ts.map +1 -0
- package/dist/plugin/copy-dir.js +20 -0
- package/dist/plugin/getCondition.d.ts +2 -0
- package/dist/plugin/getCondition.d.ts.map +1 -0
- package/dist/plugin/getCondition.js +1 -0
- package/dist/plugin/getEnv.d.ts.map +1 -0
- package/dist/plugin/getEnv.js +107 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts +8 -0
- package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createClientInputNormalizer.js +35 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts +9 -0
- package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createServerInputNormalizer.js +37 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +7 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/createStaticInputNormalizer.js +18 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts +12 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getModuleManifest.js +24 -0
- package/dist/plugin/helpers/getModuleManifest.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts +3 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.js +35 -0
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +11 -0
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -0
- package/dist/plugin/helpers/inputNormalizerWorker.js +30 -0
- package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +1 -0
- package/dist/plugin/helpers/normalizedRelativePath.js +36 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts +13 -0
- package/dist/plugin/helpers/resolveFilePath.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveFilePath.js +74 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts +6 -0
- package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +1 -0
- package/dist/plugin/helpers/resolveWorkerModule.js +24 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -0
- package/dist/{src → plugin}/helpers/tryManifest.js +11 -6
- package/dist/plugin/helpers/tryManifest.js.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts +3 -0
- package/dist/plugin/helpers/validateModuleBase.d.ts.map +1 -0
- package/dist/plugin/helpers/validateModuleBase.js +16 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts +3 -0
- package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +1 -0
- package/dist/plugin/helpers/validateResolvedConfig.js +17 -0
- package/dist/plugin/index.d.ts +3 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/loader/createBuildLoader.d.ts +9 -0
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createBuildLoader.js +52 -0
- package/dist/plugin/loader/createBuildLoader.js.map +1 -0
- package/dist/plugin/loader/createCssLoader.d.ts +30 -0
- package/dist/plugin/loader/createCssLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createCssLoader.js +35 -0
- package/dist/{html → plugin/loader}/createPageLoader.d.ts +2 -4
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createPageLoader.js +57 -0
- package/dist/plugin/manifest.d.ts.map +1 -0
- package/dist/plugin/manifest.js +13 -0
- package/dist/plugin/module-graph.d.ts.map +1 -0
- package/dist/plugin/module-graph.js +35 -0
- package/dist/plugin/plugin.d.ts +7 -0
- package/dist/plugin/plugin.d.ts.map +1 -0
- package/dist/plugin/plugin.js +8 -0
- package/dist/plugin/preserver/index.d.ts +2 -0
- package/dist/plugin/preserver/index.d.ts.map +1 -0
- package/dist/plugin/preserver/index.js +1 -0
- package/dist/plugin/preserver/plugin.d.ts +4 -0
- package/dist/plugin/preserver/plugin.d.ts.map +1 -0
- package/dist/plugin/preserver/plugin.js +90 -0
- package/dist/plugin/preserver/plugin.js.map +1 -0
- package/dist/plugin/react-client/index.d.ts +2 -0
- package/dist/plugin/react-client/index.d.ts.map +1 -0
- package/dist/plugin/react-client/index.js +1 -0
- package/dist/plugin/react-client/plugin.d.ts +4 -0
- package/dist/plugin/react-client/plugin.d.ts.map +1 -0
- package/dist/plugin/react-client/plugin.js +34 -0
- package/dist/plugin/react-client/plugin.js.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevMiddleware.js +68 -0
- package/dist/plugin/react-server/createDevServer.d.ts.map +1 -0
- package/dist/plugin/react-server/createDevServer.js +4 -0
- package/dist/plugin/react-server/createHandler.d.ts +17 -0
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createHandler.js +28 -17
- package/dist/plugin/react-server/createHandler.js.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +1 -0
- package/dist/plugin/react-server/createReactNodeStreamer.js +7 -0
- package/dist/{react-server → plugin/react-server}/createRscStream.d.ts +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -0
- package/dist/{src → plugin}/react-server/createRscStream.js +14 -13
- package/dist/plugin/react-server/createRscStream.js.map +1 -0
- package/dist/{react-server → plugin/react-server}/createSsrHandler.d.ts +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -0
- package/dist/plugin/react-server/createSsrHandler.js +102 -0
- package/dist/plugin/react-server/index.d.ts +4 -0
- package/dist/plugin/react-server/index.d.ts.map +1 -0
- package/dist/plugin/react-server/index.js +10 -0
- package/dist/{react-server → plugin/react-server}/plugin.d.ts +2 -2
- package/dist/plugin/react-server/plugin.d.ts.map +1 -0
- package/dist/plugin/react-server/plugin.js +375 -0
- package/dist/plugin/react-server/plugin.js.map +1 -0
- package/dist/plugin/resolvePage.d.ts.map +1 -0
- package/dist/{src → plugin}/resolvePage.js +8 -4
- package/dist/plugin/resolvePage.js.map +1 -0
- package/dist/plugin/resolveProps.d.ts.map +1 -0
- package/dist/{src → plugin}/resolveProps.js +21 -8
- package/dist/plugin/resolveProps.js.map +1 -0
- package/dist/plugin/server.d.ts +2 -0
- package/dist/plugin/server.d.ts.map +1 -0
- package/dist/plugin/server.js +1 -0
- package/dist/plugin/transformer/index.d.ts +2 -0
- package/dist/plugin/transformer/index.d.ts.map +1 -0
- package/dist/plugin/transformer/index.js +1 -0
- package/dist/{transformer/index.d.ts → plugin/transformer/plugin.d.ts} +3 -3
- package/dist/plugin/transformer/plugin.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.js +86 -0
- package/dist/plugin/transformer/plugin.js.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts +21 -0
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-client-components.js +61 -0
- package/dist/plugin/transformer/transformer-client-components.js.map +1 -0
- package/dist/{transformer/transformer.d.ts → plugin/transformer/transformer-server-actions.d.ts} +3 -4
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -0
- package/dist/plugin/transformer/transformer-server-actions.js +76 -0
- package/dist/plugin/transformer/transformer-server-actions.js.map +1 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -0
- package/dist/plugin/transformer/types.js +1 -0
- package/dist/plugin/types.d.ts +225 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/worker/createWorker.d.ts +15 -0
- package/dist/plugin/worker/createWorker.d.ts.map +1 -0
- package/dist/plugin/worker/createWorker.js +71 -0
- package/dist/plugin/worker/createWorker.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.js +12 -0
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.js +4 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts +2 -0
- package/dist/plugin/worker/html/html-worker.production.d.ts.map +1 -0
- package/dist/plugin/worker/html/html-worker.production.js +12 -0
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -0
- package/dist/plugin/worker/html/index.d.ts +2 -0
- package/dist/plugin/worker/html/index.d.ts.map +1 -0
- package/dist/plugin/worker/html/index.js +7 -0
- package/dist/plugin/worker/html/index.js.map +1 -0
- package/dist/plugin/worker/html/messageHandler.d.ts +3 -0
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -0
- package/dist/plugin/worker/html/messageHandler.js +98 -0
- package/dist/plugin/worker/html/messageHandler.js.map +1 -0
- package/dist/plugin/worker/html/plugin.d.ts +4 -0
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/html/plugin.js +89 -0
- package/dist/plugin/worker/html/renderPages.d.ts +38 -0
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -0
- package/dist/plugin/worker/html/renderPages.js +121 -0
- package/dist/plugin/worker/html/renderPages.js.map +1 -0
- package/dist/plugin/worker/loader.d.ts.map +1 -0
- package/dist/plugin/worker/loader.js +11 -0
- package/dist/plugin/worker/loader.js.map +1 -0
- package/dist/plugin/worker/plugin.d.ts +10 -0
- package/dist/plugin/worker/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/plugin.js +14 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts +5 -0
- package/dist/plugin/worker/rsc/createRscStream.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/createRscStream.js +39 -0
- package/dist/plugin/worker/rsc/createRscStream.js.map +1 -0
- package/dist/plugin/worker/rsc/development.d.ts +5 -0
- package/dist/plugin/worker/rsc/development.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/development.js +13 -0
- package/dist/plugin/worker/rsc/development.js.map +1 -0
- package/dist/plugin/worker/rsc/index.d.ts +4 -0
- package/dist/plugin/worker/rsc/index.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/index.js +15 -0
- package/dist/plugin/worker/rsc/index.js.map +1 -0
- package/dist/plugin/worker/rsc/plugin.d.ts +4 -0
- package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/plugin.js +82 -0
- package/dist/plugin/worker/rsc/plugin.js.map +1 -0
- package/dist/plugin/worker/rsc/production.d.ts +5 -0
- package/dist/plugin/worker/rsc/production.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/production.js +13 -0
- package/dist/plugin/worker/rsc/production.js.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts +2 -0
- package/dist/plugin/worker/rsc/rsc-worker.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.js +106 -0
- package/dist/plugin/worker/types.d.ts +99 -0
- package/dist/plugin/worker/types.d.ts.map +1 -0
- package/dist/plugin/worker/types.js +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +9 -0
- package/dist/server.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +1 -201
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +44 -25
- package/plugin/build/createClientBuildConfig.ts +21 -0
- package/plugin/build/createServerBuildConfig.ts +66 -0
- package/plugin/build/createSharedBuildConfig.ts +35 -0
- package/plugin/build/mergeInputs.ts +58 -0
- package/plugin/checkFilesExist.ts +82 -0
- package/{src → plugin}/collect-css-manifest.ts +4 -2
- package/plugin/config/defaults.ts +44 -0
- package/plugin/config/getCondition.ts +3 -0
- package/plugin/config/getPaths.ts +25 -0
- package/plugin/config/getWorkerPath.ts +5 -0
- package/plugin/config/index.ts +8 -0
- package/plugin/config/moduleIdDefault.ts +23 -0
- package/plugin/config/resolveOptions.ts +53 -0
- package/plugin/config/resolvePages.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +97 -0
- package/{src → plugin}/getEnv.ts +1 -1
- package/plugin/helpers/createClientInputNormalizer.ts +48 -0
- package/plugin/helpers/createServerInputNormalizer.ts +52 -0
- package/plugin/helpers/createStaticInputNormalizer.ts +26 -0
- package/plugin/helpers/getModuleManifest.ts +31 -0
- package/plugin/helpers/inputNormalizer.ts +39 -0
- package/plugin/helpers/inputNormalizerWorker.ts +47 -0
- package/plugin/helpers/resolveFilePath.ts +108 -0
- package/plugin/helpers/resolveWorkerModule.ts +41 -0
- package/plugin/helpers/validateModuleBase.ts +30 -0
- package/plugin/helpers/validateResolvedConfig.ts +21 -0
- package/plugin/index.ts +2 -0
- package/plugin/loader/createBuildLoader.ts +60 -0
- package/plugin/loader/createCssLoader.ts +73 -0
- package/{src/html → plugin/loader}/createPageLoader.ts +35 -27
- package/plugin/plugin.ts +8 -0
- package/plugin/preserver/index.ts +1 -0
- package/plugin/preserver/plugin.ts +110 -0
- package/plugin/react-client/index.ts +1 -0
- package/plugin/react-client/plugin.ts +33 -0
- package/{src → plugin}/react-server/createDevMiddleware.ts +17 -1
- package/{src → plugin}/react-server/createDevServer.ts +0 -1
- package/{src → plugin}/react-server/createHandler.ts +31 -10
- package/{src → plugin}/react-server/createReactNodeStreamer.ts +1 -0
- package/{src → plugin}/react-server/createRscStream.ts +8 -12
- package/{src → plugin}/react-server/createSsrHandler.ts +16 -19
- package/plugin/react-server/index.ts +13 -0
- package/plugin/react-server/plugin.ts +465 -0
- package/{src → plugin}/resolvePage.ts +1 -1
- package/{src → plugin}/resolveProps.ts +15 -6
- package/plugin/server.tsx +0 -0
- package/plugin/transformer/index.ts +1 -0
- package/plugin/transformer/plugin.ts +131 -0
- package/plugin/transformer/transformer-client-components.ts +94 -0
- package/{src/transformer/transformer.ts → plugin/transformer/transformer-server-actions.ts} +14 -27
- package/{src → plugin}/types.ts +97 -55
- package/plugin/worker/createWorker.ts +84 -0
- package/plugin/worker/html/html-worker.development.tsx +8 -0
- package/plugin/worker/html/html-worker.production.tsx +8 -0
- package/plugin/worker/html/html-worker.ts +5 -0
- package/plugin/worker/html/index.ts +5 -0
- package/plugin/worker/html/messageHandler.ts +116 -0
- package/plugin/worker/html/plugin.ts +97 -0
- package/plugin/worker/html/renderPages.ts +187 -0
- package/plugin/worker/plugin.ts +17 -0
- package/plugin/worker/rsc/createRscStream.ts +42 -0
- package/plugin/worker/rsc/development.ts +6 -0
- package/plugin/worker/rsc/index.ts +14 -0
- package/plugin/worker/rsc/plugin.ts +83 -0
- package/plugin/worker/rsc/production.ts +6 -0
- package/plugin/worker/rsc/rsc-worker.tsx +128 -0
- package/plugin/worker/types.ts +124 -0
- package/scripts/bump-version.mjs +68 -0
- package/scripts/check-react-version.mjs +66 -0
- package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +4291 -0
- package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +108798 -0
- package/scripts/react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch +24775 -0
- package/{patches → scripts}/react-server-dom-esm+0.0.1.patch +10259 -3
- package/tsconfig.json +15 -13
- package/dist/assertServerCondition.d.ts.map +0 -1
- package/dist/bin/patch.js +0 -51
- package/dist/bin/patch.js.map +0 -1
- package/dist/build/createBuildConfig.d.ts +0 -13
- package/dist/build/createBuildConfig.d.ts.map +0 -1
- package/dist/build/mergeInputs.d.ts +0 -5
- package/dist/build/mergeInputs.d.ts.map +0 -1
- package/dist/checkFilesExist.d.ts +0 -8
- package/dist/checkFilesExist.d.ts.map +0 -1
- package/dist/collect-css-manifest.d.ts.map +0 -1
- package/dist/components.d.ts.map +0 -1
- package/dist/copy-dir.d.ts.map +0 -1
- package/dist/getEnv.d.ts.map +0 -1
- package/dist/helpers/inputNormalizer.d.ts +0 -6
- package/dist/helpers/inputNormalizer.d.ts.map +0 -1
- package/dist/helpers/normalizedRelativePath.d.ts.map +0 -1
- package/dist/helpers/tryManifest.d.ts.map +0 -1
- package/dist/html/createPageLoader.d.ts.map +0 -1
- package/dist/manifest.d.ts.map +0 -1
- package/dist/module-graph.d.ts.map +0 -1
- package/dist/options.d.ts +0 -91
- package/dist/options.d.ts.map +0 -1
- package/dist/plugin.d.ts +0 -3
- package/dist/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.d.ts +0 -4
- package/dist/react-client/plugin.d.ts.map +0 -1
- package/dist/react-client/plugin.js +0 -28
- package/dist/react-client/plugin.js.map +0 -1
- package/dist/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/react-server/createDevServer.d.ts.map +0 -1
- package/dist/react-server/createHandler.d.ts +0 -23
- package/dist/react-server/createHandler.d.ts.map +0 -1
- package/dist/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/react-server/createRscStream.d.ts.map +0 -1
- package/dist/react-server/createSsrHandler.d.ts.map +0 -1
- package/dist/react-server/plugin.d.ts.map +0 -1
- package/dist/react-server/plugin.js +0 -345
- package/dist/react-server/plugin.js.map +0 -1
- package/dist/resolvePage.d.ts.map +0 -1
- package/dist/resolveProps.d.ts.map +0 -1
- package/dist/src/build/createBuildConfig.js +0 -44
- package/dist/src/build/createBuildConfig.js.map +0 -1
- package/dist/src/build/mergeInputs.js +0 -16
- package/dist/src/build/mergeInputs.js.map +0 -1
- package/dist/src/checkFilesExist.js +0 -61
- package/dist/src/checkFilesExist.js.map +0 -1
- package/dist/src/collect-css-manifest.js.map +0 -1
- package/dist/src/components.js.map +0 -1
- package/dist/src/getEnv.js +0 -76
- package/dist/src/getEnv.js.map +0 -1
- package/dist/src/helpers/inputNormalizer.js +0 -11
- package/dist/src/helpers/inputNormalizer.js.map +0 -1
- package/dist/src/helpers/normalizedRelativePath.js +0 -34
- package/dist/src/helpers/normalizedRelativePath.js.map +0 -1
- package/dist/src/helpers/tryManifest.js.map +0 -1
- package/dist/src/html/createPageLoader.js +0 -72
- package/dist/src/html/createPageLoader.js.map +0 -1
- package/dist/src/options.js +0 -307
- package/dist/src/options.js.map +0 -1
- package/dist/src/react-server/createHandler.js.map +0 -1
- package/dist/src/react-server/createRscStream.js.map +0 -1
- package/dist/src/resolvePage.js.map +0 -1
- package/dist/src/resolveProps.js.map +0 -1
- package/dist/src/worker/createHtmlStream.js +0 -62
- package/dist/src/worker/createHtmlStream.js.map +0 -1
- package/dist/src/worker/createWorker.js +0 -34
- package/dist/src/worker/createWorker.js.map +0 -1
- package/dist/src/worker/renderPages.js +0 -99
- package/dist/src/worker/renderPages.js.map +0 -1
- package/dist/transformer/index.d.ts.map +0 -1
- package/dist/transformer/preserveDirectives.d.ts +0 -4
- package/dist/transformer/preserveDirectives.d.ts.map +0 -1
- package/dist/transformer/preserver.d.ts +0 -2
- package/dist/transformer/preserver.d.ts.map +0 -1
- package/dist/transformer/transformer.d.ts.map +0 -1
- package/dist/transformer/types.d.ts.map +0 -1
- package/dist/worker/createHtmlStream.d.ts +0 -7
- package/dist/worker/createHtmlStream.d.ts.map +0 -1
- package/dist/worker/createWorker.d.ts +0 -10
- package/dist/worker/createWorker.d.ts.map +0 -1
- package/dist/worker/loader.d.ts.map +0 -1
- package/dist/worker/loader.js +0 -7
- package/dist/worker/loader.js.map +0 -1
- package/dist/worker/renderPages.d.ts +0 -18
- package/dist/worker/renderPages.d.ts.map +0 -1
- package/dist/worker/types.d.ts +0 -31
- package/dist/worker/types.d.ts.map +0 -1
- package/dist/worker/worker.d.ts +0 -7
- package/dist/worker/worker.d.ts.map +0 -1
- package/dist/worker/worker.js +0 -112
- package/dist/worker/worker.js.map +0 -1
- package/src/build/createBuildConfig.ts +0 -57
- package/src/build/mergeInputs.ts +0 -42
- package/src/checkFilesExist.ts +0 -67
- package/src/helpers/inputNormalizer.ts +0 -22
- package/src/index.ts +0 -4
- package/src/options.ts +0 -423
- package/src/plugin.ts +0 -5
- package/src/react-client/plugin.ts +0 -34
- package/src/react-server/plugin.ts +0 -409
- package/src/transformer/index.ts +0 -112
- package/src/transformer/preserveDirectives.ts +0 -100
- package/src/transformer/preserver.ts +0 -47
- package/src/worker/createHtmlStream.ts +0 -76
- package/src/worker/createWorker.ts +0 -44
- package/src/worker/renderPages.ts +0 -144
- package/src/worker/types.ts +0 -38
- package/src/worker/worker.tsx +0 -136
- /package/dist/{assertServerCondition.d.ts → plugin/assertServerCondition.d.ts} +0 -0
- /package/dist/{components.d.ts → plugin/components.d.ts} +0 -0
- /package/dist/{copy-dir.d.ts → plugin/copy-dir.d.ts} +0 -0
- /package/dist/{getEnv.d.ts → plugin/getEnv.d.ts} +0 -0
- /package/dist/{helpers → plugin/helpers}/normalizedRelativePath.d.ts +0 -0
- /package/dist/{helpers → plugin/helpers}/tryManifest.d.ts +0 -0
- /package/dist/{manifest.d.ts → plugin/manifest.d.ts} +0 -0
- /package/dist/{module-graph.d.ts → plugin/module-graph.d.ts} +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevMiddleware.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createDevServer.d.ts +0 -0
- /package/dist/{react-server → plugin/react-server}/createReactNodeStreamer.d.ts +0 -0
- /package/dist/{resolvePage.d.ts → plugin/resolvePage.d.ts} +0 -0
- /package/dist/{resolveProps.d.ts → plugin/resolveProps.d.ts} +0 -0
- /package/dist/{transformer → plugin/transformer}/types.d.ts +0 -0
- /package/dist/{worker → plugin/worker}/loader.d.ts +0 -0
- /package/{src → plugin}/assertServerCondition.ts +0 -0
- /package/{src → plugin}/components.tsx +0 -0
- /package/{src → plugin}/copy-dir.ts +0 -0
- /package/{src/server.tsx → plugin/getCondition.ts} +0 -0
- /package/{src → plugin}/helpers/normalizedRelativePath.ts +0 -0
- /package/{src → plugin}/helpers/tryManifest.ts +0 -0
- /package/{src → plugin}/manifest.ts +0 -0
- /package/{src → plugin}/module-graph.ts +0 -0
- /package/{src → plugin}/transformer/README.md +0 -0
- /package/{src → plugin}/transformer/types.ts +0 -0
- /package/{src → plugin}/worker/loader.ts +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
3
|
+
import type { HtmlRenderState, HtmlWorkerMessage } from "../types.js";
|
|
4
|
+
import 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
|
+
|
|
14
|
+
export const messageHandler = async (message: HtmlWorkerMessage) => {
|
|
15
|
+
try {
|
|
16
|
+
switch (message.type) {
|
|
17
|
+
case "RSC_CHUNK": {
|
|
18
|
+
const { id, chunk, ...rest } = message;
|
|
19
|
+
const render = activeRenders.get(id);
|
|
20
|
+
|
|
21
|
+
if (!render) {
|
|
22
|
+
activeRenders.set(id, {
|
|
23
|
+
chunks: [chunk],
|
|
24
|
+
id,
|
|
25
|
+
complete: false,
|
|
26
|
+
rendered: false,
|
|
27
|
+
...rest,
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
render.chunks = [...render.chunks, chunk];
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
case "RSC_END": {
|
|
36
|
+
const { id } = message;
|
|
37
|
+
const render = activeRenders.get(id);
|
|
38
|
+
if (!render) {
|
|
39
|
+
throw new Error(`No render state found for ${id}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Create a PassThrough stream to handle the chunks
|
|
43
|
+
const rscStream = new PassThrough();
|
|
44
|
+
|
|
45
|
+
// Write all chunks to the stream
|
|
46
|
+
for (const chunk of render.chunks) {
|
|
47
|
+
rscStream.write(chunk);
|
|
48
|
+
}
|
|
49
|
+
rscStream.end();
|
|
50
|
+
|
|
51
|
+
// Create React elements from stream
|
|
52
|
+
const reactElements = createFromNodeStream(
|
|
53
|
+
rscStream,
|
|
54
|
+
render.moduleRootPath,
|
|
55
|
+
render.moduleBaseURL
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Create a promise that resolves when HTML is complete
|
|
59
|
+
const htmlPromise = new Promise<string>((resolve) => {
|
|
60
|
+
let html = "";
|
|
61
|
+
const collectStream = new PassThrough();
|
|
62
|
+
|
|
63
|
+
collectStream.on("data", (chunk) => {
|
|
64
|
+
html += chunk.toString();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
collectStream.on("end", () => {
|
|
68
|
+
resolve(html);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Render to pipeable stream
|
|
72
|
+
const stream = ReactDOMServer.renderToPipeableStream(
|
|
73
|
+
reactElements as React.ReactNode,
|
|
74
|
+
{
|
|
75
|
+
...render.pipableStreamOptions,
|
|
76
|
+
onShellReady() {
|
|
77
|
+
parentPort?.postMessage({ type: "SHELL_READY", id });
|
|
78
|
+
},
|
|
79
|
+
async onAllReady() {
|
|
80
|
+
const finalHtml = await htmlPromise;
|
|
81
|
+
parentPort?.postMessage({
|
|
82
|
+
type: "HTML_READY",
|
|
83
|
+
id,
|
|
84
|
+
html: finalHtml,
|
|
85
|
+
outputPath: render.htmlOutputPath,
|
|
86
|
+
});
|
|
87
|
+
parentPort?.postMessage({ type: "ALL_READY", id });
|
|
88
|
+
},
|
|
89
|
+
onError(error) {
|
|
90
|
+
parentPort?.postMessage({
|
|
91
|
+
type: "ERROR",
|
|
92
|
+
id,
|
|
93
|
+
error: error instanceof Error ? error.message : String(error),
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Pipe to collection stream
|
|
100
|
+
stream.pipe(collectStream);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
parentPort?.postMessage({
|
|
108
|
+
type: "ERROR",
|
|
109
|
+
id:
|
|
110
|
+
message.type === "RSC_CHUNK" || message.type === "RSC_END"
|
|
111
|
+
? message.id
|
|
112
|
+
: "",
|
|
113
|
+
error: error instanceof Error ? error.message : String(error),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import type { ModuleFormat } from 'rollup';
|
|
4
|
+
import type { StreamPluginOptions } from "../../types.js";
|
|
5
|
+
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
6
|
+
import { getPluginRoot } from "../../config/getPaths.js";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export function reactHtmlWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
10
|
+
return {
|
|
11
|
+
name: "vite:react-html-worker",
|
|
12
|
+
config(config) {
|
|
13
|
+
const root = config.root ?? process.cwd();
|
|
14
|
+
const pluginRoot = getPluginRoot();
|
|
15
|
+
const htmlWorkerPath = typeof options.htmlWorkerPath === 'string'
|
|
16
|
+
? resolve(root, options.htmlWorkerPath)
|
|
17
|
+
: resolve(pluginRoot, DEFAULT_CONFIG.HTML_WORKER_PATH);
|
|
18
|
+
|
|
19
|
+
const format: ModuleFormat = 'esm';
|
|
20
|
+
|
|
21
|
+
// Single worker output for server build
|
|
22
|
+
const workerConfig = {
|
|
23
|
+
input: {
|
|
24
|
+
'html-worker': htmlWorkerPath,
|
|
25
|
+
},
|
|
26
|
+
output: {
|
|
27
|
+
format,
|
|
28
|
+
dir: options.build?.server ?? 'dist/server', // Output to server directory
|
|
29
|
+
entryFileNames: '[name].js',
|
|
30
|
+
preserveModules: true,
|
|
31
|
+
// Add manifest entry
|
|
32
|
+
manualChunks: {
|
|
33
|
+
'html-worker': [htmlWorkerPath]
|
|
34
|
+
},
|
|
35
|
+
resolve: {
|
|
36
|
+
conditions: ['react-server'],
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
build: {
|
|
43
|
+
rollupOptions: {
|
|
44
|
+
preserveEntrySignatures: 'strict',
|
|
45
|
+
input: {
|
|
46
|
+
...workerConfig.input,
|
|
47
|
+
...(typeof config.build?.rollupOptions?.input === 'object'
|
|
48
|
+
? config.build?.rollupOptions?.input
|
|
49
|
+
: {}),
|
|
50
|
+
},
|
|
51
|
+
external: [
|
|
52
|
+
'vite',
|
|
53
|
+
'rollup',
|
|
54
|
+
'react',
|
|
55
|
+
'react-dom',
|
|
56
|
+
'react-dom/server',
|
|
57
|
+
'react-server-dom-esm',
|
|
58
|
+
'react-server-dom-esm/client.node',
|
|
59
|
+
'react-server-dom-esm/server.node',
|
|
60
|
+
'react-server-dom-esm/node-loader',
|
|
61
|
+
'source-map',
|
|
62
|
+
'acorn-loose',
|
|
63
|
+
'webpack-sources',
|
|
64
|
+
'stream',
|
|
65
|
+
'util',
|
|
66
|
+
'crypto',
|
|
67
|
+
'async_hooks',
|
|
68
|
+
'fs',
|
|
69
|
+
'path',
|
|
70
|
+
'worker_threads',
|
|
71
|
+
// if we use node: paths in our code, it should always be catched by below rule.
|
|
72
|
+
/^node:.*/,
|
|
73
|
+
],
|
|
74
|
+
output: {
|
|
75
|
+
...workerConfig.output,
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
manifest: true, // Ensure manifest is generated
|
|
79
|
+
minify: false,
|
|
80
|
+
sourcemap: true,
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
// Add this to ensure entry is in manifest
|
|
85
|
+
generateBundle(_, bundle) {
|
|
86
|
+
const workerEntry = bundle['html-worker.js'];
|
|
87
|
+
if (workerEntry) {
|
|
88
|
+
Object.defineProperty(workerEntry, 'isEntry', {
|
|
89
|
+
value: true,
|
|
90
|
+
writable: false,
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: false
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { join, resolve as resolvePath } from "node:path";
|
|
2
|
+
import { Transform } from "node:stream";
|
|
3
|
+
import type { Worker } from "node:worker_threads";
|
|
4
|
+
import { createHandler } from "../../react-server/createHandler.js";
|
|
5
|
+
import type { ResolvedUserConfig, StreamPluginOptions } from "../../types.js";
|
|
6
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
+
|
|
8
|
+
interface PipeableStreamOptions {
|
|
9
|
+
bootstrapModules?: string[];
|
|
10
|
+
bootstrapScripts?: string[];
|
|
11
|
+
bootstrapScriptContent?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
identifierPrefix?: string;
|
|
14
|
+
namespaceURI?: string;
|
|
15
|
+
nonce?: string;
|
|
16
|
+
progressiveChunkSize?: number;
|
|
17
|
+
onShellReady?: () => void;
|
|
18
|
+
onAllReady?: () => void;
|
|
19
|
+
onError?: (error: unknown) => void;
|
|
20
|
+
importMap?: {
|
|
21
|
+
imports?: Record<string, string>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type RenderPagesOptions = {
|
|
26
|
+
pluginOptions: Required<
|
|
27
|
+
Pick<
|
|
28
|
+
StreamPluginOptions,
|
|
29
|
+
"moduleBase" | "moduleBasePath" | "moduleBaseURL" | "projectRoot"
|
|
30
|
+
>
|
|
31
|
+
> &
|
|
32
|
+
Pick<
|
|
33
|
+
StreamPluginOptions,
|
|
34
|
+
"Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName"
|
|
35
|
+
>;
|
|
36
|
+
userConfig: ResolvedUserConfig;
|
|
37
|
+
manifest: Record<string, { file: string }>;
|
|
38
|
+
worker: Worker;
|
|
39
|
+
pipableStreamOptions?: PipeableStreamOptions;
|
|
40
|
+
loader: (id: string) => Promise<Record<string, any>>;
|
|
41
|
+
onCssFile?: (path: string) => void;
|
|
42
|
+
clientCss?: string[];
|
|
43
|
+
moduleBasePath: string;
|
|
44
|
+
moduleBaseURL: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export async function renderPages(
|
|
48
|
+
routes: string[],
|
|
49
|
+
options: RenderPagesOptions
|
|
50
|
+
) {
|
|
51
|
+
console.log("[renderPages] Starting render for routes:", routes);
|
|
52
|
+
|
|
53
|
+
const destinationRoot = resolvePath(options.userConfig.root, options.userConfig.build.outDir);
|
|
54
|
+
const failedRoutes = new Map<string, Error>();
|
|
55
|
+
const moduleRootPath = join(destinationRoot, options.moduleBasePath);
|
|
56
|
+
const moduleBaseURL = options.moduleBaseURL;
|
|
57
|
+
const htmlRoot = join(
|
|
58
|
+
options.userConfig.root,
|
|
59
|
+
options.pluginOptions.build?.client ?? options.userConfig.build.outDir.replace('server', 'client')
|
|
60
|
+
);
|
|
61
|
+
console.log("[renderPages] HTML root:", htmlRoot);
|
|
62
|
+
|
|
63
|
+
const streamStarted = new Set<string>();
|
|
64
|
+
const completedRoutes = new Set<string>();
|
|
65
|
+
const htmlContent = new Map<string, string>();
|
|
66
|
+
const writePromises = new Map<string, Promise<void>>();
|
|
67
|
+
|
|
68
|
+
// Create a promise that resolves when all routes are complete
|
|
69
|
+
const allRoutesComplete = new Promise<void>((resolve, reject) => {
|
|
70
|
+
const timeout = setTimeout(() => {
|
|
71
|
+
reject(new Error(`Render timeout - Started: ${streamStarted.size}, Completed: ${completedRoutes.size}`));
|
|
72
|
+
}, 5000);
|
|
73
|
+
|
|
74
|
+
options.worker.on("message", function messageHandler(msg: any) {
|
|
75
|
+
switch (msg.type) {
|
|
76
|
+
case "SHELL_READY": {
|
|
77
|
+
streamStarted.add(msg.id);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case "HTML_READY": {
|
|
81
|
+
htmlContent.set(msg.id, msg.html);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "ALL_READY": {
|
|
85
|
+
completedRoutes.add(msg.id);
|
|
86
|
+
|
|
87
|
+
if (completedRoutes.size === routes.length) {
|
|
88
|
+
options.worker.removeListener("message", messageHandler);
|
|
89
|
+
clearTimeout(timeout);
|
|
90
|
+
|
|
91
|
+
// Write all HTML files
|
|
92
|
+
for (const [route, html] of htmlContent) {
|
|
93
|
+
const outputPath = route === '/'
|
|
94
|
+
? join(htmlRoot, 'index.html')
|
|
95
|
+
: join(htmlRoot, route, 'index.html');
|
|
96
|
+
|
|
97
|
+
const writePromise = writeFile(outputPath, html)
|
|
98
|
+
.catch(error => {
|
|
99
|
+
failedRoutes.set(route, error as Error);
|
|
100
|
+
});
|
|
101
|
+
writePromises.set(route, writePromise);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Wait for all files to be written
|
|
105
|
+
Promise.all(writePromises.values())
|
|
106
|
+
.then(() => resolve())
|
|
107
|
+
.catch(reject);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case "ERROR": {
|
|
112
|
+
console.error("[renderPages] Worker error:", msg.error);
|
|
113
|
+
if (msg.id) {
|
|
114
|
+
failedRoutes.set(msg.id, new Error(msg.error));
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await mkdir(htmlRoot, { recursive: true });
|
|
124
|
+
|
|
125
|
+
const renderPromises = routes.map(async (route) => {
|
|
126
|
+
console.log("[renderPages] Processing route:", route);
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
const result = await createHandler(route, options.pluginOptions, {
|
|
130
|
+
loader: options.loader,
|
|
131
|
+
manifest: options.manifest,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (result.type !== "success") {
|
|
135
|
+
console.log("[renderPages] Handler failed:", result);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const htmlOutputPath = route === '/'
|
|
140
|
+
? resolvePath(htmlRoot, 'index.html')
|
|
141
|
+
: resolvePath(htmlRoot, route, 'index.html');
|
|
142
|
+
|
|
143
|
+
const transform = new Transform({
|
|
144
|
+
transform(chunk, _encoding, callback) {
|
|
145
|
+
options.worker.postMessage({
|
|
146
|
+
type: "RSC_CHUNK",
|
|
147
|
+
id: route,
|
|
148
|
+
chunk: chunk,
|
|
149
|
+
moduleRootPath: moduleRootPath,
|
|
150
|
+
moduleBaseURL: moduleBaseURL,
|
|
151
|
+
htmlOutputPath,
|
|
152
|
+
outDir: options.userConfig.build.outDir,
|
|
153
|
+
pipableStreamOptions: options.pipableStreamOptions ?? {},
|
|
154
|
+
});
|
|
155
|
+
callback(null, chunk);
|
|
156
|
+
},
|
|
157
|
+
flush(callback) {
|
|
158
|
+
options.worker.postMessage({
|
|
159
|
+
type: "RSC_END",
|
|
160
|
+
id: route,
|
|
161
|
+
});
|
|
162
|
+
callback();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
result.stream.pipe(transform);
|
|
167
|
+
|
|
168
|
+
} catch (error) {
|
|
169
|
+
failedRoutes.set(route, error as Error);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Wait for both the render promises and all routes to complete
|
|
174
|
+
await Promise.all([
|
|
175
|
+
Promise.all(renderPromises),
|
|
176
|
+
allRoutesComplete
|
|
177
|
+
]);
|
|
178
|
+
|
|
179
|
+
} finally {
|
|
180
|
+
await options.worker.terminate();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
failedRoutes,
|
|
185
|
+
completedRoutes
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StreamPluginOptions } from "../types.js"
|
|
2
|
+
import type { Plugin } from "vite"
|
|
3
|
+
import { reactHtmlWorkerPlugin } from "./html/plugin.js"
|
|
4
|
+
import { reactRscWorkerPlugin } from "./rsc/plugin.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This plugin can be used to create your own worker paths. By default, prebuild workers are used.
|
|
8
|
+
*
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function reactWorkerPlugin(options: StreamPluginOptions): Plugin[] {
|
|
13
|
+
return [
|
|
14
|
+
reactHtmlWorkerPlugin(options),
|
|
15
|
+
reactRscWorkerPlugin(options)
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { renderToPipeableStream
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
} from "react-server-dom-esm/server.node";
|
|
4
|
+
import type { Writable } from "node:stream";
|
|
5
|
+
import type { MessagePort } from "node:worker_threads";
|
|
6
|
+
import type { RscRenderState } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export function createRscStream(
|
|
9
|
+
renderState: RscRenderState,
|
|
10
|
+
writeStream: Writable,
|
|
11
|
+
parentPort: MessagePort | null
|
|
12
|
+
) {
|
|
13
|
+
console.log("[createRscStream] Creating stream for:", renderState.id);
|
|
14
|
+
|
|
15
|
+
const stream = renderToPipeableStream(renderState.componentImport, {
|
|
16
|
+
onShellReady() {
|
|
17
|
+
console.log("[createRscStream] onShellReady called for:", renderState.id);
|
|
18
|
+
stream.pipe(writeStream);
|
|
19
|
+
},
|
|
20
|
+
onAllReady() {
|
|
21
|
+
console.log("[createRscStream] onAllReady called for:", renderState.id);
|
|
22
|
+
writeStream.on("finish", () => {
|
|
23
|
+
parentPort?.postMessage({
|
|
24
|
+
type: "WROTE_FILE",
|
|
25
|
+
id: renderState.id,
|
|
26
|
+
outputPath: renderState.rscOutputPath
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
onError(error: unknown) {
|
|
31
|
+
console.error("[createRscStream] Render error:", error);
|
|
32
|
+
parentPort?.postMessage({
|
|
33
|
+
type: "ERROR",
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
id: renderState.id
|
|
36
|
+
});
|
|
37
|
+
stream.abort();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return stream;
|
|
42
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRscStream as devCreateRscStream } from './createRscStream.js';
|
|
2
|
+
import { createWorker as devCreateWorker } from '../createWorker.js';
|
|
3
|
+
|
|
4
|
+
// Development-specific implementations
|
|
5
|
+
export const createRscStream = devCreateRscStream;
|
|
6
|
+
export const createWorker = devCreateWorker;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { reactRscWorkerPlugin } from "./plugin.js";
|
|
2
|
+
|
|
3
|
+
// Dynamic import based on NODE_ENV
|
|
4
|
+
export const worker = await (
|
|
5
|
+
process.env['NODE_ENV'] === 'production'
|
|
6
|
+
? import('./production.js')
|
|
7
|
+
: import('./development.js')
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
// Re-export worker functions
|
|
11
|
+
export const {
|
|
12
|
+
createRscStream,
|
|
13
|
+
createWorker
|
|
14
|
+
} = worker;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import type { ModuleFormat } from 'rollup';
|
|
4
|
+
import type { StreamPluginOptions } from "../../types.js";
|
|
5
|
+
import { DEFAULT_CONFIG } from "../../config/defaults.js";
|
|
6
|
+
import { getPluginRoot } from "../../config/getPaths.js";
|
|
7
|
+
|
|
8
|
+
export function reactRscWorkerPlugin(options: StreamPluginOptions): Plugin {
|
|
9
|
+
return {
|
|
10
|
+
name: "vite:react-rsc-worker",
|
|
11
|
+
config(config) {
|
|
12
|
+
const root = config.root ?? process.cwd();
|
|
13
|
+
const pluginRoot = getPluginRoot();
|
|
14
|
+
const rscWorkerPath = typeof options.rscWorkerPath === 'string'
|
|
15
|
+
? resolve(root, options.rscWorkerPath)
|
|
16
|
+
: resolve(pluginRoot, DEFAULT_CONFIG.RSC_WORKER_PATH);
|
|
17
|
+
|
|
18
|
+
const format: ModuleFormat = 'esm';
|
|
19
|
+
|
|
20
|
+
// Single worker output for server build
|
|
21
|
+
const workerConfig = {
|
|
22
|
+
input: {
|
|
23
|
+
'rsc-worker': rscWorkerPath,
|
|
24
|
+
},
|
|
25
|
+
output: {
|
|
26
|
+
format,
|
|
27
|
+
dir: options.build?.server ?? 'dist/server', // Output to server directory
|
|
28
|
+
entryFileNames: '[name].js',
|
|
29
|
+
preserveModules: true,
|
|
30
|
+
manualChunks: {
|
|
31
|
+
'rsc-worker': [rscWorkerPath]
|
|
32
|
+
},
|
|
33
|
+
resolve: {
|
|
34
|
+
conditions: ['react-server'],
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
build: {
|
|
41
|
+
rollupOptions: {
|
|
42
|
+
preserveEntrySignatures: 'strict',
|
|
43
|
+
input: {
|
|
44
|
+
...workerConfig.input,
|
|
45
|
+
...(typeof config.build?.rollupOptions?.input === 'object'
|
|
46
|
+
? config.build?.rollupOptions?.input
|
|
47
|
+
: {}),
|
|
48
|
+
},
|
|
49
|
+
external: [
|
|
50
|
+
'vite',
|
|
51
|
+
'rollup',
|
|
52
|
+
'react',
|
|
53
|
+
'react-dom',
|
|
54
|
+
'react-dom/server',
|
|
55
|
+
'react-server-dom-esm',
|
|
56
|
+
'react-server-dom-esm/client.node',
|
|
57
|
+
'react-server-dom-esm/server.node',
|
|
58
|
+
'react-server-dom-esm/node-loader',
|
|
59
|
+
'source-map',
|
|
60
|
+
'acorn-loose',
|
|
61
|
+
'webpack-sources',
|
|
62
|
+
'stream',
|
|
63
|
+
'util',
|
|
64
|
+
'crypto',
|
|
65
|
+
'async_hooks',
|
|
66
|
+
'fs',
|
|
67
|
+
'path',
|
|
68
|
+
'worker_threads',
|
|
69
|
+
// if we use node: paths in our code, it should always be catched by below rule.
|
|
70
|
+
/^node:.*/,
|
|
71
|
+
],
|
|
72
|
+
output: {
|
|
73
|
+
...workerConfig.output,
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
manifest: true, // Ensure manifest is generated
|
|
77
|
+
minify: false,
|
|
78
|
+
sourcemap: true,
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRscStream as prodCreateRscStream } from './createRscStream.js';
|
|
2
|
+
import { createWorker as prodCreateWorker } from '../createWorker.js';
|
|
3
|
+
|
|
4
|
+
// Production-specific optimizations could go here
|
|
5
|
+
export const createRscStream = prodCreateRscStream;
|
|
6
|
+
export const createWorker = prodCreateWorker;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import type { Writable } from "node:stream";
|
|
5
|
+
import { parentPort } from "node:worker_threads";
|
|
6
|
+
import {
|
|
7
|
+
registerClientReference,
|
|
8
|
+
registerServerReference
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
} from "react-server-dom-esm/server.node";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
RscRenderState,
|
|
14
|
+
RscWorkerMessage,
|
|
15
|
+
RscWorkerResponse
|
|
16
|
+
} from "../types.js";
|
|
17
|
+
import { createRscStream } from "./createRscStream.js";
|
|
18
|
+
|
|
19
|
+
if (!parentPort) {
|
|
20
|
+
throw new Error("This module must be run as a worker");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Track active renders
|
|
24
|
+
const activeRenders = new Map<string, RscRenderState>();
|
|
25
|
+
const activeStreams = new Map<string, ReturnType<typeof createRscStream>>();
|
|
26
|
+
const activeWrites = new Map<string, Writable>();
|
|
27
|
+
|
|
28
|
+
async function shutdown() {
|
|
29
|
+
console.log("[RSC Worker] Shutting down forcefully");
|
|
30
|
+
for (const stream of activeStreams.values()) {
|
|
31
|
+
stream.abort();
|
|
32
|
+
}
|
|
33
|
+
for (const writeStream of activeWrites.values()) {
|
|
34
|
+
writeStream.destroy();
|
|
35
|
+
}
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sendMessage(message: RscWorkerResponse) {
|
|
40
|
+
parentPort?.postMessage(message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Handle incoming messages
|
|
44
|
+
parentPort.on("message", async (message: RscWorkerMessage) => {
|
|
45
|
+
if (message.type === "SHUTDOWN") {
|
|
46
|
+
await shutdown();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
switch (message.type) {
|
|
52
|
+
case "RSC_RENDER": {
|
|
53
|
+
const { id, pageImport, propsImport, outDir, moduleRootPath, moduleBaseURL, pipableStreamOptions } = message;
|
|
54
|
+
|
|
55
|
+
// Skip if already rendered
|
|
56
|
+
if (activeRenders.has(id)) return;
|
|
57
|
+
|
|
58
|
+
// Create render state
|
|
59
|
+
const renderState: RscRenderState = {
|
|
60
|
+
id,
|
|
61
|
+
outDir,
|
|
62
|
+
moduleRootPath,
|
|
63
|
+
moduleBaseURL,
|
|
64
|
+
rscOutputPath: `${outDir}/${id}.rsc`,
|
|
65
|
+
componentImport: pageImport,
|
|
66
|
+
propsImport,
|
|
67
|
+
pipableStreamOptions
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Ensure output directory exists
|
|
71
|
+
await mkdir(dirname(renderState.rscOutputPath), { recursive: true });
|
|
72
|
+
const writeStream = createWriteStream(renderState.rscOutputPath);
|
|
73
|
+
|
|
74
|
+
// Create stream
|
|
75
|
+
const stream = createRscStream(renderState, writeStream, parentPort);
|
|
76
|
+
|
|
77
|
+
// Track active streams
|
|
78
|
+
activeRenders.set(id, renderState);
|
|
79
|
+
activeStreams.set(id, stream);
|
|
80
|
+
activeWrites.set(id, writeStream);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
case "RSC_END": {
|
|
85
|
+
const { id } = message;
|
|
86
|
+
activeRenders.delete(id);
|
|
87
|
+
activeStreams.delete(id);
|
|
88
|
+
activeWrites.delete(id);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case "CLIENT_REFERENCE": {
|
|
93
|
+
const { id, location, key } = message;
|
|
94
|
+
const ref = registerClientReference(id, location, key);
|
|
95
|
+
sendMessage({
|
|
96
|
+
type: "CLIENT_REFERENCE",
|
|
97
|
+
id,
|
|
98
|
+
location,
|
|
99
|
+
key,
|
|
100
|
+
ref
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
case "SERVER_REFERENCE": {
|
|
106
|
+
const { id, location, key } = message;
|
|
107
|
+
const ref = registerServerReference(id, location, key);
|
|
108
|
+
sendMessage({
|
|
109
|
+
type: "SERVER_REFERENCE",
|
|
110
|
+
id,
|
|
111
|
+
location,
|
|
112
|
+
key,
|
|
113
|
+
ref
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (error) {
|
|
119
|
+
sendMessage({
|
|
120
|
+
type: "ERROR",
|
|
121
|
+
id: message.type === "RSC_RENDER" ? message.id : "",
|
|
122
|
+
error: error instanceof Error ? error.message : String(error)
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Signal ready
|
|
128
|
+
parentPort.postMessage({ type: "READY" });
|