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
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { HtmlWorkerRenderState } from "./types.js";
|
|
2
2
|
import { PassThrough } from "stream";
|
|
3
|
-
import { workerData } from "node:worker_threads";
|
|
4
|
-
import type {
|
|
3
|
+
import { workerData, parentPort } from "node:worker_threads";
|
|
4
|
+
import type { SerializeableRenderToPipeableStreamOptions } from "../types.js";
|
|
5
5
|
import { type ErrorInfo } from "react";
|
|
6
|
-
import { createFromNodeStream } from "react-server-dom-esm/client.node";
|
|
7
6
|
import { Transform } from "node:stream";
|
|
8
7
|
import type { HtmlWorkerOutputMessage } from "../types.js";
|
|
9
8
|
import { join } from "node:path";
|
|
10
9
|
import type { StreamMetrics } from "../../types.js";
|
|
11
|
-
import { ReactDOMServer } from "../../vendor/vendor.client.js";
|
|
10
|
+
import { ReactDOMServer, ReactDOMClient } from "../../vendor/vendor.client.js";
|
|
12
11
|
|
|
12
|
+
type CallServerCallback = (id: string, args: unknown[]) => Promise<unknown>;
|
|
13
13
|
|
|
14
14
|
const createMetrics = (): StreamMetrics => {
|
|
15
15
|
return {
|
|
@@ -47,7 +47,31 @@ export function createHtmlWorkerRenderState(
|
|
|
47
47
|
if(!moduleRootPath.endsWith('/')) {
|
|
48
48
|
moduleRootPath = moduleRootPath + '/';
|
|
49
49
|
}
|
|
50
|
-
const elements = createFromNodeStream(rscStream, moduleRootPath, moduleBaseURL
|
|
50
|
+
const elements = ReactDOMClient.createFromNodeStream(rscStream, moduleRootPath, moduleBaseURL, {
|
|
51
|
+
callServer: (async (id: string, args: unknown[]) => {
|
|
52
|
+
// Forward server action calls back to the main thread
|
|
53
|
+
sendMessage({
|
|
54
|
+
type: "SERVER_ACTION",
|
|
55
|
+
id,
|
|
56
|
+
args
|
|
57
|
+
} as HtmlWorkerOutputMessage);
|
|
58
|
+
console.log('[html-worker] callServer', id, args);
|
|
59
|
+
// Wait for response
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const handler = (msg: any) => {
|
|
62
|
+
if (msg.type === "SERVER_ACTION_RESPONSE" && msg.id === id) {
|
|
63
|
+
parentPort?.removeListener("message", handler);
|
|
64
|
+
if (msg.error) {
|
|
65
|
+
reject(new Error(msg.error));
|
|
66
|
+
} else {
|
|
67
|
+
resolve(msg.result);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
parentPort?.on("message", handler);
|
|
72
|
+
});
|
|
73
|
+
}) as CallServerCallback
|
|
74
|
+
});
|
|
51
75
|
const metrics = createMetrics();
|
|
52
76
|
const htmlTransform = new Transform({
|
|
53
77
|
transform(chunk, encoding, callback) {
|
|
@@ -69,7 +93,7 @@ export function createHtmlWorkerRenderState(
|
|
|
69
93
|
id,
|
|
70
94
|
success: true,
|
|
71
95
|
metrics: metrics,
|
|
72
|
-
});
|
|
96
|
+
} satisfies HtmlWorkerOutputMessage);
|
|
73
97
|
callback();
|
|
74
98
|
},
|
|
75
99
|
})
|
|
@@ -80,7 +104,7 @@ export function createHtmlWorkerRenderState(
|
|
|
80
104
|
sendMessage({
|
|
81
105
|
type: "ALL_READY",
|
|
82
106
|
id,
|
|
83
|
-
} satisfies
|
|
107
|
+
} satisfies HtmlWorkerOutputMessage);
|
|
84
108
|
},
|
|
85
109
|
onError: (error: unknown, errorInfo: ErrorInfo) => {
|
|
86
110
|
sendMessage({
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { messageHandler } from "./messageHandler.js";
|
|
3
|
-
import {
|
|
4
|
-
import { pluginRoot } from "../../root.js";
|
|
5
|
-
import { register } from "node:module";
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
6
3
|
import type { ReadyMessage } from "../types.js";
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
const cssLoaderChannel = new MessageChannel();
|
|
10
|
-
cssLoaderChannel.port2.on("message", messageHandler);
|
|
11
|
-
|
|
12
|
-
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
|
|
13
|
-
register(cssLoaderPath, {
|
|
14
|
-
parentURL: pluginRoot,
|
|
15
|
-
data: { port: cssLoaderChannel.port1 },
|
|
16
|
-
transferList: [cssLoaderChannel.port1],
|
|
17
|
-
});
|
|
5
|
+
const verbose = workerData.verbose;
|
|
18
6
|
|
|
7
|
+
function developmentMessageHandler(msg: any) {
|
|
8
|
+
if (verbose) {
|
|
9
|
+
if ("chunk" in msg) {
|
|
10
|
+
let preview = Buffer.from(msg.chunk).toString("utf-8");
|
|
11
|
+
console.log(`[html-worker:${msg.type}] ${preview}`);
|
|
12
|
+
} else {
|
|
13
|
+
console.log(`[html-worker:${msg.type}] ${JSON.stringify(msg)}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
messageHandler(msg);
|
|
17
|
+
}
|
|
19
18
|
|
|
20
19
|
// Signal ready with environment
|
|
21
|
-
parentPort?.on("message",
|
|
20
|
+
parentPort?.on("message", developmentMessageHandler);
|
|
22
21
|
parentPort?.postMessage({
|
|
23
22
|
type: "READY",
|
|
23
|
+
id: "html-worker",
|
|
24
24
|
env: process.env["NODE_ENV"],
|
|
25
25
|
pid: process.pid,
|
|
26
|
-
} satisfies ReadyMessage);
|
|
26
|
+
} satisfies ReadyMessage);
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { messageHandler } from "./messageHandler.js";
|
|
3
|
-
import {
|
|
4
|
-
import { pluginRoot } from "../../root.js";
|
|
5
|
-
import { register } from "node:module";
|
|
2
|
+
import { parentPort } from "node:worker_threads";
|
|
6
3
|
import type { ReadyMessage } from "../types.js";
|
|
7
4
|
|
|
8
|
-
// Create channels for each loader
|
|
9
|
-
const cssLoaderChannel = new MessageChannel();
|
|
10
|
-
|
|
11
|
-
cssLoaderChannel.port2.on("message", messageHandler);
|
|
12
|
-
|
|
13
|
-
const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.production.js");
|
|
14
|
-
|
|
15
|
-
register(cssLoaderPath, {
|
|
16
|
-
parentURL: pluginRoot,
|
|
17
|
-
data: { port: cssLoaderChannel.port1 },
|
|
18
|
-
transferList: [cssLoaderChannel.port1],
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
|
|
22
5
|
// Signal ready with environment
|
|
23
6
|
parentPort?.on("message", messageHandler);
|
|
24
7
|
parentPort?.postMessage({
|
|
25
8
|
type: "READY",
|
|
9
|
+
id: "html-worker",
|
|
26
10
|
env: process.env["NODE_ENV"],
|
|
27
11
|
pid: process.pid,
|
|
28
|
-
} satisfies ReadyMessage);
|
|
12
|
+
} satisfies ReadyMessage);
|
|
@@ -3,10 +3,9 @@ import type {
|
|
|
3
3
|
HtmlWorkerInputMessage,
|
|
4
4
|
HtmlWorkerOutputMessage,
|
|
5
5
|
} from "../types.js";
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import * as ReactDOMServer from "react-dom/server.node";
|
|
8
6
|
import type { HtmlWorkerRenderState } from "./types.js";
|
|
9
7
|
import { createHtmlWorkerRenderState } from "./createHtmlWorkerRenderState.js";
|
|
8
|
+
import { toError } from "../../error/toError.js";
|
|
10
9
|
|
|
11
10
|
// Track active renders
|
|
12
11
|
const activeRenders = new Map<string, HtmlWorkerRenderState>();
|
|
@@ -41,7 +40,6 @@ function cleanup(id: string) {
|
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
export async function messageHandler(msg: HtmlWorkerInputMessage) {
|
|
46
44
|
const { type, id } = msg;
|
|
47
45
|
try {
|
|
@@ -120,7 +118,7 @@ export async function messageHandler(msg: HtmlWorkerInputMessage) {
|
|
|
120
118
|
sendMessage({
|
|
121
119
|
type: "ERROR",
|
|
122
120
|
id,
|
|
123
|
-
error:
|
|
121
|
+
error: toError(error),
|
|
124
122
|
});
|
|
125
123
|
}
|
|
126
124
|
}
|
|
@@ -9,9 +9,12 @@ import { workerData } from "node:worker_threads";
|
|
|
9
9
|
import { React } from "../../vendor/vendor.server.js";
|
|
10
10
|
import { hmrState } from "./state.js";
|
|
11
11
|
import { performance } from "node:perf_hooks";
|
|
12
|
+
import type { PagePropOpt } from "../../types.js";
|
|
12
13
|
|
|
13
|
-
export async function handleRender
|
|
14
|
-
|
|
14
|
+
export async function handleRender<
|
|
15
|
+
T extends PagePropOpt = PagePropOpt
|
|
16
|
+
>(
|
|
17
|
+
msg: RscRenderMessage<T>,
|
|
15
18
|
handlers: StreamHandlers
|
|
16
19
|
) {
|
|
17
20
|
let {
|
|
@@ -54,14 +57,14 @@ export async function handleRender(
|
|
|
54
57
|
});
|
|
55
58
|
if (pageAndPropsResult.type !== "success") {
|
|
56
59
|
const { error, ...rest } = pageAndPropsResult;
|
|
57
|
-
return handlers.onError(error, rest);
|
|
60
|
+
return handlers.onError(id, error, rest);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
const { PageComponent, pageProps } = pageAndPropsResult;
|
|
61
64
|
|
|
62
65
|
const adaptedOnEvent = (event: "error" | "postpone", data: any) => {
|
|
63
66
|
if (event === "error") {
|
|
64
|
-
handlers.onError(data.error, data.errorInfo);
|
|
67
|
+
handlers.onError(id, data.error, data.errorInfo);
|
|
65
68
|
}
|
|
66
69
|
};
|
|
67
70
|
|
|
@@ -76,8 +79,8 @@ export async function handleRender(
|
|
|
76
79
|
const streamResult = createRscStream({
|
|
77
80
|
projectRoot: projectRoot,
|
|
78
81
|
Html: React.Fragment,
|
|
79
|
-
PageComponent
|
|
80
|
-
CssCollector
|
|
82
|
+
PageComponent,
|
|
83
|
+
CssCollector,
|
|
81
84
|
pageProps,
|
|
82
85
|
moduleBase,
|
|
83
86
|
moduleRootPath,
|
|
@@ -93,7 +96,7 @@ export async function handleRender(
|
|
|
93
96
|
});
|
|
94
97
|
|
|
95
98
|
if (streamResult.type !== "success") {
|
|
96
|
-
handlers.onError(streamResult.error);
|
|
99
|
+
handlers.onError(id, streamResult.error);
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -111,26 +114,26 @@ export async function handleRender(
|
|
|
111
114
|
metrics.chunks++;
|
|
112
115
|
metrics.bytes += chunk.length;
|
|
113
116
|
metrics.duration = performance.now() - metrics.startTime;
|
|
114
|
-
handlers.onData(chunk);
|
|
117
|
+
handlers.onData(id, chunk);
|
|
115
118
|
});
|
|
116
119
|
|
|
117
120
|
// Handle stream end
|
|
118
121
|
passThrough.on("end", () => {
|
|
119
122
|
metrics.duration = performance.now() - metrics.startTime;
|
|
120
|
-
handlers.onEnd();
|
|
123
|
+
handlers.onEnd(id);
|
|
121
124
|
if (activeStreams.has(id)) {
|
|
122
|
-
handlers.onMetrics(metrics);
|
|
125
|
+
handlers.onMetrics(id, metrics);
|
|
123
126
|
activeStreams.delete(id);
|
|
124
127
|
}
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
// Handle errors
|
|
128
131
|
passThrough.on("error", (error) => {
|
|
129
|
-
handlers.onError(error as Error, { reason: `${id} stream error` });
|
|
132
|
+
handlers.onError(id, error as Error, { reason: `${id} stream error` });
|
|
130
133
|
activeStreams.delete(id);
|
|
131
134
|
});
|
|
132
135
|
} catch (error) {
|
|
133
|
-
handlers.onError(error as Error, { reason: `${id} render error` });
|
|
136
|
+
handlers.onError(id, error as Error, { reason: `${id} render error` });
|
|
134
137
|
return Promise.reject(error);
|
|
135
138
|
}
|
|
136
139
|
}
|
|
@@ -1,138 +1,209 @@
|
|
|
1
1
|
import { parentPort, workerData } from "node:worker_threads";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
activeStreams,
|
|
4
|
+
addCssFileContent,
|
|
5
|
+
hmrState,
|
|
6
|
+
addModuleId,
|
|
7
|
+
} from "./state.js";
|
|
3
8
|
import { handleRender } from "./handleRender.js";
|
|
4
9
|
import type {
|
|
5
|
-
HmrAcceptMessage,
|
|
6
10
|
RscWorkerInputMessage,
|
|
7
|
-
RscWorkerOutputMessage,
|
|
8
11
|
StreamHandlers,
|
|
9
12
|
} from "../types.js";
|
|
10
|
-
import {
|
|
13
|
+
import { sendRscWorkerMessage } from "../sendMessage.js";
|
|
14
|
+
import { toError } from "../../error/toError.js";
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
// In test mode, we want errors to propagate up immediately
|
|
17
|
+
const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
|
|
18
|
+
const isDevEnv = process.env["NODE_ENV"] !== "production";
|
|
19
|
+
|
|
20
|
+
const handlers: Required<StreamHandlers> = {
|
|
21
|
+
onError: (id, error, errorInfo) => {
|
|
22
|
+
sendRscWorkerMessage({
|
|
23
|
+
type: "ERROR",
|
|
24
|
+
id: id,
|
|
25
|
+
errorInfo,
|
|
26
|
+
error: toError(error),
|
|
27
|
+
});
|
|
28
|
+
sendRscWorkerMessage({
|
|
29
|
+
type: "RSC_END",
|
|
30
|
+
id: id,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
onData: (id, data: any) => {
|
|
34
|
+
sendRscWorkerMessage({
|
|
35
|
+
type: "RSC_CHUNK",
|
|
36
|
+
id: id,
|
|
37
|
+
chunk: data,
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
onEnd: (id: string) => {
|
|
41
|
+
sendRscWorkerMessage({
|
|
42
|
+
type: "RSC_END",
|
|
43
|
+
id: id,
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
onMetrics: (id: string, metrics: any) => {
|
|
47
|
+
sendRscWorkerMessage({
|
|
48
|
+
type: "RSC_METRICS",
|
|
49
|
+
id: id,
|
|
50
|
+
metrics,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
onHmrAccept: (id, routes) => {
|
|
54
|
+
sendRscWorkerMessage({
|
|
55
|
+
type: "HMR_ACCEPT",
|
|
56
|
+
id: id,
|
|
57
|
+
routes: routes,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
onHmrUpdate: (id, routes) => {
|
|
61
|
+
sendRscWorkerMessage({
|
|
62
|
+
type: "HMR_UPDATE",
|
|
63
|
+
id: id,
|
|
64
|
+
routes: routes,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
onServerModule: (id, url, source) => {
|
|
68
|
+
sendRscWorkerMessage({
|
|
69
|
+
type: "SERVER_MODULE",
|
|
70
|
+
id,
|
|
71
|
+
url,
|
|
72
|
+
source,
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
onServerActionResponse: (id, result, error) => {
|
|
76
|
+
sendRscWorkerMessage({
|
|
77
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
78
|
+
id,
|
|
79
|
+
result,
|
|
80
|
+
error,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
onServerAction: async (id, args) => {
|
|
84
|
+
try {
|
|
85
|
+
// Get the server action function from the worker data
|
|
86
|
+
const serverAction = workerData.serverActions?.[id];
|
|
87
|
+
if (!serverAction) {
|
|
88
|
+
throw new Error(`Server action ${id} not found`);
|
|
23
89
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
name: error.name,
|
|
32
|
-
cause: error.cause,
|
|
33
|
-
},
|
|
34
|
-
} satisfies RscWorkerOutputMessage);
|
|
35
|
-
port.postMessage({
|
|
36
|
-
type: "RSC_END",
|
|
37
|
-
id: msg.id,
|
|
38
|
-
} satisfies RscWorkerOutputMessage);
|
|
39
|
-
},
|
|
40
|
-
onData: (data: any) => {
|
|
41
|
-
port.postMessage({
|
|
42
|
-
type: "RSC_CHUNK",
|
|
43
|
-
id: msg.id,
|
|
44
|
-
chunk: data,
|
|
45
|
-
} satisfies RscWorkerOutputMessage);
|
|
46
|
-
},
|
|
47
|
-
onEnd: () => {
|
|
48
|
-
port.postMessage({
|
|
49
|
-
type: "RSC_END",
|
|
50
|
-
id: msg.id,
|
|
51
|
-
} satisfies RscWorkerOutputMessage);
|
|
52
|
-
},
|
|
53
|
-
onMetrics: (metrics: any) => {
|
|
54
|
-
port.postMessage({
|
|
55
|
-
type: "RSC_METRICS",
|
|
56
|
-
id: msg.id,
|
|
57
|
-
metrics,
|
|
58
|
-
} satisfies RscWorkerOutputMessage);
|
|
59
|
-
},
|
|
60
|
-
onHmrAccept: (routes: string[]) => {
|
|
61
|
-
port.postMessage({
|
|
62
|
-
type: "HMR_ACCEPT",
|
|
63
|
-
id: (msg as HmrAcceptMessage).id,
|
|
64
|
-
routes: routes,
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
onHmrUpdate: (routes: string[]) => {
|
|
68
|
-
port.postMessage({
|
|
69
|
-
type: "HMR_UPDATE",
|
|
70
|
-
id: msg.id,
|
|
71
|
-
routes: routes,
|
|
90
|
+
// Execute the server action
|
|
91
|
+
const result = await serverAction(...args);
|
|
92
|
+
// Send the result back
|
|
93
|
+
sendRscWorkerMessage({
|
|
94
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
95
|
+
id,
|
|
96
|
+
result,
|
|
72
97
|
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
case "INITIALIZED_CSS_LOADER":
|
|
81
|
-
return;
|
|
82
|
-
case "INITIALIZED_ENV_LOADER":
|
|
83
|
-
return;
|
|
84
|
-
case "HMR_UPDATE":
|
|
85
|
-
// Mark the module as invalidated
|
|
86
|
-
hmrState.set(msg.id, {
|
|
87
|
-
timestamp: msg.timestamp || Date.now(),
|
|
88
|
-
invalidated: true,
|
|
89
|
-
routes: msg.routes || [],
|
|
98
|
+
} catch (error) {
|
|
99
|
+
// Send error back
|
|
100
|
+
sendRscWorkerMessage({
|
|
101
|
+
type: "SERVER_ACTION_RESPONSE",
|
|
102
|
+
id,
|
|
103
|
+
error: error instanceof Error ? error.message : String(error),
|
|
90
104
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (msg.id) {
|
|
102
|
-
const cssOptions = workerData.userOptions.css || {
|
|
103
|
-
inlineThreshold: 1000,
|
|
104
|
-
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
onShutdown: (id: string) => {
|
|
108
|
+
// Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
|
|
109
|
+
sendRscWorkerMessage({
|
|
110
|
+
type: "SHUTDOWN_COMPLETE",
|
|
111
|
+
id: id,
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
};
|
|
105
115
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
export async function messageHandler(
|
|
117
|
+
msg: RscWorkerInputMessage,
|
|
118
|
+
port = parentPort
|
|
119
|
+
) {
|
|
120
|
+
try {
|
|
121
|
+
if (!port) {
|
|
122
|
+
throw new Error("No port found");
|
|
123
|
+
}
|
|
124
|
+
switch (msg.type) {
|
|
125
|
+
case "RSC_RENDER":
|
|
126
|
+
return await handleRender(msg, handlers);
|
|
127
|
+
case "SERVER_ACTION":
|
|
128
|
+
return handlers.onServerAction(msg.id, msg.args);
|
|
129
|
+
case "INITIALIZED_REACT_LOADER":
|
|
130
|
+
return;
|
|
131
|
+
case "INITIALIZED_CSS_LOADER":
|
|
132
|
+
return;
|
|
133
|
+
case "INITIALIZED_ENV_LOADER":
|
|
134
|
+
return;
|
|
135
|
+
case "HMR_UPDATE":
|
|
136
|
+
// Mark the module as invalidated
|
|
137
|
+
hmrState.set(msg.id, {
|
|
138
|
+
timestamp: msg.timestamp || Date.now(),
|
|
139
|
+
invalidated: true,
|
|
140
|
+
routes: msg.routes || [],
|
|
112
141
|
});
|
|
142
|
+
// Notify the main thread that we've processed the update
|
|
143
|
+
handlers.onHmrUpdate(msg.id, msg.routes || []);
|
|
144
|
+
return;
|
|
145
|
+
case "HMR_CLEANUP":
|
|
146
|
+
// Clear the invalidation state
|
|
147
|
+
hmrState.delete(msg.id);
|
|
148
|
+
// Notify the main thread that we've processed the cleanup
|
|
149
|
+
handlers.onHmrAccept(msg.id, msg.routes || []);
|
|
150
|
+
return;
|
|
151
|
+
case "CSS_FILE":
|
|
152
|
+
if (msg.id) {
|
|
153
|
+
const cssOptions = workerData.userOptions.css || {
|
|
154
|
+
inlineThreshold: 1000,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
addCssFileContent(msg.id, msg.content, {
|
|
158
|
+
projectRoot: workerData.userOptions.projectRoot || process.cwd(),
|
|
159
|
+
moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
|
|
160
|
+
moduleBasePath: workerData.userOptions.moduleBasePath || "/",
|
|
161
|
+
moduleRootPath: workerData.userOptions.moduleRootPath,
|
|
162
|
+
css: cssOptions,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
case "SERVER_MODULE":
|
|
167
|
+
if (msg.id && msg.url) {
|
|
168
|
+
addModuleId(msg.id, msg.url);
|
|
169
|
+
}
|
|
170
|
+
handlers.onServerModule(msg.id, msg.url, msg.source);
|
|
171
|
+
return;
|
|
172
|
+
case "SHUTDOWN": {
|
|
173
|
+
// If id is "*", clean up all render states
|
|
174
|
+
if (msg.id === "*") {
|
|
175
|
+
activeStreams.forEach((stream, renderId) => {
|
|
176
|
+
stream.end();
|
|
177
|
+
activeStreams.delete(renderId);
|
|
178
|
+
});
|
|
179
|
+
parentPort?.removeAllListeners();
|
|
180
|
+
} else {
|
|
181
|
+
activeStreams.delete(msg.id);
|
|
182
|
+
}
|
|
183
|
+
handlers.onShutdown(msg.id);
|
|
184
|
+
return;
|
|
113
185
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (msg.id === "*") {
|
|
118
|
-
activeStreams.forEach((stream, renderId) => {
|
|
119
|
-
stream.end();
|
|
120
|
-
activeStreams.delete(renderId);
|
|
121
|
-
});
|
|
122
|
-
parentPort?.removeAllListeners();
|
|
123
|
-
} else {
|
|
124
|
-
activeStreams.delete(msg.id);
|
|
186
|
+
default: {
|
|
187
|
+
console.log("Unknown message", msg);
|
|
188
|
+
return;
|
|
125
189
|
}
|
|
126
|
-
// Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
|
|
127
|
-
sendMessage({
|
|
128
|
-
type: "SHUTDOWN_COMPLETE",
|
|
129
|
-
id: msg.id,
|
|
130
|
-
} satisfies RscWorkerOutputMessage);
|
|
131
|
-
return;
|
|
132
190
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
191
|
+
} catch (error) {
|
|
192
|
+
const err = toError(error);
|
|
193
|
+
if (isDevEnv) {
|
|
194
|
+
console.error(err);
|
|
195
|
+
}
|
|
196
|
+
// In dev mode, try to send error message before exiting
|
|
197
|
+
if (parentPort) {
|
|
198
|
+
port?.postMessage({
|
|
199
|
+
type: "ERROR",
|
|
200
|
+
id: "rsc-worker",
|
|
201
|
+
error: err,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (!isDevEnv || isTestEnv) {
|
|
205
|
+
// In test mode or production mode, just throw the error to fail fast
|
|
206
|
+
throw err;
|
|
136
207
|
}
|
|
137
208
|
}
|
|
138
209
|
}
|