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
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// alternative to webpack-sources/lib/helpers/readMappings.js
|
|
2
|
+
// unused for now, but it's a dependency of react-server-dom-esm and you may or may not want to download webpack-sources
|
|
3
|
+
export function readMappings(
|
|
4
|
+
mappings: string,
|
|
5
|
+
onMapping: (
|
|
6
|
+
generatedLine: number,
|
|
7
|
+
generatedColumn: number,
|
|
8
|
+
sourceIndex: number,
|
|
9
|
+
originalLine: number,
|
|
10
|
+
originalColumn: number,
|
|
11
|
+
nameIndex: number
|
|
12
|
+
) => void
|
|
13
|
+
) {
|
|
14
|
+
let generatedLine = 1;
|
|
15
|
+
let generatedColumn = 0;
|
|
16
|
+
let sourceIndex = 0;
|
|
17
|
+
let originalLine = 1;
|
|
18
|
+
let originalColumn = 0;
|
|
19
|
+
let nameIndex = 0;
|
|
20
|
+
let i = 0;
|
|
21
|
+
while (i < mappings.length) {
|
|
22
|
+
if (mappings[i] === ";") {
|
|
23
|
+
generatedLine++;
|
|
24
|
+
generatedColumn = 0;
|
|
25
|
+
i++;
|
|
26
|
+
} else if (mappings[i] === ",") {
|
|
27
|
+
i++;
|
|
28
|
+
} else {
|
|
29
|
+
let value = 0;
|
|
30
|
+
let shift = 0;
|
|
31
|
+
let hasMore = true;
|
|
32
|
+
while (hasMore) {
|
|
33
|
+
const c = mappings.charCodeAt(i++);
|
|
34
|
+
if (c >= 65 && c <= 90) {
|
|
35
|
+
value += (c - 65) << shift;
|
|
36
|
+
} else if (c >= 97 && c <= 122) {
|
|
37
|
+
value += (c - 97) << shift;
|
|
38
|
+
} else if (c >= 48 && c <= 57) {
|
|
39
|
+
value += (c - 48 + 26) << shift;
|
|
40
|
+
} else if (c === 43) {
|
|
41
|
+
value += 62 << shift;
|
|
42
|
+
} else if (c === 47) {
|
|
43
|
+
value += 63 << shift;
|
|
44
|
+
} else {
|
|
45
|
+
hasMore = false;
|
|
46
|
+
}
|
|
47
|
+
if (hasMore) {
|
|
48
|
+
shift += 6;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
let isNegative = value & 1;
|
|
52
|
+
value = value >> 1;
|
|
53
|
+
if (isNegative) {
|
|
54
|
+
value = -value;
|
|
55
|
+
}
|
|
56
|
+
generatedColumn += value;
|
|
57
|
+
if (i < mappings.length && mappings[i] !== ";" && mappings[i] !== ",") {
|
|
58
|
+
value = 0;
|
|
59
|
+
shift = 0;
|
|
60
|
+
hasMore = true;
|
|
61
|
+
while (hasMore) {
|
|
62
|
+
const c = mappings.charCodeAt(i++);
|
|
63
|
+
if (c >= 65 && c <= 90) {
|
|
64
|
+
value += (c - 65) << shift;
|
|
65
|
+
} else if (c >= 97 && c <= 122) {
|
|
66
|
+
value += (c - 97) << shift;
|
|
67
|
+
} else if (c >= 48 && c <= 57) {
|
|
68
|
+
value += (c - 48 + 26) << shift;
|
|
69
|
+
} else if (c === 43) {
|
|
70
|
+
value += 62 << shift;
|
|
71
|
+
} else if (c === 47) {
|
|
72
|
+
value += 63 << shift;
|
|
73
|
+
} else {
|
|
74
|
+
hasMore = false;
|
|
75
|
+
}
|
|
76
|
+
if (hasMore) {
|
|
77
|
+
shift += 6;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
isNegative = value & 1;
|
|
81
|
+
value = value >> 1;
|
|
82
|
+
if (isNegative) {
|
|
83
|
+
value = -value;
|
|
84
|
+
}
|
|
85
|
+
sourceIndex += value;
|
|
86
|
+
if (i < mappings.length && mappings[i] !== ";" && mappings[i] !== ",") {
|
|
87
|
+
value = 0;
|
|
88
|
+
shift = 0;
|
|
89
|
+
hasMore = true;
|
|
90
|
+
while (hasMore) {
|
|
91
|
+
const c = mappings.charCodeAt(i++);
|
|
92
|
+
if (c >= 65 && c <= 90) {
|
|
93
|
+
value += (c - 65) << shift;
|
|
94
|
+
} else if (c >= 97 && c <= 122) {
|
|
95
|
+
value += (c - 97) << shift;
|
|
96
|
+
} else if (c >= 48 && c <= 57) {
|
|
97
|
+
value += (c - 48 + 26) << shift;
|
|
98
|
+
} else if (c === 43) {
|
|
99
|
+
value += 62 << shift;
|
|
100
|
+
} else if (c === 47) {
|
|
101
|
+
value += 63 << shift;
|
|
102
|
+
} else {
|
|
103
|
+
hasMore = false;
|
|
104
|
+
}
|
|
105
|
+
if (hasMore) {
|
|
106
|
+
shift += 6;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
isNegative = value & 1;
|
|
110
|
+
value = value >> 1;
|
|
111
|
+
if (isNegative) {
|
|
112
|
+
value = -value;
|
|
113
|
+
}
|
|
114
|
+
originalLine += value;
|
|
115
|
+
if (
|
|
116
|
+
i < mappings.length &&
|
|
117
|
+
mappings[i] !== ";" &&
|
|
118
|
+
mappings[i] !== ","
|
|
119
|
+
) {
|
|
120
|
+
value = 0;
|
|
121
|
+
shift = 0;
|
|
122
|
+
hasMore = true;
|
|
123
|
+
while (hasMore) {
|
|
124
|
+
const c = mappings.charCodeAt(i++);
|
|
125
|
+
if (c >= 65 && c <= 90) {
|
|
126
|
+
value += (c - 65) << shift;
|
|
127
|
+
} else if (c >= 97 && c <= 122) {
|
|
128
|
+
value += (c - 97) << shift;
|
|
129
|
+
} else if (c >= 48 && c <= 57) {
|
|
130
|
+
value += (c - 48 + 26) << shift;
|
|
131
|
+
} else if (c === 43) {
|
|
132
|
+
value += 62 << shift;
|
|
133
|
+
} else if (c === 47) {
|
|
134
|
+
value += 63 << shift;
|
|
135
|
+
} else {
|
|
136
|
+
hasMore = false;
|
|
137
|
+
}
|
|
138
|
+
if (hasMore) {
|
|
139
|
+
shift += 6;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
isNegative = value & 1;
|
|
143
|
+
value = value >> 1;
|
|
144
|
+
if (isNegative) {
|
|
145
|
+
value = -value;
|
|
146
|
+
}
|
|
147
|
+
originalColumn += value;
|
|
148
|
+
if (
|
|
149
|
+
i < mappings.length &&
|
|
150
|
+
mappings[i] !== ";" &&
|
|
151
|
+
mappings[i] !== ","
|
|
152
|
+
) {
|
|
153
|
+
value = 0;
|
|
154
|
+
shift = 0;
|
|
155
|
+
hasMore = true;
|
|
156
|
+
while (hasMore) {
|
|
157
|
+
const c = mappings.charCodeAt(i++);
|
|
158
|
+
if (c >= 65 && c <= 90) {
|
|
159
|
+
value += (c - 65) << shift;
|
|
160
|
+
} else if (c >= 97 && c <= 122) {
|
|
161
|
+
value += (c - 97) << shift;
|
|
162
|
+
} else if (c >= 48 && c <= 57) {
|
|
163
|
+
value += (c - 48 + 26) << shift;
|
|
164
|
+
} else if (c === 43) {
|
|
165
|
+
value += 62 << shift;
|
|
166
|
+
} else if (c === 47) {
|
|
167
|
+
value += 63 << shift;
|
|
168
|
+
} else {
|
|
169
|
+
hasMore = false;
|
|
170
|
+
}
|
|
171
|
+
if (hasMore) {
|
|
172
|
+
shift += 6;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
isNegative = value & 1;
|
|
176
|
+
value = value >> 1;
|
|
177
|
+
if (isNegative) {
|
|
178
|
+
value = -value;
|
|
179
|
+
}
|
|
180
|
+
nameIndex += value;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
onMapping(
|
|
186
|
+
generatedLine,
|
|
187
|
+
generatedColumn,
|
|
188
|
+
sourceIndex,
|
|
189
|
+
originalLine,
|
|
190
|
+
originalColumn,
|
|
191
|
+
nameIndex
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -1,44 +1,310 @@
|
|
|
1
|
-
# Vite React
|
|
1
|
+
# Vite React Transform Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This plugin provides the core transformation functionality for React Server Components (RSC) in Vite. It handles both client and server-side transformations, enabling seamless integration between React Server Components and Vite's build system.
|
|
4
|
+
|
|
5
|
+
## Module Transformation Strategy
|
|
6
|
+
|
|
7
|
+
The plugin uses a sophisticated approach to transform modules while preserving their structure. Each loader (client and server) handles BOTH client and server modules, but in their respective environments:
|
|
8
|
+
|
|
9
|
+
### Environment-Specific Transformations
|
|
10
|
+
|
|
11
|
+
#### Client Environment Loader
|
|
12
|
+
Handles both:
|
|
13
|
+
1. Client Modules ("use client")
|
|
14
|
+
- Registers client components for RSC boundaries
|
|
15
|
+
- Preserves client-side functionality
|
|
16
|
+
|
|
17
|
+
2. Server Modules ("use server")
|
|
18
|
+
- Transforms server actions into client-side references
|
|
19
|
+
- Creates proxies for server function calls
|
|
20
|
+
- Handles server action imports
|
|
21
|
+
|
|
22
|
+
#### Server Environment Loader
|
|
23
|
+
Handles both:
|
|
24
|
+
1. Server Modules ("use server")
|
|
25
|
+
- Registers server actions for RSC boundaries
|
|
26
|
+
- Preserves server-side functionality
|
|
27
|
+
- Handles server action imports
|
|
28
|
+
|
|
29
|
+
2. Client Modules ("use client")
|
|
30
|
+
- Registers client components for RSC boundaries
|
|
31
|
+
- Creates server-side references for client components
|
|
32
|
+
- Ensures proper server-side rendering
|
|
33
|
+
|
|
34
|
+
### AST-Based Transformation
|
|
35
|
+
|
|
36
|
+
Both loaders use Abstract Syntax Trees (AST) to:
|
|
37
|
+
1. Find the first export declaration
|
|
38
|
+
2. Split source code into before/after exports
|
|
39
|
+
3. Insert registration code in the right place
|
|
40
|
+
4. Preserve original exports
|
|
41
|
+
|
|
42
|
+
This ensures:
|
|
43
|
+
- Imports stay at the top
|
|
44
|
+
- Registration code is added in the right place
|
|
45
|
+
- Original exports are preserved
|
|
46
|
+
- No duplicate exports
|
|
47
|
+
|
|
48
|
+
### Example Transformations
|
|
49
|
+
|
|
50
|
+
#### Client Environment
|
|
51
|
+
|
|
52
|
+
Client Module:
|
|
53
|
+
```ts
|
|
54
|
+
// Original
|
|
55
|
+
"use client"
|
|
56
|
+
import { useState } from 'react';
|
|
57
|
+
export function Counter() { ... }
|
|
58
|
+
|
|
59
|
+
// Transformed
|
|
60
|
+
"use client"
|
|
61
|
+
import { useState } from 'react';
|
|
62
|
+
|
|
63
|
+
// Register client components
|
|
64
|
+
if (typeof Counter === "function") {
|
|
65
|
+
const clientReference = registerClientReference(Counter, "url", "Counter", {...});
|
|
66
|
+
Counter = clientReference;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function Counter() { ... }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Server Module:
|
|
73
|
+
```ts
|
|
74
|
+
// Original
|
|
75
|
+
"use server"
|
|
76
|
+
export async function add(a: number, b: number) { ... }
|
|
77
|
+
|
|
78
|
+
// Transformed
|
|
79
|
+
"use server"
|
|
80
|
+
|
|
81
|
+
// Transform server action into client reference
|
|
82
|
+
const add = function(...args) {
|
|
83
|
+
const serverReference = registerServerReference("url#add", add);
|
|
84
|
+
return serverReference.apply(null, args);
|
|
85
|
+
};
|
|
86
|
+
Object.defineProperties(add, {
|
|
87
|
+
$$typeof: { value: Symbol.for("react.server.reference") },
|
|
88
|
+
$$id: { value: "url#add" },
|
|
89
|
+
$$bound: { value: null },
|
|
90
|
+
$$name: { value: "add" }
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export { add };
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Server Environment
|
|
97
|
+
|
|
98
|
+
Server Module:
|
|
99
|
+
```ts
|
|
100
|
+
// Original
|
|
101
|
+
"use server"
|
|
102
|
+
export async function add(a: number, b: number) { ... }
|
|
103
|
+
|
|
104
|
+
// Transformed
|
|
105
|
+
"use server"
|
|
106
|
+
|
|
107
|
+
// Register server actions
|
|
108
|
+
if (typeof add === "function") {
|
|
109
|
+
const serverReference = registerServerReference(add, "url", "add", {...});
|
|
110
|
+
add = serverReference;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function add(a: number, b: number) { ... }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Client Module:
|
|
117
|
+
```ts
|
|
118
|
+
// Original
|
|
119
|
+
"use client"
|
|
120
|
+
import { useState } from 'react';
|
|
121
|
+
export function Counter() { ... }
|
|
122
|
+
|
|
123
|
+
// Transformed
|
|
124
|
+
"use client"
|
|
125
|
+
import { useState } from 'react';
|
|
126
|
+
|
|
127
|
+
// Register client components
|
|
128
|
+
if (typeof Counter === "function") {
|
|
129
|
+
const clientReference = registerClientReference(Counter, "url", "Counter", {...});
|
|
130
|
+
Counter = clientReference;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function Counter() { ... }
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Key Benefits
|
|
137
|
+
|
|
138
|
+
1. **Environment-Aware Transformations**
|
|
139
|
+
- Each loader handles both module types
|
|
140
|
+
- Transformations are environment-specific
|
|
141
|
+
- Proper RSC boundary handling
|
|
142
|
+
|
|
143
|
+
2. **Preserves Module Structure**
|
|
144
|
+
- Maintains original import order
|
|
145
|
+
- Keeps exports in their original location
|
|
146
|
+
- Preserves source maps
|
|
147
|
+
|
|
148
|
+
3. **Handles Complex Cases**
|
|
149
|
+
- Server action imports from .server files
|
|
150
|
+
- Client component registration
|
|
151
|
+
- Proper metadata for RSC boundaries
|
|
152
|
+
- Environment-specific transformations
|
|
153
|
+
|
|
154
|
+
4. **Avoids Common Pitfalls**
|
|
155
|
+
- No duplicate exports
|
|
156
|
+
- No broken source maps
|
|
157
|
+
- No mangled imports
|
|
158
|
+
- Proper environment isolation
|
|
159
|
+
|
|
160
|
+
## Usage
|
|
161
|
+
|
|
162
|
+
When using this plugin, you need to set the `react-server` condition in your Vite configuration:
|
|
4
163
|
|
|
5
164
|
```json
|
|
6
165
|
{
|
|
7
|
-
"scripts":{
|
|
166
|
+
"scripts": {
|
|
8
167
|
"build": "NODE_OPTIONS='--conditions react-server' vite build",
|
|
9
|
-
"dev": "NODE_OPTIONS='--conditions react-server' vite"
|
|
168
|
+
"dev": "NODE_OPTIONS='--conditions react-server' vite"
|
|
10
169
|
}
|
|
11
170
|
}
|
|
12
171
|
```
|
|
13
172
|
|
|
14
|
-
##
|
|
173
|
+
## Architecture
|
|
174
|
+
|
|
175
|
+
### Environment Separation
|
|
15
176
|
|
|
16
|
-
|
|
17
|
-
- The main thread runs with Vite's `react-server` condition
|
|
18
|
-
- HTML rendering must happen in a clean Node environment (worker thread)
|
|
19
|
-
- Worker needs `NODE_OPTIONS=''` to avoid inheriting Vite's conditions
|
|
177
|
+
The plugin maintains a clear separation between different environments and uses dedicated workers for each scenario:
|
|
20
178
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
179
|
+
1. **Client-Side Scenario**
|
|
180
|
+
- Main Thread (Vite)
|
|
181
|
+
- Runs with Vite's default conditions
|
|
182
|
+
- Handles client-side module transformation
|
|
183
|
+
- Manages the client build pipeline
|
|
184
|
+
- HTML Worker Thread
|
|
185
|
+
- Runs in a clean Node environment
|
|
186
|
+
- Handles HTML rendering
|
|
187
|
+
- Uses `react-dom/server` for server-side rendering
|
|
188
|
+
- Uses `react-server-dom-esm/client.node` for client-side RSC
|
|
189
|
+
- Processes static HTML generation
|
|
190
|
+
|
|
191
|
+
2. **Server-Side Scenario**
|
|
192
|
+
- Main Thread (Vite)
|
|
193
|
+
- Runs with `react-server` condition
|
|
194
|
+
- Handles server-side module transformation
|
|
195
|
+
- Manages the server build pipeline
|
|
196
|
+
- RSC Worker Thread
|
|
197
|
+
- Runs in a clean Node environment
|
|
198
|
+
- Handles RSC streaming
|
|
199
|
+
- Uses `react-server-dom-esm/server.node`
|
|
200
|
+
- Processes server component requests
|
|
201
|
+
|
|
202
|
+
3. **Browser Environment**
|
|
203
|
+
- Client-side React components
|
|
204
|
+
- Uses `react-dom/client`
|
|
205
|
+
- Handles hydration and client-side updates
|
|
206
|
+
|
|
207
|
+
### RSC Stream Flow
|
|
208
|
+
|
|
209
|
+
#### Client-Side Flow
|
|
210
|
+
```
|
|
211
|
+
Main Thread (Vite) HTML Worker Thread (Clean Node) Browser
|
|
212
|
+
--------------- --------------------- ---------------------
|
|
213
|
+
Client Modules → HTML Rendering React Client
|
|
214
|
+
(react-dom/server) (react-dom/client)
|
|
215
|
+
(react-server-dom-esm/client.node) (react-server-dom-esm/client.browser)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Server-Side Flow
|
|
219
|
+
```
|
|
220
|
+
Main Thread (Vite) RSC Worker Thread (Clean Node) Static Output
|
|
221
|
+
--------------- --------------------- ---------------------
|
|
222
|
+
Server Modules → RSC Streaming Static Files
|
|
223
|
+
(react-server) → (react-server-dom-esm/server.node) (HTML + RSC)
|
|
224
|
+
```
|
|
29
225
|
|
|
30
|
-
|
|
31
|
-
- Skip Vite's internal requests (`/@vite/client`, etc.)
|
|
32
|
-
- Handle HTML and directory requests
|
|
33
|
-
- Pass through static files
|
|
226
|
+
## Key Features
|
|
34
227
|
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
228
|
+
1. **Module Transformation**
|
|
229
|
+
- Transforms "use client" and "use server" directives
|
|
230
|
+
- Handles client/server component boundaries
|
|
231
|
+
- Manages module resolution and imports
|
|
39
232
|
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
233
|
+
2. **Request Handling**
|
|
234
|
+
- Processes HTML and directory requests
|
|
235
|
+
- Skips Vite's internal requests
|
|
236
|
+
- Handles static file serving
|
|
237
|
+
|
|
238
|
+
3. **Module Resolution**
|
|
239
|
+
- Maintains proper import maps for client components
|
|
240
|
+
- Resolves dependencies using Vite's module system
|
|
241
|
+
- Handles bootstrap module resolution
|
|
242
|
+
|
|
243
|
+
## Common Pitfalls
|
|
244
|
+
|
|
245
|
+
1. **Environment Conflicts**
|
|
246
|
+
- Don't use `react-dom/server.node` in the main thread
|
|
247
|
+
- Avoid mixing React server/client conditions
|
|
248
|
+
- Keep worker thread environments clean
|
|
249
|
+
- Ensure proper worker thread isolation
|
|
250
|
+
|
|
251
|
+
2. **Stream Handling**
|
|
43
252
|
- Be careful with stream handling between threads
|
|
44
|
-
-
|
|
253
|
+
- Ensure proper error handling in streams
|
|
254
|
+
- Monitor stream backpressure
|
|
255
|
+
- Handle worker thread communication properly
|
|
256
|
+
|
|
257
|
+
3. **Module Resolution**
|
|
258
|
+
- Watch for proper module resolution in both environments
|
|
259
|
+
- Ensure consistent module IDs across client/server
|
|
260
|
+
- Handle path normalization correctly
|
|
261
|
+
- Maintain proper module boundaries between workers
|
|
262
|
+
|
|
263
|
+
## Best Practices
|
|
264
|
+
|
|
265
|
+
1. **Development**
|
|
266
|
+
- Use the `react-server` condition for development
|
|
267
|
+
- Monitor stream metrics for performance
|
|
268
|
+
- Use proper error boundaries
|
|
269
|
+
- Test both client and server scenarios
|
|
270
|
+
|
|
271
|
+
2. **Production**
|
|
272
|
+
- Ensure proper build order (client → server → static)
|
|
273
|
+
- Monitor bundle sizes
|
|
274
|
+
- Test RSC boundaries thoroughly
|
|
275
|
+
- Verify worker thread performance
|
|
276
|
+
|
|
277
|
+
3. **Debugging**
|
|
278
|
+
- Use source maps for debugging
|
|
279
|
+
- Monitor stream metrics
|
|
280
|
+
- Check module resolution paths
|
|
281
|
+
- Debug worker thread issues separately
|
|
282
|
+
|
|
283
|
+
## Configuration
|
|
284
|
+
|
|
285
|
+
The plugin can be configured through Vite's plugin system:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { defineConfig } from 'vite';
|
|
289
|
+
import { reactTransformPlugin } from './plugin/transformer';
|
|
290
|
+
|
|
291
|
+
export default defineConfig({
|
|
292
|
+
plugins: [
|
|
293
|
+
reactTransformPlugin({
|
|
294
|
+
// Plugin options
|
|
295
|
+
})
|
|
296
|
+
]
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Contributing
|
|
301
|
+
|
|
302
|
+
When contributing to this plugin:
|
|
303
|
+
|
|
304
|
+
1. Maintain environment separation
|
|
305
|
+
2. Follow the established stream flow
|
|
306
|
+
3. Test in all environments
|
|
307
|
+
4. Update documentation for changes
|
|
308
|
+
5. Consider performance implications
|
|
309
|
+
6. Test both worker scenarios
|
|
310
|
+
7. Ensure proper worker thread isolation
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
|
-
import type { ResolvedUserOptions, StreamPluginOptions } from "../types.js";
|
|
3
|
-
import { type Manifest, type Plugin } from "vite";
|
|
4
|
-
import { transformModuleIfNeeded } from "../loader/react-loader.js";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { tryManifest } from "../helpers/tryManifest.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Plugin for transforming server actions for the client build.
|
|
10
|
-
*
|
|
11
|
-
* Core responsibilities:
|
|
12
|
-
* 1. Transforms "use server" directives
|
|
13
|
-
* 2. Transforms server actions for the client build
|
|
14
|
-
* 3. Uses react-loader's transformModuleIfNeeded to create a server action reference
|
|
15
|
-
*
|
|
16
|
-
* When a component is marked with "use server", it:
|
|
17
|
-
* - Gets transformed into a server action
|
|
18
|
-
* - Maintains module ID for RSC boundaries
|
|
19
|
-
* - Preserves class/function behavior
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* export default defineConfig({
|
|
24
|
-
* plugins: [
|
|
25
|
-
* viteReactClientTransformPlugin({
|
|
26
|
-
* projectRoot: process.cwd(),
|
|
27
|
-
* })
|
|
28
|
-
* ]
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
let isBuild = true;
|
|
33
|
-
|
|
34
|
-
export function reactTransformPlugin(options: StreamPluginOptions): Plugin {
|
|
35
|
-
let userOptions: ResolvedUserOptions;
|
|
36
|
-
const resolvedOptionsResult = resolveOptions(options);
|
|
37
|
-
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
38
|
-
userOptions = resolvedOptionsResult.userOptions;
|
|
39
|
-
let staticManifest: Manifest;
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
name: "vite:react-server-action-transform",
|
|
43
|
-
enforce: "pre",
|
|
44
|
-
async config(_, configEnv) {
|
|
45
|
-
isBuild = configEnv.command !== "serve";
|
|
46
|
-
if (!configEnv.isSsrBuild) {
|
|
47
|
-
staticManifest = {};
|
|
48
|
-
} else {
|
|
49
|
-
const staticManifestResult = await tryManifest({
|
|
50
|
-
root: userOptions.projectRoot,
|
|
51
|
-
ssrManifest: false,
|
|
52
|
-
outDir: join(userOptions.build.outDir, userOptions.build.static),
|
|
53
|
-
});
|
|
54
|
-
if (staticManifestResult.type === "error") {
|
|
55
|
-
staticManifest = {};
|
|
56
|
-
} else {
|
|
57
|
-
staticManifest = staticManifestResult.manifest;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
async transform(code, id, options) {
|
|
62
|
-
const ssr = options?.ssr;
|
|
63
|
-
const isServer = code.match('"use server"') !== null;
|
|
64
|
-
const isClient = code.match('"use client"') !== null;
|
|
65
|
-
if (!ssr) return null;
|
|
66
|
-
if (!isServer && !isClient) return null;
|
|
67
|
-
if (isServer && isClient) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
"Server and client components cannot be used in the same file"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (isClient) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
const [key, value] = userOptions.normalizer(id);
|
|
76
|
-
if (isServer && isBuild) {
|
|
77
|
-
id = key + ".js";
|
|
78
|
-
}
|
|
79
|
-
const finalID = userOptions.moduleID(value);
|
|
80
|
-
const transformed = await transformModuleIfNeeded(code, finalID, null);
|
|
81
|
-
if (!transformed) return null;
|
|
82
|
-
return {
|
|
83
|
-
code: transformed,
|
|
84
|
-
id: finalID,
|
|
85
|
-
map: null,
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
renderChunk(code, chunk, _options) {
|
|
89
|
-
// Only process client components
|
|
90
|
-
if (!chunk.fileName.includes(".client")) return null;
|
|
91
|
-
|
|
92
|
-
// Get the original file name without extension
|
|
93
|
-
const originalName = chunk.fileName.replace(userOptions.autoDiscover.moduleExtension, "");
|
|
94
|
-
|
|
95
|
-
// Find matching entry in static manifest
|
|
96
|
-
const manifestEntry = Object.entries(staticManifest).find(([_, info]) =>
|
|
97
|
-
info.file.startsWith(originalName)
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
if (manifestEntry) {
|
|
101
|
-
// Use the static manifest's file name
|
|
102
|
-
return {
|
|
103
|
-
code,
|
|
104
|
-
fileName: manifestEntry[1].file,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return null;
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|