vite-plugin-react-server 1.1.12 → 1.1.13
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/dist/package.json +10 -8
- package/dist/plugin/components/css-collector-elements.d.ts +4 -2
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
- package/dist/plugin/components/css-collector-elements.js +21 -7
- package/dist/plugin/components/css-collector-elements.js.map +1 -1
- package/dist/plugin/components/css-collector.d.ts +4 -5
- package/dist/plugin/components/css-collector.d.ts.map +1 -1
- package/dist/plugin/components/css-collector.js +5 -9
- package/dist/plugin/components/css-collector.js.map +1 -1
- package/dist/plugin/components/html.d.ts +1 -1
- package/dist/plugin/components/html.d.ts.map +1 -1
- package/dist/plugin/components/html.js +14 -3
- package/dist/plugin/components/html.js.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts +4 -4
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +14 -9
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +66 -12
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +69 -15
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts +5 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js +25 -0
- package/dist/plugin/config/resolveAutoDiscoverMatcher.js.map +1 -0
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.js +16 -5
- package/dist/plugin/config/resolveEnv.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +3 -3
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +59 -87
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -4
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +8 -1
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/error/toError.d.ts +3 -0
- package/dist/plugin/error/toError.d.ts.map +1 -1
- package/dist/plugin/error/toError.js +33 -4
- package/dist/plugin/error/toError.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -1
- package/dist/plugin/helpers/cleanObject.js +19 -5
- package/dist/plugin/helpers/cleanObject.js.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +3 -3
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts +4 -3
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +7 -2
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createHandler.d.ts +4 -3
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +1 -1
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +2 -2
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +15 -5
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/index.d.ts +2 -2
- package/dist/plugin/helpers/index.d.ts.map +1 -1
- package/dist/plugin/helpers/index.js +2 -2
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +4 -1
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/moduleResolver.d.ts +3 -0
- package/dist/plugin/helpers/moduleResolver.d.ts.map +1 -0
- package/dist/plugin/helpers/moduleResolver.js +25 -0
- package/dist/plugin/helpers/requestInfo.d.ts +18 -3
- package/dist/plugin/helpers/requestInfo.d.ts.map +1 -1
- package/dist/plugin/helpers/requestInfo.js +75 -11
- package/dist/plugin/helpers/requestInfo.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePage.js +2 -3
- package/dist/plugin/helpers/resolvePage.js.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +4 -3
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -1
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.d.ts +3 -2
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.js +13 -1
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -1
- package/dist/plugin/helpers/sourceMap.d.ts +8 -0
- package/dist/plugin/helpers/sourceMap.d.ts.map +1 -0
- package/dist/plugin/helpers/sourceMap.js +136 -0
- package/dist/plugin/helpers.js +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +7 -22
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +79 -65
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createDefaultLoader.d.ts +13 -0
- package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -0
- package/dist/plugin/loader/createDefaultLoader.js +47 -0
- package/dist/plugin/loader/css-loader.development.d.ts +1 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +1 -1
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/handleExports.d.ts +33 -0
- package/dist/plugin/loader/handleExports.d.ts.map +1 -0
- package/dist/plugin/loader/handleExports.js +174 -0
- package/dist/plugin/loader/handleExports.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +1 -1
- package/dist/plugin/loader/index.d.ts.map +1 -1
- package/dist/plugin/loader/index.js +4 -1
- package/dist/plugin/loader/parse.d.ts +6 -0
- package/dist/plugin/loader/parse.d.ts.map +1 -0
- package/dist/plugin/loader/parse.js +23 -0
- package/dist/plugin/loader/parse.js.map +1 -0
- package/dist/plugin/loader/react-loader.client.d.ts +2 -0
- package/dist/plugin/loader/react-loader.client.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.client.js +2 -0
- package/dist/plugin/loader/react-loader.d.ts +1 -12
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +5 -687
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/react-loader.server.d.ts +21 -0
- package/dist/plugin/loader/react-loader.server.d.ts.map +1 -0
- package/dist/plugin/loader/react-loader.server.js +69 -0
- package/dist/plugin/loader/sourceMap.d.ts +35 -0
- package/dist/plugin/loader/sourceMap.d.ts.map +1 -0
- package/dist/plugin/loader/sourceMap.js +105 -0
- package/dist/plugin/loader/temporaryReferences.d.ts +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts +2 -0
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -0
- package/dist/plugin/loader/transformModuleIfNeeded.js +27 -0
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +27 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +52 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -0
- package/dist/plugin/loader/types.d.ts +8 -0
- package/dist/plugin/loader/types.d.ts.map +1 -0
- package/dist/plugin/loader/types.js +1 -0
- package/dist/plugin/plugin.client.d.ts +2 -2
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +2 -3
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/plugin.server.d.ts +2 -2
- package/dist/plugin/plugin.server.d.ts.map +1 -1
- package/dist/plugin/plugin.server.js +2 -2
- package/dist/plugin/plugin.server.js.map +1 -1
- package/dist/plugin/preserver/plugin.d.ts +2 -2
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +6 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/{server.d.ts → configureWorkerRequestHandler.d.ts} +4 -4
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -0
- package/dist/plugin/react-client/{server.js → configureWorkerRequestHandler.js} +11 -8
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -0
- package/dist/plugin/react-client/createMessageHandlers.d.ts +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.js +18 -11
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.d.ts +5 -3
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +61 -27
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.js +14 -4
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +7 -8
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +9 -3
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-server/configureReactServer.d.ts +9 -0
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -0
- package/dist/plugin/react-server/{server.js → configureReactServer.js} +26 -8
- package/dist/plugin/react-server/configureReactServer.js.map +1 -0
- package/dist/plugin/react-server/handleServerAction.d.ts +5 -0
- package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -0
- package/dist/plugin/react-server/handleServerAction.js +145 -0
- package/dist/plugin/react-server/handleServerAction.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts +2 -2
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +1 -1
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +2 -2
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -1
- package/dist/plugin/react-static/collectRscContent.d.ts +2 -2
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -1
- package/dist/plugin/react-static/collectRscContent.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts +3 -3
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +18 -7
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts +2 -2
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +28 -12
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +2 -2
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPage.js.map +1 -1
- package/dist/plugin/react-static/renderPages.d.ts +2 -2
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/react-static/renderStreams.d.ts +2 -2
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -1
- package/dist/plugin/react-static/renderStreams.js +4 -4
- package/dist/plugin/react-static/renderStreams.js.map +1 -1
- package/dist/plugin/source-map/createMappingsSerializer.d.ts +2 -0
- package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -0
- package/dist/plugin/source-map/createMappingsSerializer.js +159 -0
- package/dist/plugin/source-map/readMappings.d.ts +2 -0
- package/dist/plugin/source-map/readMappings.d.ts.map +1 -0
- package/dist/plugin/source-map/readMappings.js +201 -0
- package/dist/plugin/transformer/index.d.ts +0 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +0 -1
- package/dist/plugin/transformer/plugin.client.d.ts +1 -3
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.client.js +1 -84
- package/dist/plugin/transformer/plugin.server.d.ts +2 -2
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +52 -20
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +89 -119
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/callServer.d.ts +1 -1
- package/dist/plugin/utils/callServer.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts +1 -1
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.js +13 -4
- package/dist/plugin/utils/createCallServer.js.map +1 -1
- package/dist/plugin/utils/index.d.ts +1 -0
- package/dist/plugin/utils/index.d.ts.map +1 -1
- package/dist/plugin/utils/index.js +1 -0
- package/dist/plugin/utils.js +1 -0
- package/dist/plugin/utils.js.map +1 -1
- package/dist/plugin/vendor/vendor.client.d.ts +2 -1
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +2 -1
- package/dist/plugin/vendor/vendor.client.js.map +1 -1
- package/dist/plugin/vendor/vendor.server.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.server.js +1 -1
- package/dist/plugin/vendor/vendor.server.js.map +1 -1
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +17 -22
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +25 -4
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +15 -13
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +2 -12
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +2 -2
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts +2 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +8 -8
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +166 -107
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +112 -52
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +5 -64
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +5 -1
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +2 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -1
- package/dist/plugin/worker/sendMessage.js +2 -1
- package/dist/plugin/worker/sendMessage.js.map +1 -1
- package/dist/plugin/worker/types.d.ts +52 -53
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -8
- package/plugin/components/css-collector-elements.tsx +30 -9
- package/plugin/components/css-collector.tsx +13 -22
- package/plugin/components/html.tsx +12 -5
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +31 -13
- package/plugin/config/defaults.tsx +72 -16
- package/plugin/config/resolveAutoDiscoverMatcher.ts +23 -0
- package/plugin/config/resolveEnv.ts +20 -12
- package/plugin/config/resolveOptions.ts +152 -155
- package/plugin/config/resolveUserConfig.ts +20 -5
- package/plugin/error/toError.ts +35 -1
- package/plugin/helpers/cleanObject.ts +79 -15
- package/plugin/helpers/collectViteModuleGraphCss.ts +4 -3
- package/plugin/helpers/createCssProps.tsx +26 -9
- package/plugin/helpers/createHandler.ts +7 -4
- package/plugin/helpers/createRscStream.tsx +20 -14
- package/plugin/helpers/index.ts +2 -2
- package/plugin/helpers/inputNormalizer.ts +4 -2
- package/plugin/helpers/moduleResolver.ts +36 -0
- package/plugin/helpers/requestInfo.ts +117 -23
- package/plugin/helpers/resolvePage.ts +2 -3
- package/plugin/helpers/resolvePageAndProps.ts +7 -6
- package/plugin/helpers/serializeUserOptions.ts +20 -2
- package/plugin/helpers/sourceMap.ts +182 -0
- package/plugin/loader/createBuildLoader.ts +124 -104
- package/plugin/loader/createDefaultLoader.ts +62 -0
- package/plugin/loader/css-loader.development.ts +3 -2
- package/plugin/loader/handleExports.ts +276 -0
- package/plugin/loader/index.ts +6 -1
- package/plugin/loader/parse.ts +22 -0
- package/plugin/loader/react-loader.client.ts +1 -0
- package/plugin/loader/react-loader.server.ts +107 -0
- package/plugin/loader/react-loader.ts +4 -1002
- package/plugin/loader/sourceMap.ts +118 -0
- package/plugin/loader/transformModuleIfNeeded.ts +33 -0
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +119 -0
- package/plugin/loader/types.ts +10 -0
- package/plugin/plugin.client.ts +18 -11
- package/plugin/plugin.server.ts +6 -3
- package/plugin/preserver/plugin.ts +37 -17
- package/plugin/react-client/{server.ts → configureWorkerRequestHandler.ts} +22 -12
- package/plugin/react-client/createMessageHandlers.ts +21 -13
- package/plugin/react-client/createWorkerStream.ts +71 -33
- package/plugin/react-client/handleWorkerRscStream.ts +15 -5
- package/plugin/react-client/plugin.ts +18 -13
- package/plugin/react-client/restartWorker.ts +17 -5
- package/plugin/react-server/{server.ts → configureReactServer.ts} +40 -9
- package/plugin/react-server/handleServerAction.ts +177 -0
- package/plugin/react-server/plugin.ts +8 -3
- package/plugin/react-static/collectHtmlWorkerContent.ts +11 -3
- package/plugin/react-static/collectRscContent.ts +17 -9
- package/plugin/react-static/configurePreviewServer.ts +37 -17
- package/plugin/react-static/plugin.ts +45 -22
- package/plugin/react-static/renderPage.ts +12 -6
- package/plugin/react-static/renderPages.ts +15 -4
- package/plugin/react-static/renderStreams.ts +13 -12
- package/plugin/source-map/createMappingsSerializer.ts +182 -0
- package/plugin/source-map/readMappings.ts +195 -0
- package/plugin/transformer/README.md +295 -29
- package/plugin/transformer/index.ts +0 -1
- package/plugin/transformer/plugin.client.ts +0 -111
- package/plugin/transformer/plugin.server.ts +94 -25
- package/plugin/types/react-server-dom-esm.d.ts +183 -24
- package/plugin/types/sourceMap.d.ts +2 -0
- package/plugin/types/webpack-sources.d.ts +24 -0
- package/plugin/types.ts +169 -132
- package/plugin/utils/createCallServer.ts +21 -6
- package/plugin/utils/index.ts +2 -1
- package/plugin/vendor/vendor.client.ts +2 -1
- package/plugin/vendor/vendor.server.ts +1 -1
- package/plugin/worker/createWorker.ts +21 -24
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +31 -7
- package/plugin/worker/html/html-worker.development.tsx +16 -16
- package/plugin/worker/html/html-worker.production.tsx +3 -19
- package/plugin/worker/html/messageHandler.tsx +2 -4
- package/plugin/worker/rsc/handleRender.ts +15 -12
- package/plugin/worker/rsc/messageHandler.tsx +191 -120
- package/plugin/worker/rsc/rsc-worker.development.ts +148 -77
- package/plugin/worker/rsc/rsc-worker.production.ts +1 -1
- package/plugin/worker/rsc/state.ts +10 -0
- package/plugin/worker/sendMessage.ts +32 -14
- package/plugin/worker/types.ts +99 -64
- package/dist/plugin/react-client/server.d.ts.map +0 -1
- package/dist/plugin/react-client/server.js.map +0 -1
- package/dist/plugin/react-server/server.d.ts +0 -9
- package/dist/plugin/react-server/server.d.ts.map +0 -1
- package/dist/plugin/react-server/server.js.map +0 -1
- package/dist/plugin/transformer/plugin.client.js.map +0 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +0 -2
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +0 -1
- package/dist/plugin/transformer/upgradeCssModuleCode.js +0 -40
- package/dist/plugin/worker/loader.d.ts +0 -5
- package/dist/plugin/worker/loader.d.ts.map +0 -1
- package/dist/plugin/worker/loader.js +0 -11
- package/dist/plugin/worker/loader.js.map +0 -1
- package/plugin/transformer/upgradeCssModuleCode.ts +0 -42
- package/plugin/worker/loader.ts +0 -7
|
@@ -7,6 +7,7 @@ import type { StreamMetrics } from "../types.js";
|
|
|
7
7
|
import type { Worker as NodeWorker } from "node:worker_threads";
|
|
8
8
|
import type { StreamHandlers } from "../worker/types.js";
|
|
9
9
|
import { createMessageHandler } from "./createMessageHandlers.js";
|
|
10
|
+
import { logError } from "../error/toError.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Creates an async generator that yields RSC chunks from the worker.
|
|
@@ -22,71 +23,108 @@ export async function* createWorkerStream({
|
|
|
22
23
|
worker,
|
|
23
24
|
message,
|
|
24
25
|
logger,
|
|
25
|
-
handlers: {
|
|
26
|
+
handlers: {
|
|
27
|
+
onHmrAccept,
|
|
28
|
+
onHmrUpdate,
|
|
29
|
+
onMetrics,
|
|
30
|
+
onError,
|
|
31
|
+
onData,
|
|
32
|
+
onEnd,
|
|
33
|
+
onServerAction,
|
|
34
|
+
onServerActionResponse,
|
|
35
|
+
},
|
|
26
36
|
verbose = false,
|
|
27
37
|
}: {
|
|
28
38
|
worker: NodeWorker;
|
|
29
|
-
message: Omit<RscRenderMessage, "type" | "id"
|
|
39
|
+
message: Omit<RscRenderMessage, "type" | "id"> &
|
|
40
|
+
Partial<Pick<RscRenderMessage, "id">> & { type?: "RSC_RENDER" };
|
|
30
41
|
logger: Logger;
|
|
31
42
|
handlers: Pick<StreamHandlers, "onHmrAccept" | "onHmrUpdate" | "onMetrics"> &
|
|
32
|
-
Partial<
|
|
43
|
+
Partial<
|
|
44
|
+
Pick<
|
|
45
|
+
StreamHandlers,
|
|
46
|
+
| "onError"
|
|
47
|
+
| "onData"
|
|
48
|
+
| "onEnd"
|
|
49
|
+
| "onServerAction"
|
|
50
|
+
| "onServerActionResponse"
|
|
51
|
+
>
|
|
52
|
+
>;
|
|
33
53
|
verbose?: boolean;
|
|
34
54
|
}): AsyncGenerator<Uint8Array> {
|
|
55
|
+
if (!worker) {
|
|
56
|
+
throw new Error("Worker is not running");
|
|
57
|
+
}
|
|
35
58
|
let messageHandler:
|
|
36
59
|
| ((message: RscWorkerOutputMessage | undefined) => void)
|
|
37
60
|
| null = null;
|
|
38
61
|
let currentResolve: ((chunk: Uint8Array) => void) | null = null;
|
|
39
62
|
const handlers: StreamHandlers = {
|
|
40
|
-
onError: (error
|
|
41
|
-
logger
|
|
42
|
-
"[react-client] " +
|
|
43
|
-
(error.stack ?? error.stack.includes(error.message) ? "" : error.message + "\n") +
|
|
44
|
-
error.stack,
|
|
45
|
-
{
|
|
46
|
-
error,
|
|
47
|
-
}
|
|
48
|
-
);
|
|
63
|
+
onError: (id, error, errorInfo) => {
|
|
64
|
+
logError(error, logger);
|
|
49
65
|
if (errorInfo) {
|
|
50
|
-
|
|
66
|
+
logError(errorInfo.componentStack, logger);
|
|
51
67
|
}
|
|
52
68
|
if (typeof onError === "function") {
|
|
53
|
-
onError(error, errorInfo);
|
|
69
|
+
onError(id, error, errorInfo);
|
|
54
70
|
}
|
|
55
71
|
},
|
|
56
|
-
onData: (chunk: Uint8Array) => {
|
|
72
|
+
onData: (id: string, chunk: Uint8Array) => {
|
|
57
73
|
currentResolve?.(chunk);
|
|
58
|
-
if (verbose)
|
|
74
|
+
if (verbose) {
|
|
75
|
+
logger.info(
|
|
76
|
+
`[react-client] received chunk ${id} ${
|
|
77
|
+
Buffer.from(chunk).byteLength
|
|
78
|
+
} bytes`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
59
81
|
if (typeof onData === "function") {
|
|
60
|
-
onData(chunk);
|
|
82
|
+
onData(id, chunk);
|
|
61
83
|
}
|
|
62
84
|
},
|
|
63
|
-
onEnd: () => {
|
|
85
|
+
onEnd: (id: string) => {
|
|
64
86
|
currentResolve?.(new Uint8Array());
|
|
65
|
-
if (verbose) logger.info(`received end`);
|
|
87
|
+
if (verbose) logger.info(`[react-client] received end`);
|
|
66
88
|
if (messageHandler) {
|
|
67
89
|
worker.removeListener("message", messageHandler);
|
|
68
90
|
messageHandler = null;
|
|
69
91
|
}
|
|
70
92
|
if (typeof onEnd === "function") {
|
|
71
|
-
onEnd();
|
|
93
|
+
onEnd(id);
|
|
72
94
|
}
|
|
73
95
|
},
|
|
74
|
-
onMetrics: (metrics: StreamMetrics) => {
|
|
75
|
-
if (verbose)
|
|
96
|
+
onMetrics: (id: string, metrics: StreamMetrics) => {
|
|
97
|
+
if (verbose)
|
|
98
|
+
logger.info(`[react-client] received chunks ${metrics.chunks}`);
|
|
76
99
|
if (typeof onMetrics === "function") {
|
|
77
|
-
onMetrics(metrics);
|
|
100
|
+
onMetrics(id, metrics);
|
|
78
101
|
}
|
|
79
102
|
},
|
|
80
|
-
onHmrAccept: (
|
|
81
|
-
if (verbose)
|
|
103
|
+
onHmrAccept: (id: string, routes?: string[]) => {
|
|
104
|
+
if (verbose)
|
|
105
|
+
logger.info(`[react-client] received hmr accept ${routes?.join(", ")}`);
|
|
82
106
|
if (typeof onHmrAccept === "function") {
|
|
83
|
-
onHmrAccept(routes);
|
|
107
|
+
onHmrAccept(id, routes);
|
|
84
108
|
}
|
|
85
109
|
},
|
|
86
|
-
onHmrUpdate: (
|
|
87
|
-
if (verbose)
|
|
110
|
+
onHmrUpdate: (id: string, routes?: string[]) => {
|
|
111
|
+
if (verbose)
|
|
112
|
+
logger.info(`[react-client] received hmr update ${routes?.join(", ")}`);
|
|
88
113
|
if (typeof onHmrUpdate === "function") {
|
|
89
|
-
onHmrUpdate(routes);
|
|
114
|
+
onHmrUpdate(id, routes);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
onServerAction: (id: string, args: unknown[]) => {
|
|
118
|
+
if (verbose) logger.info(`[react-client] received server action ${id}`);
|
|
119
|
+
if (typeof onServerAction === "function") {
|
|
120
|
+
onServerAction(id, args);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
onServerActionResponse: (id: string, result?: unknown, error?: string) => {
|
|
124
|
+
if (verbose)
|
|
125
|
+
logger.info(`[react-client] received server action response ${id}`);
|
|
126
|
+
if (typeof onServerActionResponse === "function") {
|
|
127
|
+
onServerActionResponse(id, result, error);
|
|
90
128
|
}
|
|
91
129
|
},
|
|
92
130
|
};
|
|
@@ -97,14 +135,14 @@ export async function* createWorkerStream({
|
|
|
97
135
|
worker.removeListener("message", messageHandler);
|
|
98
136
|
messageHandler = null;
|
|
99
137
|
}
|
|
100
|
-
if (verbose) logger.info(`sending message RSC_RENDER`);
|
|
138
|
+
if (verbose) logger.info(`[react-client] sending message RSC_RENDER`);
|
|
101
139
|
worker.postMessage({
|
|
102
140
|
...message,
|
|
103
141
|
type: "RSC_RENDER",
|
|
104
|
-
id:
|
|
142
|
+
id: message?.id ?? message.route,
|
|
105
143
|
});
|
|
106
144
|
|
|
107
|
-
if (verbose) logger.info(`waiting for message handler`);
|
|
145
|
+
if (verbose) logger.info(`[react-client] waiting for message handler`);
|
|
108
146
|
let workerTimeout: NodeJS.Timeout | null = null;
|
|
109
147
|
yield await new Promise<Uint8Array>((resolve) => {
|
|
110
148
|
workerTimeout = setTimeout(() => {
|
|
@@ -122,7 +160,7 @@ export async function* createWorkerStream({
|
|
|
122
160
|
if (workerTimeout) {
|
|
123
161
|
clearTimeout(workerTimeout);
|
|
124
162
|
}
|
|
125
|
-
if (verbose) logger.info(`received message handler`);
|
|
163
|
+
if (verbose) logger.info(`[react-client] received message handler`);
|
|
126
164
|
while (true) {
|
|
127
165
|
const chunk = await new Promise<Uint8Array>((resolve) => {
|
|
128
166
|
currentResolve = resolve;
|
|
@@ -21,7 +21,7 @@ export function handleWorkerRscStream({
|
|
|
21
21
|
message: Omit<RscRenderMessage, "type" | "id">,
|
|
22
22
|
logger: Logger,
|
|
23
23
|
handlers: Pick<StreamHandlers, "onMetrics" | "onHmrAccept" | "onHmrUpdate"> &
|
|
24
|
-
Partial<Pick<StreamHandlers, "onError" | "onData" | "onEnd">>,
|
|
24
|
+
Partial<Pick<StreamHandlers, "onError" | "onData" | "onEnd" | "onServerAction" | "onServerActionResponse">>,
|
|
25
25
|
verbose?: boolean
|
|
26
26
|
}): ReadableStream<Uint8Array> {
|
|
27
27
|
// Create a ReadableStream from the async generator
|
|
@@ -29,17 +29,27 @@ export function handleWorkerRscStream({
|
|
|
29
29
|
return new ReadableStream<Uint8Array>({
|
|
30
30
|
async start(controller) {
|
|
31
31
|
try {
|
|
32
|
-
if(verbose) logger.info("Starting stream");
|
|
32
|
+
if(verbose) logger.info("[react-client] Starting stream");
|
|
33
33
|
for await (const chunk of createWorkerStream({
|
|
34
34
|
worker,
|
|
35
35
|
message,
|
|
36
36
|
logger,
|
|
37
|
-
handlers
|
|
37
|
+
handlers: {
|
|
38
|
+
...handlers,
|
|
39
|
+
onServerAction: (id: string, args: unknown[]) => {
|
|
40
|
+
if (verbose) logger.info(`[react-client] Received server action ${id}`);
|
|
41
|
+
handlers.onServerAction?.(id, args);
|
|
42
|
+
},
|
|
43
|
+
onServerActionResponse: (id: string, result?: unknown, error?: string) => {
|
|
44
|
+
if (verbose) logger.info(`[react-client] Received server action response ${id}`);
|
|
45
|
+
handlers.onServerActionResponse?.(id, result, error);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
38
48
|
verbose
|
|
39
49
|
})) {
|
|
40
50
|
if (!isFlowing) {
|
|
41
51
|
isFlowing = true;
|
|
42
|
-
if(verbose) logger.info("Stream is flowing");
|
|
52
|
+
if(verbose) logger.info("[react-client] Stream is flowing");
|
|
43
53
|
}
|
|
44
54
|
controller.enqueue(chunk);
|
|
45
55
|
}
|
|
@@ -48,7 +58,7 @@ export function handleWorkerRscStream({
|
|
|
48
58
|
} finally {
|
|
49
59
|
if (isFlowing) {
|
|
50
60
|
isFlowing = false;
|
|
51
|
-
if(verbose) logger.info("Stream closing");
|
|
61
|
+
if(verbose) logger.info("[react-client] Stream closing");
|
|
52
62
|
}
|
|
53
63
|
controller.close();
|
|
54
64
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ConfigEnv, type Plugin } from "vite";
|
|
2
2
|
import type {
|
|
3
3
|
AutoDiscoveredFiles,
|
|
4
|
+
InlineCssOpt,
|
|
5
|
+
PagePropOpt,
|
|
4
6
|
ResolvedUserConfig,
|
|
5
7
|
ResolvedUserOptions,
|
|
6
8
|
StreamPluginOptions,
|
|
@@ -8,18 +10,21 @@ import type {
|
|
|
8
10
|
import { resolveOptions } from "../config/resolveOptions.js";
|
|
9
11
|
import { resolveUserConfig } from "../config/resolveUserConfig.js";
|
|
10
12
|
import { resolveAutoDiscover } from "../config/autoDiscover/resolveAutoDiscover.js";
|
|
11
|
-
import { configureWorkerRequestHandler } from "./
|
|
13
|
+
import { configureWorkerRequestHandler } from "./configureWorkerRequestHandler.js";
|
|
12
14
|
import { configurePreviewServer } from "../react-static/configurePreviewServer.js";
|
|
13
15
|
import { MessageChannel } from "node:worker_threads";
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
let
|
|
17
|
+
export function reactClientPlugin<
|
|
18
|
+
T extends PagePropOpt = PagePropOpt,
|
|
19
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
20
|
+
>(options: StreamPluginOptions<T, InlineCSS>): Plugin {
|
|
21
|
+
let userOptions: ResolvedUserOptions<T, InlineCSS>;
|
|
22
|
+
let userConfig: ResolvedUserConfig;
|
|
23
|
+
let configEnv: ConfigEnv;
|
|
24
|
+
let root: string;
|
|
25
|
+
let autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
26
|
+
let hmrChannel: MessageChannel | null = null;
|
|
21
27
|
|
|
22
|
-
export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
23
28
|
const resolvedOptions = resolveOptions(options);
|
|
24
29
|
if (resolvedOptions.type === "error") {
|
|
25
30
|
throw resolvedOptions.error;
|
|
@@ -53,7 +58,7 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
53
58
|
}
|
|
54
59
|
autoDiscoveredFiles = autoDiscoverResult.autoDiscoveredFiles;
|
|
55
60
|
|
|
56
|
-
const resolvedConfig = resolveUserConfig({
|
|
61
|
+
const resolvedConfig = resolveUserConfig<T, InlineCSS>({
|
|
57
62
|
condition: "react-client",
|
|
58
63
|
config,
|
|
59
64
|
configEnv,
|
|
@@ -66,10 +71,10 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
userConfig = resolvedConfig.userConfig;
|
|
69
|
-
return userConfig
|
|
74
|
+
return userConfig;
|
|
70
75
|
},
|
|
71
76
|
async configurePreviewServer(server) {
|
|
72
|
-
await configurePreviewServer({
|
|
77
|
+
await configurePreviewServer<T, InlineCSS>({
|
|
73
78
|
server,
|
|
74
79
|
userOptions,
|
|
75
80
|
});
|
|
@@ -92,7 +97,7 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
92
97
|
async configureServer(server) {
|
|
93
98
|
// Create HMR message channel
|
|
94
99
|
hmrChannel = new MessageChannel();
|
|
95
|
-
await configureWorkerRequestHandler({
|
|
100
|
+
await configureWorkerRequestHandler<T, InlineCSS>({
|
|
96
101
|
server,
|
|
97
102
|
autoDiscoveredFiles,
|
|
98
103
|
userOptions,
|
|
@@ -112,7 +117,7 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
|
|
|
112
117
|
|
|
113
118
|
// Find all routes affected by this file change
|
|
114
119
|
const affectedRoutes = autoDiscoveredFiles.routeMap.get(value) || [];
|
|
115
|
-
|
|
120
|
+
|
|
116
121
|
// Send HMR update directly to worker through MessageChannel
|
|
117
122
|
if (hmrChannel?.port1) {
|
|
118
123
|
hmrChannel.port1.postMessage({
|
|
@@ -5,7 +5,7 @@ import type { AutoDiscoveredFiles } from "../../types.js";
|
|
|
5
5
|
import { createWorker } from "../worker/createWorker.js";
|
|
6
6
|
import { serializedDevServerConfig } from "../helpers/serializeUserOptions.js";
|
|
7
7
|
import { serializedOptions } from "../helpers/serializeUserOptions.js";
|
|
8
|
-
import
|
|
8
|
+
import { MessageChannel, type Worker } from "node:worker_threads";
|
|
9
9
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
10
10
|
|
|
11
11
|
let currentWorker: Worker | null = null;
|
|
@@ -23,7 +23,7 @@ export async function restartWorker({
|
|
|
23
23
|
hmrChannel: MessageChannel,
|
|
24
24
|
}) {
|
|
25
25
|
if (isRestarting) {
|
|
26
|
-
|
|
26
|
+
return currentWorker;
|
|
27
27
|
}
|
|
28
28
|
isRestarting = true;
|
|
29
29
|
|
|
@@ -33,9 +33,19 @@ export async function restartWorker({
|
|
|
33
33
|
currentWorker.removeAllListeners();
|
|
34
34
|
currentWorker = null;
|
|
35
35
|
}
|
|
36
|
+
|
|
36
37
|
const routeCount = autoDiscoveredFiles.urlMap.size;
|
|
37
38
|
const hmrBuffer = 20; // Buffer for HMR and other operations
|
|
38
39
|
const maxListeners = routeCount + hmrBuffer;
|
|
40
|
+
|
|
41
|
+
// Create a new MessageChannel for this worker
|
|
42
|
+
const workerHmrChannel = new MessageChannel();
|
|
43
|
+
|
|
44
|
+
// Forward messages from the plugin's HMR channel to the worker's channel
|
|
45
|
+
hmrChannel.port1.addEventListener('message', (event: Event) => {
|
|
46
|
+
workerHmrChannel.port1.postMessage((event as MessageEvent).data);
|
|
47
|
+
});
|
|
48
|
+
|
|
39
49
|
const workerResult = await createWorker({
|
|
40
50
|
projectRoot: server.config.root,
|
|
41
51
|
workerPath: userOptions.rscWorkerPath,
|
|
@@ -49,11 +59,11 @@ export async function restartWorker({
|
|
|
49
59
|
? server.config.envPrefix[0]
|
|
50
60
|
: DEFAULT_CONFIG.ENV_PREFIX,
|
|
51
61
|
workerData: {
|
|
52
|
-
hmrPort:
|
|
62
|
+
hmrPort: workerHmrChannel.port2,
|
|
53
63
|
resolvedConfig: serializedDevServerConfig(server.config),
|
|
54
64
|
userOptions: serializedOptions(userOptions, autoDiscoveredFiles),
|
|
55
65
|
},
|
|
56
|
-
transferList: [
|
|
66
|
+
transferList: [workerHmrChannel.port2],
|
|
57
67
|
});
|
|
58
68
|
|
|
59
69
|
if (workerResult.type === "success") {
|
|
@@ -65,9 +75,11 @@ export async function restartWorker({
|
|
|
65
75
|
server.config.logger.error("Failed to start rsc-worker", {
|
|
66
76
|
error: workerResult.error,
|
|
67
77
|
});
|
|
78
|
+
throw workerResult.error;
|
|
68
79
|
}
|
|
69
80
|
} finally {
|
|
70
81
|
isRestarting = false;
|
|
71
82
|
}
|
|
83
|
+
|
|
72
84
|
return currentWorker;
|
|
73
|
-
|
|
85
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Manifest, ViteDevServer } from "vite";
|
|
2
2
|
import type { ServerResponse } from "http";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
AutoDiscoveredFiles,
|
|
5
|
+
InlineCssOpt,
|
|
6
|
+
PagePropOpt,
|
|
7
|
+
ResolvedUserOptions,
|
|
8
|
+
} from "../types.js";
|
|
4
9
|
import { createEventHandler } from "../helpers/createEventHandler.js";
|
|
5
10
|
import { collectViteModuleGraphCss } from "../helpers/collectViteModuleGraphCss.js";
|
|
6
11
|
import { resolvePageAndProps } from "../helpers/resolvePageAndProps.js";
|
|
@@ -8,9 +13,13 @@ import { createHandler } from "../helpers/createHandler.js";
|
|
|
8
13
|
import React from "react";
|
|
9
14
|
import { requestInfo } from "../helpers/requestInfo.js";
|
|
10
15
|
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
11
|
-
import {
|
|
16
|
+
import { logError } from "../error/toError.js";
|
|
17
|
+
import { handleServerAction } from "./handleServerAction.js";
|
|
12
18
|
|
|
13
|
-
export async function configureReactServer
|
|
19
|
+
export async function configureReactServer<
|
|
20
|
+
T extends PagePropOpt = PagePropOpt,
|
|
21
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
22
|
+
>({
|
|
14
23
|
server,
|
|
15
24
|
autoDiscoveredFiles,
|
|
16
25
|
userOptions: _userOptions,
|
|
@@ -18,7 +27,7 @@ export async function configureReactServer({
|
|
|
18
27
|
}: {
|
|
19
28
|
server: ViteDevServer;
|
|
20
29
|
autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
21
|
-
userOptions: ResolvedUserOptions
|
|
30
|
+
userOptions: ResolvedUserOptions<T, InlineCSS>;
|
|
22
31
|
serverManifest: Manifest;
|
|
23
32
|
}) {
|
|
24
33
|
const activeStreams = new Set<ServerResponse>();
|
|
@@ -30,10 +39,26 @@ export async function configureReactServer({
|
|
|
30
39
|
projectRoot: _projectRoot,
|
|
31
40
|
...handlerUserOptions
|
|
32
41
|
} = _userOptions;
|
|
33
|
-
const handlerOptions =
|
|
42
|
+
const handlerOptions = {
|
|
43
|
+
...handlerUserOptions,
|
|
34
44
|
moduleBaseURL: server.config.base,
|
|
35
45
|
projectRoot: server.config.root,
|
|
36
|
-
|
|
46
|
+
Html: React.Fragment,
|
|
47
|
+
onEvent: createEventHandler(onEvent),
|
|
48
|
+
css: handlerUserOptions.css
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Set environment-specific configuration
|
|
52
|
+
const define = {
|
|
53
|
+
...server.config.define,
|
|
54
|
+
"process.env.NODE_ENV": JSON.stringify(
|
|
55
|
+
process.env["NODE_ENV"] || "development"
|
|
56
|
+
),
|
|
57
|
+
};
|
|
58
|
+
server.config = {
|
|
59
|
+
...server.config,
|
|
60
|
+
define,
|
|
61
|
+
};
|
|
37
62
|
|
|
38
63
|
// Handle Vite server restarts
|
|
39
64
|
server.ws.on("restart", (path) => {
|
|
@@ -59,7 +84,13 @@ export async function configureReactServer({
|
|
|
59
84
|
if (!req.url) {
|
|
60
85
|
return next();
|
|
61
86
|
}
|
|
62
|
-
const info = requestInfo(req, handlerOptions, "");
|
|
87
|
+
const info = requestInfo(req, handlerOptions, "", server.config.logger);
|
|
88
|
+
|
|
89
|
+
// Handle server actions
|
|
90
|
+
if (info.isServerActionRequest) {
|
|
91
|
+
return handleServerAction(req, res, server, handlerOptions);
|
|
92
|
+
}
|
|
93
|
+
|
|
63
94
|
if (!info.isRscRequest) return next();
|
|
64
95
|
try {
|
|
65
96
|
const routeFiles = await getRouteFiles(
|
|
@@ -109,7 +140,7 @@ export async function configureReactServer({
|
|
|
109
140
|
}
|
|
110
141
|
const { PageComponent, pageProps } = pageAndPropsResult;
|
|
111
142
|
// Create the headless RSC stream directly;
|
|
112
|
-
const rscResult =
|
|
143
|
+
const rscResult = createHandler({
|
|
113
144
|
...handlerOptions,
|
|
114
145
|
PageComponent: PageComponent,
|
|
115
146
|
pageProps: pageProps,
|
|
@@ -135,7 +166,7 @@ export async function configureReactServer({
|
|
|
135
166
|
activeStreams.delete(res);
|
|
136
167
|
});
|
|
137
168
|
} catch (error) {
|
|
138
|
-
server.config.logger
|
|
169
|
+
logError(error, server.config.logger);
|
|
139
170
|
res.end();
|
|
140
171
|
}
|
|
141
172
|
});
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { ViteDevServer } from "vite";
|
|
2
|
+
import type {
|
|
3
|
+
InlineCssOpt,
|
|
4
|
+
PagePropOpt,
|
|
5
|
+
ResolvedUserOptions,
|
|
6
|
+
} from "../types.js";
|
|
7
|
+
import { logError, toError } from "../error/toError.js";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { ReactDOMServer } from "../vendor/vendor.server.js";
|
|
10
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
11
|
+
|
|
12
|
+
export async function handleServerAction<
|
|
13
|
+
T extends PagePropOpt,
|
|
14
|
+
InlineCss extends InlineCssOpt
|
|
15
|
+
>(
|
|
16
|
+
req: IncomingMessage,
|
|
17
|
+
res: ServerResponse,
|
|
18
|
+
server: ViteDevServer,
|
|
19
|
+
handlerOptions: ResolvedUserOptions<T, InlineCss>
|
|
20
|
+
) {
|
|
21
|
+
try {
|
|
22
|
+
if (handlerOptions.verbose) {
|
|
23
|
+
server.config.logger.info(
|
|
24
|
+
`[react-server] Handling server action request at ${req.url}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Parse the request body - handle both formats:
|
|
29
|
+
// 1. Direct args array: ["arg1", "arg2"]
|
|
30
|
+
// 2. Object with id and args: { id: "path/to/action", args: ["arg1", "arg2"] }
|
|
31
|
+
let id: string;
|
|
32
|
+
let args: unknown[];
|
|
33
|
+
try {
|
|
34
|
+
const chunks: Buffer[] = [];
|
|
35
|
+
for await (const chunk of req) {
|
|
36
|
+
chunks.push(chunk);
|
|
37
|
+
}
|
|
38
|
+
const body = Buffer.concat(chunks).toString();
|
|
39
|
+
if (handlerOptions.verbose) {
|
|
40
|
+
server.config.logger.info(`[react-server] Request body: ${body}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const parsed = JSON.parse(body);
|
|
44
|
+
if (Array.isArray(parsed)) {
|
|
45
|
+
// Format 1: Direct args array
|
|
46
|
+
args = parsed;
|
|
47
|
+
// Get the action ID from the request URL
|
|
48
|
+
id = req.url?.split("?")[0] ?? "";
|
|
49
|
+
if (handlerOptions.verbose) {
|
|
50
|
+
server.config.logger.info(
|
|
51
|
+
`[react-server] Using action ID from URL: ${id}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
} else if (parsed && typeof parsed === "object" && "id" in parsed) {
|
|
55
|
+
// Format 2: Object with id and args
|
|
56
|
+
id = parsed.id;
|
|
57
|
+
args = parsed.args ?? [];
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error("Invalid server action request format");
|
|
60
|
+
}
|
|
61
|
+
} catch (error: unknown) {
|
|
62
|
+
const err = toError(error);
|
|
63
|
+
throw new Error(`Failed to parse server action request`, {
|
|
64
|
+
cause: err,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!id) {
|
|
69
|
+
throw new Error("Server action ID is required");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (handlerOptions.verbose) {
|
|
73
|
+
server.config.logger.info(
|
|
74
|
+
`[react-server] Server action request for ${id} with args: ${JSON.stringify(
|
|
75
|
+
args
|
|
76
|
+
)}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Parse the server action ID to get the file path and export name
|
|
81
|
+
const [filePath, exportName] = id.split("#");
|
|
82
|
+
if (!filePath || !exportName) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Invalid server action ID format: ${id}. Expected format: "path/to/file.ts#exportName"`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Convert the server action ID to a file path
|
|
89
|
+
const actionPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
90
|
+
const fullPath = join(handlerOptions.projectRoot, actionPath);
|
|
91
|
+
if (handlerOptions.verbose) {
|
|
92
|
+
server.config.logger.info(
|
|
93
|
+
`[react-server] Resolved file path: id=${id}, actionPath=${actionPath}, projectRoot=${handlerOptions.projectRoot}, filePath=${fullPath}, exportName=${exportName}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Load the server action module
|
|
98
|
+
if (handlerOptions.verbose) {
|
|
99
|
+
server.config.logger.info(`[react-server] Loading module: ${fullPath}`);
|
|
100
|
+
}
|
|
101
|
+
const module = await server.ssrLoadModule(fullPath);
|
|
102
|
+
if (handlerOptions.verbose) {
|
|
103
|
+
server.config.logger.info(
|
|
104
|
+
`[react-server] Looking for action: ${exportName} in module with exports: ${Object.keys(
|
|
105
|
+
module
|
|
106
|
+
).join(", ")}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const action = module[exportName];
|
|
110
|
+
|
|
111
|
+
if (typeof action !== "function") {
|
|
112
|
+
if (handlerOptions.verbose) {
|
|
113
|
+
server.config.logger.error(
|
|
114
|
+
`[react-server] Action not found: ${exportName} in module with exports: ${Object.keys(
|
|
115
|
+
module
|
|
116
|
+
).join(", ")}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
throw new Error(`Server action not found: ${id}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Execute the server action
|
|
123
|
+
if (handlerOptions.verbose) {
|
|
124
|
+
server.config.logger.info(
|
|
125
|
+
`[react-server] Executing action with args: ${JSON.stringify(args)}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const result = await action(...args);
|
|
129
|
+
if (handlerOptions.verbose) {
|
|
130
|
+
server.config.logger.info(
|
|
131
|
+
`[react-server] Action completed successfully with result: ${JSON.stringify(
|
|
132
|
+
result
|
|
133
|
+
)}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Send the response
|
|
138
|
+
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
139
|
+
|
|
140
|
+
const { pipe } = ReactDOMServer.renderToPipeableStream(
|
|
141
|
+
{
|
|
142
|
+
type: "server-action-response",
|
|
143
|
+
returnValue: result,
|
|
144
|
+
},
|
|
145
|
+
handlerOptions.moduleBasePath,
|
|
146
|
+
{
|
|
147
|
+
onError(error: Error) {
|
|
148
|
+
logError(error, server.config.logger);
|
|
149
|
+
res.statusCode = 500;
|
|
150
|
+
res.end();
|
|
151
|
+
},
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
pipe(res);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
logError(error, server.config.logger);
|
|
158
|
+
res.statusCode = 500;
|
|
159
|
+
res.setHeader("Content-Type", "text/x-component; charset=utf-8");
|
|
160
|
+
|
|
161
|
+
const { pipe } = ReactDOMServer.renderToPipeableStream(
|
|
162
|
+
{
|
|
163
|
+
type: "server-action-response",
|
|
164
|
+
error: toError(error).message,
|
|
165
|
+
},
|
|
166
|
+
handlerOptions.moduleBasePath,
|
|
167
|
+
{
|
|
168
|
+
onError(error: Error) {
|
|
169
|
+
logError(error, server.config.logger);
|
|
170
|
+
res.end();
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
pipe(res);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -13,13 +13,15 @@ import type {
|
|
|
13
13
|
BuildTiming,
|
|
14
14
|
ReactStreamPluginMeta,
|
|
15
15
|
ResolvedUserOptions,
|
|
16
|
+
PagePropOpt,
|
|
17
|
+
InlineCssOpt,
|
|
16
18
|
} from "../types.js";
|
|
17
19
|
import { type StreamPluginOptions } from "../types.js";
|
|
18
20
|
import {
|
|
19
21
|
resolveAutoDiscover
|
|
20
22
|
} from "../config/autoDiscover/resolveAutoDiscover.js";
|
|
21
23
|
import { getCondition } from "../config/getCondition.js";
|
|
22
|
-
import { configureReactServer } from "./
|
|
24
|
+
import { configureReactServer } from "./configureReactServer.js";
|
|
23
25
|
import { configurePreviewServer } from "../react-static/configurePreviewServer.js";
|
|
24
26
|
import { getBundleManifest } from "../helpers/getBundleManifest.js";
|
|
25
27
|
|
|
@@ -31,7 +33,10 @@ if (getCondition() !== "react-server") {
|
|
|
31
33
|
process.env["NODE_OPTIONS"]
|
|
32
34
|
);
|
|
33
35
|
}
|
|
34
|
-
export function reactServerPlugin
|
|
36
|
+
export function reactServerPlugin<
|
|
37
|
+
T extends PagePropOpt = PagePropOpt,
|
|
38
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
39
|
+
>(options: StreamPluginOptions<T, InlineCSS>): VitePlugin<{
|
|
35
40
|
meta: ReactStreamPluginMeta;
|
|
36
41
|
}> {
|
|
37
42
|
const timing: BuildTiming = {
|
|
@@ -39,7 +44,7 @@ export function reactServerPlugin(options: StreamPluginOptions): VitePlugin<{
|
|
|
39
44
|
};
|
|
40
45
|
|
|
41
46
|
let autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
42
|
-
let userOptions: ResolvedUserOptions
|
|
47
|
+
let userOptions: ResolvedUserOptions<T, InlineCSS>;
|
|
43
48
|
let serverManifest: Manifest = {};
|
|
44
49
|
|
|
45
50
|
const resolvedOptions = resolveOptions(options);
|