vite-plugin-react-server 0.3.4 → 0.3.6
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/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 +7 -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/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 +130 -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 +38 -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 +3 -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 +3 -0
- package/dist/plugin/react-server/index.d.ts.map +1 -0
- package/dist/plugin/react-server/index.js +10 -0
- package/dist/plugin/react-server/plugin.d.ts +7 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -0
- package/dist/plugin/react-server/plugin.js +377 -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 -4
- package/dist/plugin/transformer/plugin.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.js +94 -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 +123 -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 +42 -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 +44 -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 +109 -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 +12 -0
- package/plugin/react-server/plugin.ts +464 -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 +141 -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 +188 -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/check-react-version.mjs +48 -30
- 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 +11354 -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 +0 -8
- 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/scripts/check-react-version.js +0 -34
- package/dist/scripts/check-react-version.js.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
package/README.md
CHANGED
|
@@ -2,62 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
A Vite plugin that enables React Server Components (RSC) streaming and static building of html pages. Uses experimental dependencies from React, specifically `react-server-dom-esm`.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- 🚀 Super fast static build times
|
|
8
|
+
- 🔄 Use vite to create your personal meta-framework
|
|
9
|
+
- ⚡ Full RSC streaming support
|
|
10
|
+
- 📦 Dual-worker architecture for optimal performance
|
|
11
|
+
- 🔧 Automatic client/server code splitting
|
|
12
|
+
- 🎯 Directive-based component targeting
|
|
8
13
|
|
|
9
|
-
##
|
|
14
|
+
## Example Project
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
only get this version of react-server-dom-esm by actually building react from source. There's a patch system included
|
|
13
|
-
that allows you to download the stub version of react-server-dom-esm and apply the patch to it.
|
|
16
|
+
The [mmcelebration.com project](https://github.com/nicobrinkkemper/mmc) uses this plugin. Build time for ~200 html pages is just a few seconds.
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
npm install react-server-dom-esm
|
|
17
|
-
```
|
|
18
|
-
This package exists, but is empty! So, we need to patch it.
|
|
18
|
+
## Installation
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
This will do two things:
|
|
24
|
-
- Look for your installed react version
|
|
25
|
-
- Change the patch around so it matches your react version
|
|
26
|
-
- Writes a file to patches/react-server-dom-esm+YOUR-REACT-VERSION.patch
|
|
27
|
-
```bash
|
|
28
|
-
npm install patch-package --save-dev
|
|
29
|
-
```
|
|
30
|
-
Add to postinstall script in package.json: (you need to do this yourself)
|
|
31
|
-
```json
|
|
32
|
-
"postinstall": "patch-package"
|
|
21
|
+
npm install vite-plugin-react-server
|
|
33
22
|
```
|
|
34
|
-
Now anytime you run install, it will patch the react-server-dom-esm package. Wait until the package is released
|
|
35
|
-
and you can remove the patch-package script.
|
|
36
|
-
|
|
37
|
-
If you don't want to rely on this, you can also build react from source yourself and run `npm run link` where the package.json is, then `npm link react-server-dom-esm` where you need to use it. However, make sure to also link the react and react-dom package as well or the versions will mismatch (hence the patch-package system).
|
|
38
23
|
|
|
39
|
-
|
|
24
|
+
### React Canary Setup
|
|
40
25
|
|
|
41
|
-
|
|
42
|
-
- 🔄 Use vite to create your personal meta-framework
|
|
43
|
-
|
|
44
|
-
## Installation
|
|
26
|
+
This plugin requires React's experimental features. You'll need to:
|
|
45
27
|
|
|
28
|
+
1. Install react-server-dom-esm (currently an empty stub package):
|
|
46
29
|
```bash
|
|
47
|
-
npm install
|
|
30
|
+
npm install react-server-dom-esm
|
|
48
31
|
```
|
|
49
32
|
|
|
50
|
-
|
|
33
|
+
2. Apply the patch:
|
|
34
|
+
```bash
|
|
35
|
+
npx vite-plugin-react-server/patch
|
|
36
|
+
```
|
|
37
|
+
This will:
|
|
38
|
+
- Detect your installed React version
|
|
39
|
+
- Adapt the patch accordingly
|
|
40
|
+
- Create `patches/react-server-dom-esm+YOUR-REACT-VERSION.patch`
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
3. Install patch-package:
|
|
43
|
+
```bash
|
|
44
|
+
npm install patch-package --save-dev
|
|
45
|
+
```
|
|
55
46
|
|
|
56
|
-
|
|
47
|
+
4. Add to package.json:
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"scripts": {
|
|
51
|
+
"postinstall": "patch-package"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
57
55
|
|
|
56
|
+
Alternative: You can build React from source and use `npm link` for react-server-dom-esm, react, and react-dom (though the patch system is recommended).
|
|
58
57
|
|
|
59
|
-
## Configuration
|
|
60
|
-
To keep the client and server build processes easy to seperate, I suggest creating two vite.config.ts files and import the config in both. Let's make the stream plugin config file and name it `.tsx`. Vite config files can't end with `.tsx` but our own files can.
|
|
58
|
+
## Basic Configuration
|
|
61
59
|
|
|
62
60
|
```typescript
|
|
63
61
|
// vite.react-server.config.ts
|
|
@@ -66,11 +64,8 @@ import type { Options } from 'vite-plugin-react-server'
|
|
|
66
64
|
|
|
67
65
|
// Custom router example
|
|
68
66
|
const createRouter = (file: 'props.ts' | 'Page.tsx') => (url: string) => {
|
|
69
|
-
|
|
70
|
-
if(url.
|
|
71
|
-
return `src/page/bidoof/${file}`
|
|
72
|
-
if(url === '/index.rsc')
|
|
73
|
-
return `src/page/${file}`;
|
|
67
|
+
if(url.includes('bidoof')) return `src/page/bidoof/${file}`
|
|
68
|
+
if(url === '/index.rsc') return `src/page/${file}`;
|
|
74
69
|
return `src/page/404/${file}`;
|
|
75
70
|
}
|
|
76
71
|
|
|
@@ -82,22 +77,21 @@ export const streamPluginOptions: Options = {
|
|
|
82
77
|
propsExportName: "props",
|
|
83
78
|
}
|
|
84
79
|
```
|
|
85
|
-
|
|
80
|
+
|
|
81
|
+
### Client Build Config
|
|
82
|
+
|
|
86
83
|
```typescript
|
|
87
84
|
// vite.config.ts
|
|
88
85
|
import { defineConfig } from 'vite'
|
|
89
86
|
import { viteReactStreamPlugin } from 'vite-plugin-react-server/client'
|
|
90
87
|
import { streamPluginOptions } from './vite.react-server.config.js'
|
|
91
88
|
|
|
92
|
-
|
|
93
89
|
export default defineConfig({
|
|
94
|
-
plugins: [
|
|
95
|
-
viteReactStreamPlugin(streamPluginOptions)
|
|
96
|
-
]
|
|
90
|
+
plugins: [viteReactStreamPlugin(streamPluginOptions)]
|
|
97
91
|
})
|
|
98
92
|
```
|
|
99
93
|
|
|
100
|
-
|
|
94
|
+
### Server Build Config
|
|
101
95
|
|
|
102
96
|
```typescript
|
|
103
97
|
// vite.server.config.ts
|
|
@@ -105,62 +99,37 @@ import { defineConfig } from 'vite'
|
|
|
105
99
|
import { viteReactStreamPlugin } from 'vite-plugin-react-server/server'
|
|
106
100
|
import { streamPluginOptions } from './vite.react-server.config.js'
|
|
107
101
|
|
|
108
|
-
export default defineConfig({
|
|
109
|
-
plugins: [
|
|
110
|
-
viteReactStreamPlugin(streamPluginOptions)
|
|
111
|
-
]
|
|
112
|
-
})
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
// vite.server.config.ts
|
|
117
|
-
import { viteReactStreamPlugin } from 'vite-plugin-react-server/server'
|
|
118
|
-
import { streamPluginOptions } from './vite.react.config.js'
|
|
119
|
-
|
|
120
102
|
export default defineConfig({
|
|
121
103
|
plugins: [viteReactStreamPlugin(streamPluginOptions)]
|
|
122
104
|
})
|
|
123
105
|
```
|
|
124
|
-
```typescript
|
|
125
|
-
// vite.config.ts
|
|
126
|
-
import { viteReactStreamPlugin } from 'vite-plugin-react-server/client'
|
|
127
|
-
import { streamPluginOptions } from './vite.react.config.js'
|
|
128
106
|
|
|
129
|
-
|
|
130
|
-
plugins: [viteReactStreamPlugin(streamPluginOptions)]
|
|
131
|
-
})
|
|
132
|
-
```
|
|
133
|
-
Then in the package.json, add the scripts:
|
|
107
|
+
### Scripts Setup
|
|
134
108
|
|
|
135
109
|
```json
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
110
|
+
{
|
|
111
|
+
"scripts": {
|
|
112
|
+
"start": "NODE_OPTIONS=--conditions=react-server vite",
|
|
113
|
+
"build": "npm run build:client && npm run build:server",
|
|
114
|
+
"build:client": "vite build",
|
|
115
|
+
"build:server": "NODE_OPTIONS=--conditions=react-server vite build --ssr --config vite.server.config.ts",
|
|
116
|
+
"test:server": "NODE_OPTIONS=--conditions=react-server vitest --config vite.server.config.ts"
|
|
117
|
+
}
|
|
142
118
|
}
|
|
143
119
|
```
|
|
144
120
|
|
|
145
|
-
|
|
121
|
+
## Component Types
|
|
146
122
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
Create server components in your pages directory:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
123
|
+
### Server Components (Default)
|
|
124
|
+
```tsx
|
|
153
125
|
// src/page/pokemon/page.tsx
|
|
154
126
|
export function Page({ pokemon }) {
|
|
155
127
|
return <div>Its a {pokemon.name}!</div>
|
|
156
128
|
}
|
|
157
129
|
```
|
|
158
130
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Define props for your pages:
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
131
|
+
### Page Props
|
|
132
|
+
```tsx
|
|
164
133
|
// src/page/pokemon/props.ts
|
|
165
134
|
export const props = async () => {
|
|
166
135
|
const res = await fetch("https://pokeapi.co/api/v2/pokemon-form/399/")
|
|
@@ -168,143 +137,25 @@ export const props = async () => {
|
|
|
168
137
|
}
|
|
169
138
|
```
|
|
170
139
|
|
|
171
|
-
|
|
140
|
+
### Client Components
|
|
141
|
+
Use the "use client" directive for client-side features:
|
|
142
|
+
```tsx
|
|
143
|
+
"use client"
|
|
144
|
+
import { useState } from 'react'
|
|
172
145
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
import type { ReactNode } from "react";
|
|
177
|
-
import { createFromFetch } from "react-server-dom-esm/client.browser";
|
|
178
|
-
import { callServer } from "./callServer.js";
|
|
179
|
-
|
|
180
|
-
export function createReactFetcher({
|
|
181
|
-
url = window.location.pathname,
|
|
182
|
-
moduleBaseURL = "/src",
|
|
183
|
-
headers = { Accept: "text/x-component" },
|
|
184
|
-
}: {
|
|
185
|
-
url?: string;
|
|
186
|
-
moduleBaseURL?: string;
|
|
187
|
-
headers?: HeadersInit;
|
|
188
|
-
} = {}): Promise<ReactNode> {
|
|
189
|
-
return createFromFetch(
|
|
190
|
-
fetch(url, {
|
|
191
|
-
headers: headers,
|
|
192
|
-
}),
|
|
193
|
-
{
|
|
194
|
-
callServer: callServer,
|
|
195
|
-
moduleBaseURL: new URL(moduleBaseURL, window.origin).href,
|
|
196
|
-
}
|
|
197
|
-
) as Promise<ReactNode>;
|
|
146
|
+
export function Counter() {
|
|
147
|
+
const [count, setCount] = useState(0)
|
|
148
|
+
return <button onClick={() => setCount(c => c + 1)}>{count}</button>
|
|
198
149
|
}
|
|
199
150
|
```
|
|
200
|
-
then use it in your client entry file:
|
|
201
|
-
```typescript
|
|
202
|
-
// src/client.tsx
|
|
203
|
-
const Shell: React.FC<{
|
|
204
|
-
data: React.Usable<unknown>;
|
|
205
|
-
}> = ({ data: initialServerData }) => {
|
|
206
|
-
const [, startTransition] = useTransition();
|
|
207
|
-
const [storeData, setStoreData] =
|
|
208
|
-
useState<React.Usable<unknown>>(initialServerData);
|
|
209
|
-
|
|
210
|
-
const navigate = useCallback((to: string) => {
|
|
211
|
-
startTransition(() => {
|
|
212
|
-
// Create new RSC data stream
|
|
213
|
-
setStoreData(
|
|
214
|
-
createReactFetcher({
|
|
215
|
-
url: to + to.endsWith("/") ? "index.rsc" : "/index.rsc",
|
|
216
|
-
})
|
|
217
|
-
);
|
|
218
|
-
});
|
|
219
|
-
}, []);
|
|
220
|
-
|
|
221
|
-
// Routing example, useEventListener would just use useEffect and window.addEventListener
|
|
222
|
-
useEventListener("popstate", (e) => {
|
|
223
|
-
if (e instanceof PopStateEvent) {
|
|
224
|
-
if (e.state?.to) {
|
|
225
|
-
return navigate(e.state.to);
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
return navigate(window.location.pathname);
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const content = use(storeData);
|
|
233
|
-
|
|
234
|
-
return <ErrorBoundary>{content as ReactNode}</ErrorBoundary>;
|
|
235
|
-
};
|
|
236
|
-
// Initialize the app
|
|
237
|
-
const rootElement = document.getElementById("root");
|
|
238
|
-
if (!rootElement) throw new Error("Root element not found");
|
|
239
|
-
|
|
240
|
-
const intitalData = createReactFetcher({
|
|
241
|
-
url: "/index.rsc",
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
createRoot(rootElement).render(<Shell data={intitalData} />);
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
## HTML Template
|
|
248
|
-
|
|
249
|
-
For development, you can still use the html template - but
|
|
250
|
-
you can provide your own Html function directly in the plugin options.
|
|
251
|
-
```html
|
|
252
|
-
<!DOCTYPE html>
|
|
253
|
-
<html lang="en">
|
|
254
|
-
<head>
|
|
255
|
-
<meta charset="utf-8" />
|
|
256
|
-
<link href="src/index.css" rel="stylesheet" />
|
|
257
|
-
</head>
|
|
258
|
-
<body>
|
|
259
|
-
<div id="root"></div>
|
|
260
|
-
<script type="module" src="/src/client.tsx"></script>
|
|
261
|
-
</body>
|
|
262
|
-
</html>
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
## Production html templating
|
|
267
|
-
|
|
268
|
-
The optional Html component can be used to wrap the entire stream. This component is only
|
|
269
|
-
used for production builds - you can not rely on it for development. This is because,
|
|
270
|
-
during development we use vite's native html template and the stream will only contain
|
|
271
|
-
the page content's.
|
|
272
|
-
|
|
273
|
-
The Html component is quite powerful since it gets access to all the page props, the vite client manifest,
|
|
274
|
-
and the children of the stream.
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
import React from "react";
|
|
278
|
-
import type { Manifest } from "vite";
|
|
279
|
-
import { Favicons } from "./layout/Favicons.js";
|
|
280
|
-
import { Head } from "./layout/Head.js";
|
|
281
|
-
|
|
282
|
-
export const Html = ({
|
|
283
|
-
children,
|
|
284
|
-
pageProps,
|
|
285
|
-
manifest,
|
|
286
|
-
}: {
|
|
287
|
-
children: React.ReactNode;
|
|
288
|
-
pageProps: HtmlProps;
|
|
289
|
-
manifest: Manifest;
|
|
290
|
-
}) => {
|
|
291
|
-
if (process.env["NODE_ENV"] === "production") {
|
|
292
|
-
return (
|
|
293
|
-
<html>
|
|
294
|
-
<head>
|
|
295
|
-
<Head title={pageProps.title} />
|
|
296
|
-
<meta name="description" content={pageProps.description} />
|
|
297
|
-
<Favicons favicons={pageProps.favicons} />
|
|
298
|
-
</head>
|
|
299
|
-
<body>
|
|
300
|
-
<div id="root">{children}</div>
|
|
301
|
-
</body>
|
|
302
|
-
</html>
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
return <>{children}</>;
|
|
306
|
-
};
|
|
307
151
|
|
|
152
|
+
### Server Actions
|
|
153
|
+
Use the "use server" directive for server-side API endpoints:
|
|
154
|
+
```tsx
|
|
155
|
+
"use server"
|
|
156
|
+
export async function submitForm(data: FormData) {
|
|
157
|
+
// Server-side logic
|
|
158
|
+
}
|
|
308
159
|
```
|
|
309
160
|
|
|
310
161
|
## Notes
|
|
@@ -318,5 +169,45 @@ export const Html = ({
|
|
|
318
169
|
|
|
319
170
|
MIT
|
|
320
171
|
|
|
172
|
+
## FAQ
|
|
173
|
+
|
|
174
|
+
### Why does this plugin use two separate workers?
|
|
175
|
+
|
|
176
|
+
The plugin uses a dual-worker architecture to handle the complex boundary between server and client code in React 19's new paradigm. This design enables four key scenarios:
|
|
177
|
+
|
|
178
|
+
1. **Pure Client** - Client-side React rendering
|
|
179
|
+
2. **Pure Server** - Server-side RSC streaming
|
|
180
|
+
3. **Client-with-server-worker** - Thread WITHOUT React server conditions using dependencies that are ONLY available using the server condition
|
|
181
|
+
4. **Server-with-client-worker** - Thread WITH React server conditions using dependencies that are ONLY available WITHOUT the server condition
|
|
182
|
+
|
|
183
|
+
This architecture is necessary because React 19 introduces a fundamental shift in how server/client boundaries work. While React was traditionally client/browser-oriented, version 19 moves much of the functionality to the server by default.
|
|
184
|
+
|
|
185
|
+
## When to use which directive?
|
|
186
|
+
|
|
187
|
+
The "use client" should be used for components that use client-only things, like hooks - browser window, localStorage, etc.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
The "use server" directive is *not* for server components, it's for server actions. Every component is a server component by default. If the "use server" directive is present,
|
|
191
|
+
this plugin will register it as a server action - which means you can intend the exported functions to be API endpoints.
|
|
192
|
+
|
|
193
|
+
## What about .client.tsx files, .server.tsx files?
|
|
194
|
+
|
|
195
|
+
Whenever you use the directive, it's recommended to also name the file with the .client.tsx or .server.tsx extension respectively.
|
|
196
|
+
While this isn't required for the plugin to work - it's the only way to make sure all client and server files are included in the build -
|
|
197
|
+
even if they are not a main entry point.
|
|
198
|
+
|
|
199
|
+
### What's the deal with NODE_OPTIONS and conditions?
|
|
200
|
+
|
|
201
|
+
The React Server Components system requires specific Node conditions:
|
|
202
|
+
|
|
203
|
+
- `NODE_OPTIONS='--conditions=react-server'` is required for RSC functionality (generating RSC streams)
|
|
204
|
+
- This condition must NOT be present for client-side React operations (generating HTML from RSC streams)
|
|
205
|
+
|
|
206
|
+
The plugin recommends using the react-server condition in the main thread to enable React server features from the start. When different conditions are needed (e.g., generating static HTML), the plugin uses workers with appropriate conditions.
|
|
207
|
+
|
|
208
|
+
### Why start with "use client"?
|
|
209
|
+
|
|
210
|
+
With React 19's server-first approach, many existing ecosystem tools and patterns need the "use client" directive to work as they did before. It's becoming a common pattern to start with "use client" to maintain compatibility with existing code while gradually adopting the new server-first paradigm.
|
|
211
|
+
|
|
321
212
|
|
|
322
213
|
|
package/bin/patch.mjs
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import path, { dirname } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const PATCH_RECONCILER_VERSION = '0.0.0-experimental-b3a95caf-20250113.patch'
|
|
7
|
+
const STUB_VERSION = '0.0.1'
|
|
8
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
async function patchReactExperimental() {
|
|
11
|
+
try {
|
|
12
|
+
// Read installed React version from user's project
|
|
13
|
+
const reactPkg = JSON.parse(
|
|
14
|
+
await fs.readFile(
|
|
15
|
+
path.resolve(process.cwd(), 'node_modules/react/package.json'),
|
|
16
|
+
'utf-8'
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
const installedVersion = reactPkg.version
|
|
20
|
+
|
|
21
|
+
// Define patches to process
|
|
22
|
+
const patches = [
|
|
23
|
+
{
|
|
24
|
+
template: `../scripts/react-server-dom-esm+${PATCH_RECONCILER_VERSION}`,
|
|
25
|
+
output: `react-server-dom-esm+${STUB_VERSION}.patch`
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
template: `../scripts/react+${PATCH_RECONCILER_VERSION}`,
|
|
29
|
+
output: `react+${installedVersion}.patch`
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
template: `../scripts/react-dom+${PATCH_RECONCILER_VERSION}`,
|
|
33
|
+
output: `react-dom+${installedVersion}.patch`
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
// Create patches dir in user's project
|
|
38
|
+
const userPatchesDir = path.resolve(process.cwd(), 'patches')
|
|
39
|
+
await fs.mkdir(userPatchesDir, { recursive: true })
|
|
40
|
+
|
|
41
|
+
// Process each patch
|
|
42
|
+
for (const {template, output} of patches) {
|
|
43
|
+
const patchPath = path.resolve(__dirname, template)
|
|
44
|
+
let patchContent = await fs.readFile(patchPath, 'utf-8')
|
|
45
|
+
|
|
46
|
+
// Replace version strings
|
|
47
|
+
patchContent = patchContent.replace(
|
|
48
|
+
new RegExp(PATCH_RECONCILER_VERSION, 'g'),
|
|
49
|
+
installedVersion
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// Write the patch file
|
|
53
|
+
const newPatchPath = path.resolve(userPatchesDir, output)
|
|
54
|
+
await fs.writeFile(newPatchPath, patchContent)
|
|
55
|
+
console.log(`Created patch file: patches/${output}`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
console.log(`
|
|
59
|
+
✅ Created patch files for React packages
|
|
60
|
+
Location: patches/
|
|
61
|
+
|
|
62
|
+
Next steps:
|
|
63
|
+
1. Install patch-package:
|
|
64
|
+
npm install patch-package --save-dev
|
|
65
|
+
|
|
66
|
+
2. Add to package.json:
|
|
67
|
+
"postinstall": "patch-package"
|
|
68
|
+
|
|
69
|
+
3. Run:
|
|
70
|
+
npm install
|
|
71
|
+
|
|
72
|
+
The patches will be applied automatically on install.
|
|
73
|
+
`)
|
|
74
|
+
return true
|
|
75
|
+
} catch (e) {
|
|
76
|
+
console.error('Failed to create patches:', e)
|
|
77
|
+
process.exit(1)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
patchReactExperimental().catch((e) => {
|
|
82
|
+
console.error('Unexpected error:', e)
|
|
83
|
+
process.exit(1)
|
|
84
|
+
})
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,mBAAmB,mBAAmB,CAAC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import type { StreamPluginOptions } from './plugin/types.js';
|
|
2
|
+
export declare const viteReactServer: (options: StreamPluginOptions) => Promise<import("vite").Plugin<{
|
|
3
|
+
meta: import("./server.js").ReactStreamPluginMeta;
|
|
4
|
+
addCssFile: (path: string) => void;
|
|
5
|
+
}> | (() => void)>;
|
|
6
|
+
export declare const viteReactClient: (options: StreamPluginOptions) => Promise<import("vite").Plugin<any> | (() => void)>;
|
|
7
|
+
export declare const viteReactStream: (options: StreamPluginOptions) => Promise<import("vite").Plugin<any> | (() => void)>;
|
|
3
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAI7D,eAAO,MAAM,eAAe,YAAmB,mBAAmB;;;kBAOjE,CAAA;AAED,eAAO,MAAM,eAAe,YAAmB,mBAAmB,uDAOjE,CAAA;AAED,eAAO,MAAM,eAAe,YAAa,mBAAmB,uDAM3D,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* vite-plugin-react-server
|
|
3
|
+
* Copyright (c) Nico Brinkkemper
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
const isServer = process.env["NODE_OPTIONS"]?.match(/--conditions[= ]react-server/);
|
|
7
|
+
const viteReactServer = async (options) => {
|
|
8
|
+
if (!isServer) {
|
|
9
|
+
return () => {
|
|
10
|
+
};
|
|
11
|
+
} else {
|
|
12
|
+
const module = await import('./server.js');
|
|
13
|
+
return module.reactServerPlugin(options);
|
|
14
|
+
}
|
|
4
15
|
};
|
|
16
|
+
const viteReactClient = async (options) => {
|
|
17
|
+
if (isServer) {
|
|
18
|
+
return () => {
|
|
19
|
+
};
|
|
20
|
+
} else {
|
|
21
|
+
const module = await import('./client.js');
|
|
22
|
+
return module.reactClientPlugin(options);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const viteReactStream = (options) => {
|
|
26
|
+
if (isServer) {
|
|
27
|
+
return viteReactClient(options);
|
|
28
|
+
} else {
|
|
29
|
+
return viteReactServer(options);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { viteReactClient, viteReactServer, viteReactStream };
|
|
5
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../index.ts"],"sourcesContent":["\"use strict\";\n\nimport type { StreamPluginOptions } from './plugin/types.js';\n\nconst isServer = process.env['NODE_OPTIONS']?.match(/--conditions[= ]react-server/)\n\nexport const viteReactServer = async (options: StreamPluginOptions)=>{\n if(!isServer){\n return ()=>{}\n } else {\n const module = await import('./server.js')\n return module.reactServerPlugin(options)\n }\n}\n\nexport const viteReactClient = async (options: StreamPluginOptions)=>{\n if(isServer){\n return ()=>{}\n } else {\n const module = await import('./client.js')\n return module.reactClientPlugin(options)\n }\n}\n\nexport const viteReactStream = (options: StreamPluginOptions)=>{\n if(isServer){\n return viteReactClient(options)\n } else {\n return viteReactServer(options)\n }\n}"],"names":[],"mappings":";;;;;AAIA,MAAM,WAAW,OAAQ,CAAA,GAAA,CAAI,cAAc,CAAA,EAAG,MAAM,8BAA8B,CAAA;AAErE,MAAA,eAAA,GAAkB,OAAO,OAA+B,KAAA;AACnE,EAAA,IAAG,CAAC,QAAS,EAAA;AACX,IAAA,OAAO,MAAI;AAAA,KAAC;AAAA,GACP,MAAA;AACL,IAAM,MAAA,MAAA,GAAS,MAAM,OAAO,aAAa,CAAA;AACzC,IAAO,OAAA,MAAA,CAAO,kBAAkB,OAAO,CAAA;AAAA;AAE3C;AAEa,MAAA,eAAA,GAAkB,OAAO,OAA+B,KAAA;AACnE,EAAA,IAAG,QAAS,EAAA;AACR,IAAA,OAAO,MAAI;AAAA,KAAC;AAAA,GACT,MAAA;AACL,IAAM,MAAA,MAAA,GAAS,MAAM,OAAO,aAAa,CAAA;AACzC,IAAO,OAAA,MAAA,CAAO,kBAAkB,OAAO,CAAA;AAAA;AAE3C;AAEa,MAAA,eAAA,GAAkB,CAAC,OAA+B,KAAA;AAC7D,EAAA,IAAG,QAAS,EAAA;AACV,IAAA,OAAO,gBAAgB,OAAO,CAAA;AAAA,GACzB,MAAA;AACL,IAAA,OAAO,gBAAgB,OAAO,CAAA;AAAA;AAElC;;;;"}
|