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,118 @@
|
|
|
1
|
+
import type { SourceMap } from "../types/sourceMap.js";
|
|
2
|
+
import createMappingsSerializer from 'webpack-sources/lib/helpers/createMappingsSerializer.js';
|
|
3
|
+
import { basename } from "path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a basic source map for a module
|
|
7
|
+
*/
|
|
8
|
+
export function createBasicSourceMap(url: string, source: string): SourceMap {
|
|
9
|
+
const createMapping = createMappingsSerializer();
|
|
10
|
+
let mappings = '';
|
|
11
|
+
let lineCount = 1;
|
|
12
|
+
let idx = -1;
|
|
13
|
+
|
|
14
|
+
// Map each line with VLQ encoding
|
|
15
|
+
while ((idx = source.indexOf('\n', idx + 1)) !== -1) {
|
|
16
|
+
createMapping(lineCount, 0, 0, lineCount, 0, -1);
|
|
17
|
+
lineCount++;
|
|
18
|
+
}
|
|
19
|
+
// Add final line
|
|
20
|
+
createMapping(lineCount, 0, 0, lineCount, 0, -1);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
version: 3,
|
|
24
|
+
file: basename(url),
|
|
25
|
+
sources: [url],
|
|
26
|
+
sourcesContent: [source],
|
|
27
|
+
mappings,
|
|
28
|
+
sourceRoot: '',
|
|
29
|
+
names: []
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Extends an existing source map with new lines
|
|
35
|
+
*/
|
|
36
|
+
export function extendSourceMap(sourceMap: SourceMap, newLines: number, originalSource: string): SourceMap {
|
|
37
|
+
const createMapping = createMappingsSerializer();
|
|
38
|
+
let mappings = sourceMap.mappings || '';
|
|
39
|
+
let lineCount = originalSource.split('\n').length;
|
|
40
|
+
|
|
41
|
+
// Add padding for new lines
|
|
42
|
+
for (let i = 0; i < newLines; i++) {
|
|
43
|
+
createMapping(lineCount + i, 0, 0, lineCount + i, 0, -1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
...sourceMap,
|
|
48
|
+
version: 3,
|
|
49
|
+
sourcesContent: [originalSource],
|
|
50
|
+
mappings
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Adds a source map as a base64 data URL to the source code
|
|
56
|
+
*/
|
|
57
|
+
export function addSourceMapToSource(source: string, sourceMap: SourceMap): string {
|
|
58
|
+
// Convert version to number for serialization
|
|
59
|
+
const serializedMap = {
|
|
60
|
+
...sourceMap,
|
|
61
|
+
version: Number(sourceMap.version)
|
|
62
|
+
};
|
|
63
|
+
return source + '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
|
|
64
|
+
Buffer.from(JSON.stringify(serializedMap)).toString('base64');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Detects and extracts source map URL from source code
|
|
69
|
+
*/
|
|
70
|
+
export function detectSourceMapURL(source: string): { url: string | null; start: number; end: number; lines: number } {
|
|
71
|
+
let sourceMappingURL: string | null = null;
|
|
72
|
+
let sourceMappingStart = 0;
|
|
73
|
+
let sourceMappingEnd = 0;
|
|
74
|
+
let sourceMappingLines = 0;
|
|
75
|
+
|
|
76
|
+
const lines = source.split('\n');
|
|
77
|
+
for (let i = 0; i < lines.length; i++) {
|
|
78
|
+
const line = lines[i];
|
|
79
|
+
if (line.includes('# sourceMappingURL=') || line.includes('@ sourceMappingURL=')) {
|
|
80
|
+
const match = line.match(/(?:#|@) sourceMappingURL=(.+)/);
|
|
81
|
+
if (match) {
|
|
82
|
+
sourceMappingURL = match[1];
|
|
83
|
+
sourceMappingStart = source.indexOf(line);
|
|
84
|
+
sourceMappingEnd = sourceMappingStart + line.length;
|
|
85
|
+
sourceMappingLines = 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { url: sourceMappingURL, start: sourceMappingStart, end: sourceMappingEnd, lines: sourceMappingLines };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Strips source map URL comment from source code
|
|
95
|
+
*/
|
|
96
|
+
export function stripSourceMapURL(source: string, sourceMapInfo: { start: number; end: number; lines: number }): string {
|
|
97
|
+
if (sourceMapInfo.start === 0 && sourceMapInfo.end === 0) {
|
|
98
|
+
return source;
|
|
99
|
+
}
|
|
100
|
+
return source.slice(0, sourceMapInfo.start) +
|
|
101
|
+
'\n'.repeat(sourceMapInfo.lines) +
|
|
102
|
+
source.slice(sourceMapInfo.end);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Creates a source map with the given parameters
|
|
107
|
+
*/
|
|
108
|
+
export function createSourceMap(id: string, code: string, mappings: string): SourceMap {
|
|
109
|
+
return {
|
|
110
|
+
version: 3,
|
|
111
|
+
file: basename(id),
|
|
112
|
+
sources: [id],
|
|
113
|
+
sourcesContent: [code],
|
|
114
|
+
names: [],
|
|
115
|
+
mappings,
|
|
116
|
+
sourceRoot: "",
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getCondition } from "../config/getCondition.js";
|
|
2
|
+
import { transformModuleWithPreservedFunctions } from "./transformModuleWithPreservedFunctions.js";
|
|
3
|
+
import { parse } from "./parse.js";
|
|
4
|
+
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
5
|
+
|
|
6
|
+
export function transformModuleIfNeeded(
|
|
7
|
+
source: string,
|
|
8
|
+
moduleId: string,
|
|
9
|
+
isServerFunction: boolean | RegExpMatchArray | null = DEFAULT_CONFIG.AUTO_DISCOVER.isServerFunction(source),
|
|
10
|
+
isClientComponent: boolean | RegExpMatchArray | null = DEFAULT_CONFIG.AUTO_DISCOVER.isClientComponent(source),
|
|
11
|
+
isServerEnvironment = getCondition() === "react-server"
|
|
12
|
+
) {
|
|
13
|
+
// Parse source and handle source maps
|
|
14
|
+
const ast = parse(source);
|
|
15
|
+
|
|
16
|
+
// Handle environment-specific cases
|
|
17
|
+
if (
|
|
18
|
+
(isServerEnvironment && !isServerFunction && !isClientComponent) ||
|
|
19
|
+
(!isServerEnvironment && isClientComponent)
|
|
20
|
+
) {
|
|
21
|
+
return source
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result = transformModuleWithPreservedFunctions(
|
|
25
|
+
source,
|
|
26
|
+
moduleId,
|
|
27
|
+
ast,
|
|
28
|
+
isServerFunction,
|
|
29
|
+
isClientComponent
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # RSC Boundary Handling
|
|
3
|
+
*
|
|
4
|
+
* This file provides the core transformation logic for React Server Components (RSC) boundaries.
|
|
5
|
+
*
|
|
6
|
+
* - **Server Loader**: Always strips implementation for client modules, exports error-throwing references.
|
|
7
|
+
* - **Client Loader**: Always strips implementation for server modules, exports error-throwing references.
|
|
8
|
+
* - **Browser**: Only client modules are passed through as-is.
|
|
9
|
+
*
|
|
10
|
+
* All transformations are handled by `transformModuleWithPreservedFunctions` for consistency.
|
|
11
|
+
*
|
|
12
|
+
* ## Error Behavior
|
|
13
|
+
*
|
|
14
|
+
* - If a client component is imported on the server, the export is a function that throws a clear error.
|
|
15
|
+
* - If a server action is imported on the client, the export is a function that throws a clear error.
|
|
16
|
+
*
|
|
17
|
+
* This ensures that implementation details are never leaked across boundaries and errors are easy to debug.
|
|
18
|
+
*/
|
|
19
|
+
import { handleExports } from "./handleExports.js";
|
|
20
|
+
import type { Program } from "./types.js";
|
|
21
|
+
|
|
22
|
+
export interface TransformOptions {
|
|
23
|
+
id: string;
|
|
24
|
+
exportNames: string[];
|
|
25
|
+
beforeExports: string;
|
|
26
|
+
afterExports: string;
|
|
27
|
+
isServerModule?: boolean;
|
|
28
|
+
isClientModule?: boolean;
|
|
29
|
+
program?: Program;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates a client reference error message
|
|
34
|
+
*/
|
|
35
|
+
function createClientReferenceError(name: string): string {
|
|
36
|
+
return `Attempted to call ${name}() from the server but ${name} is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Transforms a module for RSC boundaries.
|
|
41
|
+
* - Server modules: exports are wrapped with server references while preserving functionality.
|
|
42
|
+
* - Client modules: exports are replaced with client references or errors, depending on environment.
|
|
43
|
+
* - Only the correct references are exported; implementation is never leaked across boundaries.
|
|
44
|
+
*
|
|
45
|
+
* @param source - The original module source code.
|
|
46
|
+
* @param moduleId - The module's unique identifier.
|
|
47
|
+
* @param url - The module's URL.
|
|
48
|
+
* @param program - The parsed AST.
|
|
49
|
+
* @param map - The source map for the source code.
|
|
50
|
+
* @param isServerFunction - Whether the module is a server function.
|
|
51
|
+
* @param isClientComponent - Whether the module is a client component.
|
|
52
|
+
* @returns The transformed source code.
|
|
53
|
+
*/
|
|
54
|
+
export function transformModuleWithPreservedFunctions(
|
|
55
|
+
source: string,
|
|
56
|
+
moduleId: string,
|
|
57
|
+
program: Program,
|
|
58
|
+
isServerFunction: boolean | RegExpMatchArray | null,
|
|
59
|
+
isClientComponent: boolean | RegExpMatchArray | null,
|
|
60
|
+
): string {
|
|
61
|
+
|
|
62
|
+
// Get export names and create module ID literal
|
|
63
|
+
const { exportNames, exports } = handleExports(source, program, isServerFunction, isClientComponent);
|
|
64
|
+
const moduleIdLiteral = JSON.stringify(moduleId);
|
|
65
|
+
|
|
66
|
+
// For server modules in server environment, register server references
|
|
67
|
+
if (isServerFunction) {
|
|
68
|
+
const imports = ['import { registerServerReference } from "react-server-dom-esm/server.node";'];
|
|
69
|
+
const registrations: string[] = [];
|
|
70
|
+
|
|
71
|
+
// Register each export
|
|
72
|
+
for (const name of exportNames) {
|
|
73
|
+
const exportInfo = exports.get(name);
|
|
74
|
+
if (exportInfo) {
|
|
75
|
+
// For default exports, use the localName if available
|
|
76
|
+
const exportName = name === "default" && exportInfo.localName ? exportInfo.localName : name;
|
|
77
|
+
// Register all exports in server modules
|
|
78
|
+
registrations.push(
|
|
79
|
+
`registerServerReference(${exportName}, ${moduleIdLiteral}, ${JSON.stringify(name)});`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Create new source with registrations
|
|
85
|
+
// First, add the imports at the top
|
|
86
|
+
const newSource = [...imports, source].join("\n\n");
|
|
87
|
+
// Then, add the registrations at the end
|
|
88
|
+
const finalSource = newSource + "\n\n" + registrations.join("\n");
|
|
89
|
+
|
|
90
|
+
return finalSource;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// For client modules in server environment, register client references
|
|
94
|
+
if (isClientComponent) {
|
|
95
|
+
const imports = ['import { registerClientReference } from "react-server-dom-esm/server.node";'];
|
|
96
|
+
const declarations: string[] = [];
|
|
97
|
+
|
|
98
|
+
for (const name of exportNames) {
|
|
99
|
+
const errorMessage = createClientReferenceError(name);
|
|
100
|
+
if (name === "default") {
|
|
101
|
+
declarations.push(`export default registerClientReference(function() {
|
|
102
|
+
throw new Error("${errorMessage}");
|
|
103
|
+
}, ${moduleIdLiteral}, "default");`);
|
|
104
|
+
} else {
|
|
105
|
+
declarations.push(`export const ${name} = registerClientReference(function() {
|
|
106
|
+
throw new Error("${errorMessage}");
|
|
107
|
+
}, ${moduleIdLiteral}, ${JSON.stringify(name)});`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Create new source with declarations
|
|
112
|
+
const newSource = [...imports, ...declarations].join("\n\n");
|
|
113
|
+
|
|
114
|
+
return newSource;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// For other cases, return original source
|
|
118
|
+
return source;
|
|
119
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Program as AcornProgram, Statement } from "acorn";
|
|
2
|
+
|
|
3
|
+
// Directive is a special type in Acorn that extends ExpressionStatement
|
|
4
|
+
export type Directive = Statement & {
|
|
5
|
+
directive: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export interface Program extends AcornProgram {
|
|
9
|
+
exports?: string[];
|
|
10
|
+
}
|
package/plugin/plugin.client.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
2
|
+
import type {
|
|
3
|
+
StreamPluginOptions,
|
|
4
|
+
InlineCssOpt,
|
|
5
|
+
PagePropOpt,
|
|
6
|
+
} from "../types.js";
|
|
4
7
|
import { reactClientPlugin } from "./react-client/plugin.js";
|
|
5
8
|
import { envPlugin } from "./env/plugin.js";
|
|
9
|
+
//import { reactTransformPlugin } from "./transformer/plugin.client.js";
|
|
6
10
|
|
|
7
|
-
export function vitePluginReactServer
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
export function vitePluginReactServer<
|
|
12
|
+
T extends PagePropOpt = PagePropOpt,
|
|
13
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
14
|
+
>(options = {} as StreamPluginOptions<T, InlineCSS>): import("vite").Plugin[] {
|
|
15
|
+
return [
|
|
16
|
+
envPlugin(),
|
|
17
|
+
//reactTransformPlugin(options),
|
|
18
|
+
reactClientPlugin(options),
|
|
19
|
+
reactPreservePlugin(options),
|
|
20
|
+
];
|
|
21
|
+
}
|
package/plugin/plugin.server.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
2
2
|
import { reactStaticPlugin } from "./react-static/plugin.js";
|
|
3
3
|
import { reactTransformPlugin } from "./transformer/plugin.server.js";
|
|
4
|
-
import type { StreamPluginOptions } from "./types.js";
|
|
4
|
+
import type { StreamPluginOptions, PagePropOpt, InlineCssOpt } from "./types.js";
|
|
5
5
|
import { reactServerPlugin } from "./react-server/plugin.js";
|
|
6
6
|
import { envPlugin } from "./env/plugin.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
export function vitePluginReactServer
|
|
10
|
-
|
|
9
|
+
export function vitePluginReactServer<
|
|
10
|
+
T extends PagePropOpt = PagePropOpt,
|
|
11
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
12
|
+
>(
|
|
13
|
+
options = {} as StreamPluginOptions<T, InlineCSS>
|
|
11
14
|
): import("vite").Plugin[] {
|
|
12
15
|
if(!options.build?.pages || (Array.isArray(options.build.pages) && options.build.pages.length === 0)) {
|
|
13
16
|
// in this case we do not need the static plugin at all
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Node } from "estree";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
InlineCssOpt,
|
|
4
|
+
PagePropOpt,
|
|
5
|
+
StreamPluginOptions,
|
|
6
|
+
} from "../types.js";
|
|
3
7
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
4
8
|
import { basename } from "path";
|
|
9
|
+
import { resolveAutoDiscoverMatcher } from "../config/resolveAutoDiscoverMatcher.js";
|
|
5
10
|
|
|
6
11
|
const REACT_DIRECTIVES = new Set(["use client", "use server"]);
|
|
7
12
|
|
|
@@ -17,10 +22,13 @@ function createSourceMap(id: string, code: string, mappings: string) {
|
|
|
17
22
|
};
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
function removeRanges(
|
|
25
|
+
function removeRanges(
|
|
26
|
+
code: string,
|
|
27
|
+
ranges: Array<{ start: number; end: number }>
|
|
28
|
+
) {
|
|
21
29
|
// Sort ranges in reverse order to not affect positions
|
|
22
30
|
ranges.sort((a, b) => b.start - a.start);
|
|
23
|
-
|
|
31
|
+
|
|
24
32
|
let result = code;
|
|
25
33
|
for (const range of ranges) {
|
|
26
34
|
result = result.slice(0, range.start) + result.slice(range.end);
|
|
@@ -31,14 +39,20 @@ function removeRanges(code: string, ranges: Array<{ start: number; end: number }
|
|
|
31
39
|
function countLines(str: string): number {
|
|
32
40
|
let count = 1;
|
|
33
41
|
for (let i = 0; i < str.length; i++) {
|
|
34
|
-
if (str[i] ===
|
|
42
|
+
if (str[i] === "\n") count++;
|
|
35
43
|
}
|
|
36
44
|
return count;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
export function reactPreservePlugin
|
|
47
|
+
export function reactPreservePlugin<
|
|
48
|
+
T extends PagePropOpt = PagePropOpt,
|
|
49
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
50
|
+
>(options: StreamPluginOptions<T, InlineCSS>): import("vite").Plugin {
|
|
40
51
|
const meta: Record<string, Set<string>> = {};
|
|
41
|
-
|
|
52
|
+
// saves us from transforming all the options
|
|
53
|
+
const moduleExtension = resolveAutoDiscoverMatcher(options.autoDiscover?.moduleExtension, DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension);
|
|
54
|
+
const vendorPattern = resolveAutoDiscoverMatcher(options.autoDiscover?.vendorPattern, DEFAULT_CONFIG.AUTO_DISCOVER.vendorPattern);
|
|
55
|
+
const virtualPattern = resolveAutoDiscoverMatcher(options.autoDiscover?.virtualPattern, DEFAULT_CONFIG.AUTO_DISCOVER.virtualPattern);
|
|
42
56
|
return {
|
|
43
57
|
name: "vite-plugin-react-server:preserve-directives",
|
|
44
58
|
enforce: "post",
|
|
@@ -47,7 +61,11 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
|
|
|
47
61
|
order: "post", // Ensure this runs last in transform phase
|
|
48
62
|
handler(code: string, id: string) {
|
|
49
63
|
// Skip node_modules and vite files
|
|
50
|
-
if (
|
|
64
|
+
if (
|
|
65
|
+
vendorPattern(id) ||
|
|
66
|
+
virtualPattern(id) ||
|
|
67
|
+
!moduleExtension(id)
|
|
68
|
+
) {
|
|
51
69
|
return null;
|
|
52
70
|
}
|
|
53
71
|
|
|
@@ -91,14 +109,16 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
|
|
|
91
109
|
if (directive && "start" in node && "end" in node) {
|
|
92
110
|
meta[id] ||= new Set<string>();
|
|
93
111
|
meta[id].add(directive);
|
|
94
|
-
rangesToRemove.push({
|
|
95
|
-
start: node.start as number,
|
|
96
|
-
end: node.end as number
|
|
112
|
+
rangesToRemove.push({
|
|
113
|
+
start: node.start as number,
|
|
114
|
+
end: node.end as number,
|
|
97
115
|
});
|
|
98
116
|
hasChanged = true;
|
|
99
|
-
|
|
117
|
+
|
|
100
118
|
// Add mapping for each line removed
|
|
101
|
-
const removedLines =
|
|
119
|
+
const removedLines =
|
|
120
|
+
code.slice(node.start as number, node.end as number).split("\n")
|
|
121
|
+
.length - 1;
|
|
102
122
|
for (let i = 0; i < removedLines; i++) {
|
|
103
123
|
mappings += ";AACA";
|
|
104
124
|
lineCount++;
|
|
@@ -134,10 +154,11 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
|
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
if (chunkDirectives.size) {
|
|
137
|
-
const directivesCode =
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
const directivesCode =
|
|
158
|
+
Array.from(chunkDirectives)
|
|
159
|
+
.map((d) => `"${d}";`)
|
|
160
|
+
.join("\n") + "\n";
|
|
161
|
+
|
|
141
162
|
const newCode = directivesCode + code;
|
|
142
163
|
|
|
143
164
|
// Create source map for the prepended directives
|
|
@@ -155,4 +176,3 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
|
|
|
155
176
|
},
|
|
156
177
|
};
|
|
157
178
|
}
|
|
158
|
-
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ViteDevServer } from "vite";
|
|
2
2
|
import type {
|
|
3
3
|
AutoDiscoveredFiles,
|
|
4
|
+
InlineCssOpt,
|
|
5
|
+
PagePropOpt,
|
|
4
6
|
RenderMetrics,
|
|
5
7
|
RequestHandler,
|
|
6
8
|
ResolvedUserOptions,
|
|
@@ -15,7 +17,7 @@ import { handleWorkerRscStream } from "./handleWorkerRscStream.js";
|
|
|
15
17
|
import { getRouteFiles } from "../helpers/getRouteFiles.js";
|
|
16
18
|
import type { RscWorkerInputMessage } from "../worker/types.js";
|
|
17
19
|
import { Readable } from "node:stream";
|
|
18
|
-
import { ReadableStream } from "node:stream/web";
|
|
20
|
+
import type { ReadableStream } from "node:stream/web";
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* Configures the worker request handler.
|
|
@@ -23,7 +25,10 @@ import { ReadableStream } from "node:stream/web";
|
|
|
23
25
|
* @param autoDiscoveredFiles - The auto discovered files
|
|
24
26
|
* @param userOptions - The user options
|
|
25
27
|
*/
|
|
26
|
-
export async function configureWorkerRequestHandler
|
|
28
|
+
export async function configureWorkerRequestHandler<
|
|
29
|
+
T extends PagePropOpt = PagePropOpt,
|
|
30
|
+
InlineCSS extends InlineCssOpt = InlineCssOpt
|
|
31
|
+
>({
|
|
27
32
|
server,
|
|
28
33
|
autoDiscoveredFiles,
|
|
29
34
|
userOptions: _userOptions,
|
|
@@ -32,7 +37,7 @@ export async function configureWorkerRequestHandler({
|
|
|
32
37
|
}: {
|
|
33
38
|
server: ViteDevServer;
|
|
34
39
|
autoDiscoveredFiles: AutoDiscoveredFiles;
|
|
35
|
-
userOptions: ResolvedUserOptions
|
|
40
|
+
userOptions: ResolvedUserOptions<T, InlineCSS>;
|
|
36
41
|
hmrChannel: MessageChannel;
|
|
37
42
|
onMetrics?: (metrics: RenderMetrics) => void;
|
|
38
43
|
}) {
|
|
@@ -77,12 +82,12 @@ export async function configureWorkerRequestHandler({
|
|
|
77
82
|
// Create the request handler
|
|
78
83
|
const handler: RequestHandler = async (req, res, next) => {
|
|
79
84
|
if (!req.url) return next();
|
|
80
|
-
if (handlerOptions.verbose) logger.info(`Received request: ${req.url}`);
|
|
81
85
|
|
|
82
|
-
const info = requestInfo(req, handlerOptions, "");
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
+
const info = requestInfo(req, handlerOptions, "", server.config.logger);
|
|
87
|
+
|
|
88
|
+
if (!info.isRscRequest) {
|
|
89
|
+
return next();
|
|
90
|
+
}
|
|
86
91
|
|
|
87
92
|
const routeFiles = await getRouteFiles(
|
|
88
93
|
info.route,
|
|
@@ -101,7 +106,7 @@ export async function configureWorkerRequestHandler({
|
|
|
101
106
|
res.setHeader("Transfer-Encoding", "chunked");
|
|
102
107
|
res.setHeader("Connection", "keep-alive");
|
|
103
108
|
|
|
104
|
-
const serializedUserOptions = serializedOptions(
|
|
109
|
+
const serializedUserOptions = serializedOptions<T, InlineCSS>(
|
|
105
110
|
handlerOptions,
|
|
106
111
|
autoDiscoveredFiles
|
|
107
112
|
);
|
|
@@ -140,6 +145,8 @@ export async function configureWorkerRequestHandler({
|
|
|
140
145
|
worker: currentWorker!,
|
|
141
146
|
message: {
|
|
142
147
|
...serializedUserOptions,
|
|
148
|
+
id: info.route,
|
|
149
|
+
type: "RSC_RENDER",
|
|
143
150
|
// we make the worker stream aware of the route, pagePath, propsPath
|
|
144
151
|
route: info.route,
|
|
145
152
|
pagePath: pagePath,
|
|
@@ -153,14 +160,17 @@ export async function configureWorkerRequestHandler({
|
|
|
153
160
|
},
|
|
154
161
|
logger,
|
|
155
162
|
handlers: {
|
|
156
|
-
onMetrics:
|
|
163
|
+
onMetrics: (id, metrics) => {
|
|
164
|
+
metrics.route = id;
|
|
165
|
+
userOnMetrics(metrics);
|
|
166
|
+
},
|
|
157
167
|
onHmrAccept: () => {
|
|
158
168
|
// TODO: implement
|
|
159
|
-
|
|
169
|
+
// console.log("onHmrAccept", routes);
|
|
160
170
|
},
|
|
161
171
|
onHmrUpdate: () => {
|
|
162
172
|
// TODO: implement
|
|
163
|
-
|
|
173
|
+
// console.log("onHmrUpdate", routes);
|
|
164
174
|
},
|
|
165
175
|
},
|
|
166
176
|
verbose: handlerOptions.verbose,
|
|
@@ -11,39 +11,47 @@ type MessageHandlerContext = {
|
|
|
11
11
|
export function createMessageHandler({
|
|
12
12
|
handlers,
|
|
13
13
|
logger,
|
|
14
|
-
verbose = false
|
|
14
|
+
verbose = false,
|
|
15
15
|
}: MessageHandlerContext) {
|
|
16
16
|
return (message: RscWorkerOutputMessage | undefined) => {
|
|
17
17
|
if (!message) {
|
|
18
|
-
logger.warn("
|
|
18
|
+
logger.warn("Received undefined message");
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
switch (message.type) {
|
|
23
23
|
case "READY":
|
|
24
24
|
if(verbose) logger.info("[react-client] Worker is ready");
|
|
25
25
|
break;
|
|
26
|
+
case "ERROR":
|
|
27
|
+
handlers.onError(message.id, message.error, message.errorInfo);
|
|
28
|
+
break;
|
|
26
29
|
case "RSC_CHUNK":
|
|
27
|
-
handlers.onData(message.chunk);
|
|
30
|
+
handlers.onData(message.id, message.chunk);
|
|
28
31
|
break;
|
|
29
32
|
case "RSC_END":
|
|
30
|
-
handlers.onEnd();
|
|
31
|
-
break;
|
|
32
|
-
case "ERROR":
|
|
33
|
-
handlers.onError(message.error, message.errorInfo);
|
|
33
|
+
handlers.onEnd(message.id);
|
|
34
34
|
break;
|
|
35
35
|
case "RSC_METRICS":
|
|
36
|
-
handlers.onMetrics(message.metrics);
|
|
36
|
+
handlers.onMetrics(message.id, message.metrics);
|
|
37
37
|
break;
|
|
38
38
|
case "HMR_ACCEPT":
|
|
39
|
-
handlers.onHmrAccept(message.routes
|
|
39
|
+
handlers.onHmrAccept(message.id, message.routes);
|
|
40
40
|
break;
|
|
41
41
|
case "HMR_UPDATE":
|
|
42
|
-
handlers.onHmrUpdate(message.routes
|
|
42
|
+
handlers.onHmrUpdate(message.id, message.routes);
|
|
43
43
|
break;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
case "SERVER_ACTION":
|
|
45
|
+
handlers.onServerAction?.(message.id, message.args);
|
|
46
|
+
break;
|
|
47
|
+
case "SERVER_ACTION_RESPONSE":
|
|
48
|
+
handlers.onServerActionResponse?.(message.id, message.result, message.error);
|
|
46
49
|
break;
|
|
50
|
+
case "SERVER_MODULE":
|
|
51
|
+
handlers.onServerModule?.(message.id, message.url, message.source);
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
logger.warn(`Unknown worker output message type: ${(message as { type: string }).type}`);
|
|
47
55
|
}
|
|
48
56
|
};
|
|
49
57
|
}
|