vite-plugin-react-server 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -76
- package/bin/patch.mjs +27 -20
- package/dist/_virtual/dynamic-import-helper.js +24 -0
- package/dist/_virtual/dynamic-import-helper.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/package.json +24 -14
- package/dist/plugin/components.d.ts +1 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js +30 -0
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.js.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts +13 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js +24 -0
- package/dist/plugin/config/autoDiscover/customWorkerFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts +11 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js +29 -0
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.js.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts +6 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.d.ts.map +1 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +83 -0
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +18 -14
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +42 -21
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/getCondition.d.ts +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +2 -2
- package/dist/plugin/config/getCondition.js.map +1 -1
- package/dist/plugin/config/getPaths.d.ts +0 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.js.map +1 -1
- package/dist/plugin/config/index.d.ts +0 -1
- package/dist/plugin/config/index.d.ts.map +1 -1
- package/dist/plugin/config/index.js +0 -1
- package/dist/plugin/config/resolveAutoDiscover.d.ts +20 -0
- package/dist/plugin/config/resolveAutoDiscover.d.ts.map +1 -0
- package/dist/plugin/config/resolveAutoDiscover.js +128 -0
- package/dist/plugin/config/resolveAutoDiscover.js.map +1 -0
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +109 -77
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +0 -1
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js +6 -8
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUrlOption.d.ts +16 -0
- package/dist/plugin/config/resolveUrlOption.d.ts.map +1 -0
- package/dist/plugin/config/resolveUrlOption.js +37 -0
- package/dist/plugin/config/resolveUrlOption.js.map +1 -0
- package/dist/plugin/config/resolveUserConfig.d.ts +4 -5
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +80 -132
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/copy.d.ts +7 -0
- package/dist/plugin/copy.d.ts.map +1 -0
- package/dist/plugin/copy.js +30 -0
- package/dist/plugin/css-collector-elements.d.ts +4 -0
- package/dist/plugin/css-collector-elements.d.ts.map +1 -0
- package/dist/plugin/css-collector-elements.js +19 -0
- package/dist/plugin/css-collector-elements.js.map +1 -0
- package/dist/plugin/css-collector.d.ts +2 -8
- package/dist/plugin/css-collector.d.ts.map +1 -1
- package/dist/plugin/css-collector.js +9 -36
- package/dist/plugin/css-collector.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.d.ts +3 -0
- package/dist/plugin/helpers/cleanObject.d.ts.map +1 -0
- package/dist/plugin/helpers/cleanObject.js +47 -0
- package/dist/plugin/helpers/cleanObject.js.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts +8 -0
- package/dist/plugin/helpers/collectBundleManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectBundleManifestCss.js +110 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts +7 -0
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectManifestCss.js +44 -0
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +31 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +104 -0
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -0
- package/dist/plugin/helpers/createCssProps.d.ts +25 -0
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -0
- package/dist/plugin/helpers/createCssProps.js +57 -0
- package/dist/plugin/helpers/createCssProps.js.map +1 -0
- package/dist/plugin/helpers/createEventHandler.d.ts +22 -0
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -0
- package/dist/plugin/helpers/createEventHandler.js +36 -0
- package/dist/plugin/helpers/createEventHandler.js.map +1 -0
- package/dist/plugin/helpers/createHandler.d.ts +7 -13
- package/dist/plugin/helpers/createHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createHandler.js +54 -96
- package/dist/plugin/helpers/createHandler.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts +12 -26
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +105 -51
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/defaultFileWriter.d.ts +2 -0
- package/dist/plugin/helpers/defaultFileWriter.d.ts.map +1 -0
- package/dist/plugin/helpers/defaultFileWriter.js +1 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts +10 -16
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +30 -22
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts +14 -0
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -0
- package/dist/plugin/helpers/getRouteFiles.js +36 -0
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +38 -32
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/metrics.d.ts +11 -0
- package/dist/plugin/helpers/metrics.d.ts.map +1 -0
- package/dist/plugin/helpers/metrics.js +35 -0
- package/dist/plugin/helpers/metrics.js.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts +27 -0
- package/dist/plugin/helpers/resolvePageAndProps.d.ts.map +1 -0
- package/dist/plugin/helpers/resolvePageAndProps.js +51 -0
- package/dist/plugin/helpers/resolvePageAndProps.js.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts +8 -0
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -0
- package/dist/plugin/helpers/serializeUserOptions.js +182 -0
- package/dist/plugin/helpers/serializeUserOptions.js.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts +2 -0
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -0
- package/dist/plugin/helpers/stashReturnValue.js +14 -0
- package/dist/plugin/helpers/tryManifest.d.ts +5 -3
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +16 -7
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/html.d.ts +2 -3
- package/dist/plugin/html.d.ts.map +1 -1
- package/dist/plugin/html.js +7 -1
- package/dist/plugin/html.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +3 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +26 -4
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +98 -33
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/css-loader.development.d.ts +57 -0
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.development.js +81 -0
- package/dist/plugin/loader/css-loader.development.js.map +1 -0
- package/dist/plugin/loader/css-loader.production.d.ts +31 -0
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -0
- package/dist/plugin/loader/css-loader.production.js +45 -0
- package/dist/plugin/loader/css-loader.production.js.map +1 -0
- package/dist/plugin/loader/index.d.ts +2 -0
- package/dist/plugin/loader/index.d.ts.map +1 -0
- package/dist/plugin/loader/index.js +1 -0
- package/dist/plugin/loader/plugin.d.ts +22 -0
- package/dist/plugin/loader/plugin.d.ts.map +1 -0
- package/dist/plugin/loader/plugin.js +27 -0
- package/dist/plugin/loader/react-loader.d.ts +3 -7
- package/dist/plugin/loader/react-loader.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.js +85 -30
- package/dist/plugin/loader/react-loader.js.map +1 -1
- package/dist/plugin/loader/temporaryReferences.d.ts +2 -0
- package/dist/plugin/loader/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/loader/temporaryReferences.js +11 -0
- package/dist/plugin/loader/temporaryReferences.js.map +1 -0
- package/dist/plugin/moduleRefs.d.ts +7 -0
- package/dist/plugin/moduleRefs.d.ts.map +1 -0
- package/dist/plugin/moduleRefs.js +17 -0
- package/dist/plugin/moduleRefs.js.map +1 -0
- package/dist/plugin/plugin.client.d.ts +3 -0
- package/dist/plugin/plugin.client.d.ts.map +1 -0
- package/dist/plugin/plugin.client.js +19 -0
- package/dist/plugin/plugin.client.js.map +1 -0
- package/dist/plugin/plugin.d.ts +1 -5
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +3 -9
- package/dist/plugin/plugin.server.d.ts +3 -0
- package/dist/plugin/plugin.server.d.ts.map +1 -0
- package/dist/plugin/plugin.server.js +28 -0
- package/dist/plugin/plugin.server.js.map +1 -0
- package/dist/plugin/preserver/plugin.js +1 -1
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +1 -2
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +1 -19
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +60 -219
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-client/server.d.ts +27 -0
- package/dist/plugin/react-client/server.d.ts.map +1 -0
- package/dist/plugin/react-client/server.js +197 -0
- package/dist/plugin/react-client/server.js.map +1 -0
- package/dist/plugin/react-server/index.d.ts +1 -2
- package/dist/plugin/react-server/index.d.ts.map +1 -1
- package/dist/plugin/react-server/index.js +1 -21
- package/dist/plugin/react-server/plugin.d.ts +0 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +60 -186
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-server/server.d.ts +9 -0
- package/dist/plugin/react-server/server.d.ts.map +1 -0
- package/dist/plugin/react-server/server.js +120 -0
- package/dist/plugin/react-server/server.js.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts +23 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js +85 -0
- package/dist/plugin/react-static/collectHtmlWorkerContent.js.map +1 -0
- package/dist/plugin/react-static/collectRscContent.d.ts +24 -0
- package/dist/plugin/react-static/collectRscContent.d.ts.map +1 -0
- package/dist/plugin/react-static/collectRscContent.js +49 -0
- package/dist/plugin/react-static/collectRscContent.js.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts +7 -0
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -0
- package/dist/plugin/react-static/configurePreviewServer.js +67 -0
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -0
- package/dist/plugin/react-static/fileWriter.d.ts +23 -0
- package/dist/plugin/react-static/fileWriter.d.ts.map +1 -0
- package/dist/plugin/react-static/fileWriter.js +65 -0
- package/dist/plugin/react-static/fileWriter.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts +15 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +248 -149
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPage.d.ts +3 -0
- package/dist/plugin/react-static/renderPage.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPage.js +116 -0
- package/dist/plugin/react-static/renderPage.js.map +1 -0
- package/dist/plugin/react-static/renderPages.d.ts +3 -0
- package/dist/plugin/react-static/renderPages.d.ts.map +1 -0
- package/dist/plugin/react-static/renderPages.js +125 -0
- package/dist/plugin/react-static/renderPages.js.map +1 -0
- package/dist/plugin/react-static/renderStreams.d.ts +26 -0
- package/dist/plugin/react-static/renderStreams.d.ts.map +1 -0
- package/dist/plugin/react-static/renderStreams.js +27 -0
- package/dist/plugin/react-static/renderStreams.js.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts +22 -0
- package/dist/plugin/react-static/rscToHtmlStream.d.ts.map +1 -0
- package/dist/plugin/react-static/rscToHtmlStream.js +54 -0
- package/dist/plugin/react-static/rscToHtmlStream.js.map +1 -0
- package/dist/plugin/react-static/streamHandler.d.ts +2 -0
- package/dist/plugin/react-static/streamHandler.d.ts.map +1 -0
- package/dist/plugin/react-static/streamHandler.js +1 -0
- package/dist/plugin/react-static/types.d.ts +11 -0
- package/dist/plugin/react-static/types.d.ts.map +1 -1
- package/dist/plugin/resolvePage.d.ts +26 -9
- package/dist/plugin/resolvePage.d.ts.map +1 -1
- package/dist/plugin/resolvePage.js +41 -39
- package/dist/plugin/resolvePage.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts +40 -7
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +100 -75
- package/dist/plugin/resolveProps.js.map +1 -1
- package/dist/plugin/root.d.ts +1 -0
- package/dist/plugin/root.d.ts.map +1 -1
- package/dist/plugin/root.js +1 -0
- package/dist/plugin/root.js.map +1 -1
- package/dist/plugin/transformer/index.d.ts +2 -1
- package/dist/plugin/transformer/index.d.ts.map +1 -1
- package/dist/plugin/transformer/index.js +2 -1
- package/dist/plugin/transformer/plugin.client.d.ts +4 -0
- package/dist/plugin/transformer/plugin.client.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.client.js +83 -0
- package/dist/plugin/transformer/plugin.client.js.map +1 -0
- package/dist/plugin/transformer/plugin.d.ts +1 -27
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +3 -87
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.server.d.ts +4 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +76 -0
- package/dist/plugin/transformer/plugin.server.js.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts +11 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.d.ts.map +1 -0
- package/dist/plugin/transformer/upgradeCssModuleCode.js +38 -0
- package/dist/plugin/types/css-tracking.d.ts +6 -0
- package/dist/plugin/types/css-tracking.d.ts.map +1 -0
- package/dist/plugin/types/css-tracking.js +1 -0
- package/dist/plugin/types.d.ts +372 -86
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/types.js +1 -1
- package/dist/plugin/vendor.client.d.ts +4 -0
- package/dist/plugin/vendor.client.d.ts.map +1 -0
- package/dist/plugin/vendor.client.js +16 -0
- package/dist/plugin/vendor.client.js.map +1 -0
- package/dist/plugin/vendor.server.d.ts +4 -0
- package/dist/plugin/vendor.server.d.ts.map +1 -0
- package/dist/plugin/vendor.server.js +16 -0
- package/dist/plugin/vendor.server.js.map +1 -0
- package/dist/plugin/worker/createWorker.d.ts +25 -7
- package/dist/plugin/worker/createWorker.d.ts.map +1 -1
- package/dist/plugin/worker/createWorker.js +108 -33
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts +12 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.d.ts.map +1 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js +103 -0
- package/dist/plugin/worker/html/createHtmlWorkerRenderState.js.map +1 -0
- package/dist/plugin/worker/html/html-worker.development.d.ts +0 -30
- package/dist/plugin/worker/html/html-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/html/html-worker.development.js +3 -17
- package/dist/plugin/worker/html/html-worker.development.js.map +1 -1
- package/dist/plugin/worker/html/html-worker.production.js +12 -5
- package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +87 -84
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/types.d.ts +18 -0
- package/dist/plugin/worker/html/types.d.ts.map +1 -0
- package/dist/plugin/worker/html/types.js +1 -0
- package/dist/plugin/worker/registerLoaders.d.ts +9 -0
- package/dist/plugin/worker/registerLoaders.d.ts.map +1 -0
- package/dist/plugin/worker/registerLoaders.js +45 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts +4 -0
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handleRender.js +147 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts +2 -2
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +47 -112
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +0 -30
- package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +29 -4
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.production.js +3 -3
- package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +73 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +40 -3
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/sendMessage.d.ts +3 -0
- package/dist/plugin/worker/sendMessage.d.ts.map +1 -0
- package/dist/plugin/worker/sendMessage.js +48 -0
- package/dist/plugin/worker/types.d.ts +218 -76
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -1
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -14
- package/plugin/components.ts +1 -1
- package/plugin/config/autoDiscover/createGlobAutoDiscover.ts +29 -0
- package/plugin/config/autoDiscover/customWorkerFiles.ts +27 -0
- package/plugin/config/autoDiscover/pageAndPropFiles.ts +36 -0
- package/plugin/config/autoDiscover/resolveBuildPages.ts +98 -0
- package/plugin/config/defaults.tsx +38 -29
- package/plugin/config/getCondition.ts +7 -3
- package/plugin/config/getPaths.ts +1 -7
- package/plugin/config/index.ts +0 -1
- package/plugin/config/resolveAutoDiscover.ts +177 -0
- package/plugin/config/resolveOptions.ts +220 -118
- package/plugin/config/resolvePages.ts +5 -7
- package/plugin/config/resolveUrlOption.ts +43 -0
- package/plugin/config/resolveUserConfig.ts +116 -166
- package/plugin/copy.ts +39 -0
- package/plugin/css-collector-elements.tsx +21 -0
- package/plugin/css-collector.tsx +20 -53
- package/plugin/helpers/cleanObject.ts +50 -0
- package/plugin/helpers/collectBundleManifestCss.ts +160 -0
- package/plugin/helpers/collectManifestCss.ts +61 -0
- package/plugin/helpers/collectViteModuleGraphCss.ts +158 -0
- package/plugin/helpers/createCssProps.tsx +85 -0
- package/plugin/helpers/createEventHandler.ts +44 -0
- package/plugin/helpers/createHandler.ts +57 -126
- package/plugin/helpers/createRscStream.tsx +156 -0
- package/plugin/helpers/defaultFileWriter.ts +0 -0
- package/plugin/helpers/getBundleManifest.ts +42 -37
- package/plugin/helpers/getRouteFiles.ts +47 -0
- package/plugin/helpers/inputNormalizer.ts +16 -10
- package/plugin/helpers/metrics.ts +64 -0
- package/plugin/helpers/resolvePageAndProps.ts +81 -0
- package/plugin/helpers/serializeUserOptions.ts +209 -0
- package/plugin/helpers/stashReturnValue.ts +16 -0
- package/plugin/helpers/tryManifest.ts +35 -18
- package/plugin/html.tsx +14 -3
- package/plugin/index.ts +5 -2
- package/plugin/loader/createBuildLoader.ts +152 -47
- package/plugin/loader/css-loader.development.ts +157 -0
- package/plugin/loader/css-loader.production.ts +86 -0
- package/plugin/loader/index.ts +1 -0
- package/plugin/loader/plugin.ts +33 -0
- package/plugin/loader/react-loader.ts +109 -41
- package/plugin/loader/temporaryReferences.ts +3 -0
- package/plugin/moduleRefs.ts +11 -0
- package/plugin/plugin.client.ts +12 -0
- package/plugin/plugin.server.ts +25 -0
- package/plugin/plugin.ts +5 -9
- package/plugin/preserver/plugin.ts +1 -1
- package/plugin/react-client/index.ts +1 -12
- package/plugin/react-client/plugin.ts +70 -259
- package/plugin/react-client/server.ts +276 -0
- package/plugin/react-server/index.ts +1 -14
- package/plugin/react-server/plugin.ts +69 -220
- package/plugin/react-server/server.ts +128 -0
- package/plugin/react-static/collectHtmlWorkerContent.ts +120 -0
- package/plugin/react-static/collectRscContent.ts +77 -0
- package/plugin/react-static/configurePreviewServer.ts +68 -0
- package/plugin/react-static/fileWriter.ts +103 -0
- package/plugin/react-static/plugin.ts +308 -181
- package/plugin/react-static/renderPage.ts +151 -0
- package/plugin/react-static/renderPages.ts +154 -0
- package/plugin/react-static/renderStreams.ts +48 -0
- package/plugin/react-static/rscToHtmlStream.ts +85 -0
- package/plugin/react-static/streamHandler.ts +0 -0
- package/plugin/react-static/types.ts +10 -0
- package/plugin/resolvePage.ts +67 -57
- package/plugin/resolveProps.ts +148 -104
- package/plugin/root.ts +1 -1
- package/plugin/transformer/index.ts +2 -1
- package/plugin/transformer/plugin.client.ts +109 -0
- package/plugin/transformer/plugin.server.ts +98 -0
- package/plugin/transformer/plugin.ts +2 -115
- package/plugin/transformer/upgradeCssModuleCode.ts +42 -0
- package/plugin/types/css-tracking.ts +5 -0
- package/plugin/types/react-server-dom-esm.d.ts +54 -0
- package/plugin/types.ts +508 -97
- package/plugin/vendor.client.ts +12 -0
- package/plugin/vendor.server.ts +12 -0
- package/plugin/worker/createWorker.ts +158 -53
- package/plugin/worker/html/createHtmlWorkerRenderState.tsx +112 -0
- package/plugin/worker/html/html-worker.development.tsx +5 -75
- package/plugin/worker/html/html-worker.production.tsx +18 -7
- package/plugin/worker/html/messageHandler.tsx +126 -0
- package/plugin/worker/html/types.ts +19 -0
- package/plugin/worker/registerLoaders.ts +54 -0
- package/plugin/worker/rsc/handleRender.ts +180 -0
- package/plugin/worker/rsc/messageHandler.tsx +58 -132
- package/plugin/worker/rsc/rsc-worker.development.ts +49 -63
- package/plugin/worker/rsc/rsc-worker.production.ts +5 -5
- package/plugin/worker/rsc/state.ts +79 -2
- package/plugin/worker/sendMessage.ts +49 -0
- package/plugin/worker/types.ts +299 -100
- package/scripts/check-react-version.mjs +60 -48
- package/scripts/react+0.0.0-experimental-0ca8420f-20250504.patch +57 -0
- package/scripts/react-dom+0.0.0-experimental-0ca8420f-20250504.patch +819 -0
- package/scripts/{react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch → react-server-dom-esm+0.0.0-experimental-0ca8420f-20250504.patch} +1702 -2820
- package/tsconfig.json +7 -2
- package/dist/plugin/assertServerCondition.d.ts +0 -6
- package/dist/plugin/assertServerCondition.d.ts.map +0 -1
- package/dist/plugin/assertServerCondition.js +0 -13
- package/dist/plugin/checkFilesExist.d.ts +0 -3
- package/dist/plugin/checkFilesExist.d.ts.map +0 -1
- package/dist/plugin/checkFilesExist.js +0 -67
- package/dist/plugin/checkFilesExist.js.map +0 -1
- package/dist/plugin/collect-manifest-client-files.d.ts +0 -23
- package/dist/plugin/collect-manifest-client-files.d.ts.map +0 -1
- package/dist/plugin/collect-manifest-client-files.js +0 -131
- package/dist/plugin/collect-manifest-client-files.js.map +0 -1
- package/dist/plugin/config/getWorkerPath.d.ts +0 -2
- package/dist/plugin/config/getWorkerPath.d.ts.map +0 -1
- package/dist/plugin/config/getWorkerPath.js +0 -4
- package/dist/plugin/copy-dir.d.ts +0 -4
- package/dist/plugin/copy-dir.d.ts.map +0 -1
- package/dist/plugin/copy-dir.js +0 -25
- package/dist/plugin/copy-dir.js.map +0 -1
- package/dist/plugin/css-collector-inline.d.ts +0 -10
- package/dist/plugin/css-collector-inline.d.ts.map +0 -1
- package/dist/plugin/css-collector-inline.js +0 -55
- package/dist/plugin/css-collector-inline.js.map +0 -1
- package/dist/plugin/loader/css-loader.d.ts +0 -16
- package/dist/plugin/loader/css-loader.d.ts.map +0 -1
- package/dist/plugin/loader/css-loader.js +0 -70
- package/dist/plugin/loader/css-loader.js.map +0 -1
- package/dist/plugin/react-client/index.js.map +0 -1
- package/dist/plugin/react-server/index.js.map +0 -1
- package/dist/plugin/worker/html/renderPages.d.ts +0 -26
- package/dist/plugin/worker/html/renderPages.d.ts.map +0 -1
- package/dist/plugin/worker/html/renderPages.js +0 -241
- package/dist/plugin/worker/html/renderPages.js.map +0 -1
- package/plugin/assertServerCondition.ts +0 -12
- package/plugin/checkFilesExist.ts +0 -66
- package/plugin/collect-manifest-client-files.ts +0 -167
- package/plugin/config/getWorkerPath.ts +0 -5
- package/plugin/copy-dir.ts +0 -27
- package/plugin/css-collector-inline.tsx +0 -60
- package/plugin/helpers/createRscStream.ts +0 -109
- package/plugin/loader/css-loader.ts +0 -94
- package/plugin/worker/html/messageHandler.ts +0 -130
- package/plugin/worker/html/renderPages.ts +0 -293
- package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +0 -159
- package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +0 -12508
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { type MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { LoadHookContext } from "node:module";
|
|
3
|
+
import type { LoaderContext, SerializedUserConfig } from "../types.js";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { preprocessCSS } from "vite";
|
|
6
|
+
import type { ResolvedConfig } from "vite";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Global port for communication between the main thread and the CSS loader.
|
|
12
|
+
* This port is used to send CSS file requests and receive responses.
|
|
13
|
+
*/
|
|
14
|
+
export let loaderPort: MessagePort | undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tracks CSS files used by each page.
|
|
18
|
+
* Maps page URLs to sets of CSS file paths that are used by that page.
|
|
19
|
+
*/
|
|
20
|
+
const cssFilesByPage = new Map<string, Set<string>>();
|
|
21
|
+
|
|
22
|
+
let currentPage: string | null = null;
|
|
23
|
+
let resolvedConfig: ResolvedConfig | undefined;
|
|
24
|
+
// Get environment variables
|
|
25
|
+
const env = import.meta?.env || {
|
|
26
|
+
BASE_URL: '/',
|
|
27
|
+
DEV: true,
|
|
28
|
+
MODE: 'development',
|
|
29
|
+
PROD: false,
|
|
30
|
+
SSR: true
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initializes the CSS loader with the necessary communication channels.
|
|
35
|
+
* Sets up message handlers for CSS file requests and responses.
|
|
36
|
+
*
|
|
37
|
+
* @param data - Configuration data for the CSS loader
|
|
38
|
+
* @param data.port - The message port for communication
|
|
39
|
+
*/
|
|
40
|
+
export async function initialize(data: { port: MessagePort, resolvedConfig: SerializedUserConfig }) {
|
|
41
|
+
loaderPort = data.port;
|
|
42
|
+
resolvedConfig = data.resolvedConfig;
|
|
43
|
+
data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sets the current page being processed.
|
|
48
|
+
* Used to track which CSS files are associated with which pages.
|
|
49
|
+
*
|
|
50
|
+
* @param page - The URL of the current page, or null if no page is active
|
|
51
|
+
*/
|
|
52
|
+
export function setCurrentPage(page: string | null) {
|
|
53
|
+
currentPage = page;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves all CSS files associated with a specific page.
|
|
58
|
+
*
|
|
59
|
+
* @param page - The URL of the page
|
|
60
|
+
* @returns An array of CSS file paths used by the page
|
|
61
|
+
*/
|
|
62
|
+
export function getCssFilesForPage(page: string): string[] {
|
|
63
|
+
return Array.from(cssFilesByPage.get(page) || []);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Processes a CSS file request.
|
|
68
|
+
* Sends a request to the main thread and waits for the processed CSS.
|
|
69
|
+
*
|
|
70
|
+
* @param filePath - The file system path of the CSS file
|
|
71
|
+
* @param config - The Vite config
|
|
72
|
+
* @returns A promise that resolves to the processed CSS content
|
|
73
|
+
*/
|
|
74
|
+
async function processCssFile(
|
|
75
|
+
filePath: string,
|
|
76
|
+
config: ResolvedConfig,
|
|
77
|
+
inline: boolean
|
|
78
|
+
): Promise<{ format: string; source: string; shortCircuit: boolean }> {
|
|
79
|
+
try {
|
|
80
|
+
// Convert file URL to path if needed
|
|
81
|
+
const path = filePath.startsWith("file://")
|
|
82
|
+
? fileURLToPath(filePath)
|
|
83
|
+
: filePath;
|
|
84
|
+
|
|
85
|
+
// Process CSS using Vite's preprocessCSS
|
|
86
|
+
const source = await readFile(path, "utf-8");
|
|
87
|
+
const processed = await preprocessCSS(source, path, {
|
|
88
|
+
...config,
|
|
89
|
+
env: env
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// If we're processing CSS for a specific page, notify the message handler
|
|
93
|
+
if (loaderPort) {
|
|
94
|
+
loaderPort.postMessage({
|
|
95
|
+
type: "CSS_FILE",
|
|
96
|
+
id: currentPage ? join(path, "?page=" + currentPage) : path,
|
|
97
|
+
path: path,
|
|
98
|
+
content: processed.code,
|
|
99
|
+
modules: processed.modules || {},
|
|
100
|
+
inline,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Return a module that can be used by React components
|
|
105
|
+
if (inline) {
|
|
106
|
+
return {
|
|
107
|
+
format: "module",
|
|
108
|
+
source: processed.code,
|
|
109
|
+
shortCircuit: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
format: "module",
|
|
114
|
+
source: `export default ${JSON.stringify(processed.modules || {})};`,
|
|
115
|
+
shortCircuit: true,
|
|
116
|
+
};
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.error(`[css-loader] Error processing CSS file: ${error}`);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Vite's load hook implementation for CSS files.
|
|
125
|
+
* Handles CSS file loading requests and returns a placeholder module.
|
|
126
|
+
* The actual CSS content is processed in the main thread.
|
|
127
|
+
*
|
|
128
|
+
* @param url - The URL of the module to load
|
|
129
|
+
* @param context - The load hook context
|
|
130
|
+
* @param defaultLoad - The default load function
|
|
131
|
+
* @returns A promise that resolves to the module content
|
|
132
|
+
*/
|
|
133
|
+
export async function load(
|
|
134
|
+
url: string,
|
|
135
|
+
context: LoadHookContext & LoaderContext & { resolvedConfig: SerializedUserConfig },
|
|
136
|
+
defaultLoad: any
|
|
137
|
+
) {
|
|
138
|
+
const [name, query] = url.split("?");
|
|
139
|
+
if (name.endsWith(".css")) {
|
|
140
|
+
return processCssFile(url, resolvedConfig as ResolvedConfig, query === "inline");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return defaultLoad(url, context, defaultLoad);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Vite's resolve hook implementation.
|
|
148
|
+
* Handles module resolution during development.
|
|
149
|
+
*
|
|
150
|
+
* @param specifier - The module specifier to resolve
|
|
151
|
+
* @param context - The resolve hook context
|
|
152
|
+
* @param defaultResolve - The default resolve function
|
|
153
|
+
* @returns A promise that resolves to the resolved module
|
|
154
|
+
*/
|
|
155
|
+
export function resolve(specifier: string, context: any, defaultResolve: any) {
|
|
156
|
+
return defaultResolve(specifier, context, defaultResolve);
|
|
157
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { MessagePort } from "node:worker_threads";
|
|
2
|
+
import type { LoadHookContext } from "node:module";
|
|
3
|
+
import type { LoaderContext } from "../types.js";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Global port for communication between the main thread and the CSS loader.
|
|
9
|
+
* This port is used to send CSS file requests and receive responses.
|
|
10
|
+
*/
|
|
11
|
+
export let loaderPort: MessagePort | undefined;
|
|
12
|
+
|
|
13
|
+
let stashedCssFiles = new Map();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the CSS loader with the necessary communication channels.
|
|
17
|
+
* Sets up message handlers for CSS file requests and responses.
|
|
18
|
+
*
|
|
19
|
+
* @param data - Configuration data for the CSS loader
|
|
20
|
+
* @param data.port - The message port for communication
|
|
21
|
+
* @param data.server - The Vite dev server instance
|
|
22
|
+
*/
|
|
23
|
+
export async function initialize(data: { port: MessagePort }) {
|
|
24
|
+
loaderPort = data.port;
|
|
25
|
+
data.port.postMessage({ type: "INITIALIZED_CSS_LOADER" });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Processes a CSS file request.
|
|
30
|
+
* Sends a request to the main thread and waits for the processed CSS.
|
|
31
|
+
*
|
|
32
|
+
* @param filePath - The file system path of the CSS file
|
|
33
|
+
* @param config - The Vite config
|
|
34
|
+
* @returns A promise that resolves to the processed CSS content
|
|
35
|
+
*/
|
|
36
|
+
async function processCssFile(
|
|
37
|
+
filePath: string
|
|
38
|
+
): Promise<{ format: string; source: string; shortCircuit: boolean }> {
|
|
39
|
+
try {
|
|
40
|
+
// Convert file URL to path if needed
|
|
41
|
+
const path = filePath.startsWith("file://")
|
|
42
|
+
? fileURLToPath(filePath)
|
|
43
|
+
: filePath;
|
|
44
|
+
if (stashedCssFiles.has(filePath)) {
|
|
45
|
+
return {
|
|
46
|
+
format: "module",
|
|
47
|
+
source: stashedCssFiles.get(filePath),
|
|
48
|
+
shortCircuit: true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Process CSS using Vite's preprocessCSS
|
|
52
|
+
const source = await readFile(path, "utf-8");
|
|
53
|
+
stashedCssFiles.set(path, source);
|
|
54
|
+
return {
|
|
55
|
+
format: "module",
|
|
56
|
+
source: source,
|
|
57
|
+
shortCircuit: true,
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Vite's load hook implementation for CSS files.
|
|
66
|
+
* Handles CSS file loading requests and returns a placeholder module.
|
|
67
|
+
* The actual CSS content is processed in the main thread.
|
|
68
|
+
*
|
|
69
|
+
* @param url - The URL of the module to load
|
|
70
|
+
* @param context - The load hook context
|
|
71
|
+
* @param defaultLoad - The default load function
|
|
72
|
+
* @returns A promise that resolves to the module content
|
|
73
|
+
*/
|
|
74
|
+
export async function load(
|
|
75
|
+
url: string,
|
|
76
|
+
context: LoadHookContext & LoaderContext,
|
|
77
|
+
defaultLoad: any
|
|
78
|
+
) {
|
|
79
|
+
// Handle CSS files
|
|
80
|
+
const [name] = url.split("?");
|
|
81
|
+
if (name.endsWith(".css")) {
|
|
82
|
+
return processCssFile(url);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return defaultLoad(url, context, defaultLoad);
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { reactLoaderPlugin } from "./plugin.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveOptions } from "../config/resolveOptions.js";
|
|
2
|
+
import type {
|
|
3
|
+
StreamPluginOptions,
|
|
4
|
+
} from "../types.js";
|
|
5
|
+
import type { Plugin } from "vite";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Plugin for loading various front-end react files like css-loader, react-loader, etc.
|
|
9
|
+
*
|
|
10
|
+
* Core responsibilities:
|
|
11
|
+
* 1. Use the load hook to use the appropriate loader for the file type
|
|
12
|
+
* 2. When used, we can assume that such files work the same as when used as node loader
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* export default defineConfig({
|
|
17
|
+
* plugins: [
|
|
18
|
+
* reactLoaderPlugin({
|
|
19
|
+
* projectRoot: process.cwd(),
|
|
20
|
+
* })
|
|
21
|
+
* ]
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export function reactLoaderPlugin(options: StreamPluginOptions): Plugin {
|
|
27
|
+
const resolvedOptionsResult = resolveOptions(options);
|
|
28
|
+
if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
name: "vite:react-loader",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
type LoadHookContext,
|
|
9
9
|
type ResolveHookContext,
|
|
10
10
|
} from "node:module";
|
|
11
|
+
import { workerData } from "node:worker_threads";
|
|
11
12
|
import type { MessagePort } from "node:worker_threads";
|
|
13
|
+
import type { LoaderContext } from "../types.js";
|
|
12
14
|
|
|
13
15
|
let stashedGetSource: any = null;
|
|
14
16
|
let stashedResolve: any = null;
|
|
@@ -19,13 +21,20 @@ setSourceMapsSupport(true, {
|
|
|
19
21
|
generatedCode: true, // Enable for generated code
|
|
20
22
|
});
|
|
21
23
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Get environment variables from workerData or import.meta
|
|
25
|
+
const env = workerData?.importMeta?.env ||
|
|
26
|
+
import.meta?.env || {
|
|
27
|
+
BASE_URL: "/",
|
|
28
|
+
DEV: false,
|
|
29
|
+
MODE: "production",
|
|
30
|
+
PROD: true,
|
|
31
|
+
SSR: true,
|
|
32
|
+
};
|
|
26
33
|
|
|
27
34
|
// Store port globally for use in load hook
|
|
28
|
-
let loaderPort: MessagePort | undefined;
|
|
35
|
+
export let loaderPort: MessagePort | undefined;
|
|
36
|
+
// during development, we actually just want to be explicit about the .node extension
|
|
37
|
+
let isDev = process.env["NODE_ENV"] === "development";
|
|
29
38
|
|
|
30
39
|
export async function getSource(
|
|
31
40
|
url: string,
|
|
@@ -353,9 +362,13 @@ function transformServerModule(
|
|
|
353
362
|
}
|
|
354
363
|
}
|
|
355
364
|
|
|
356
|
-
newSrc
|
|
357
|
-
newSrc +=
|
|
358
|
-
|
|
365
|
+
newSrc = "";
|
|
366
|
+
newSrc += `import ReactDOMServerESM from "react-server-dom-esm/server${
|
|
367
|
+
isDev ? ".node" : ""
|
|
368
|
+
}";\n`;
|
|
369
|
+
// include stack trace where module is imported from
|
|
370
|
+
newSrc += `if(ReactDOMServerESM instanceof Error){ throw ReactDOMServerESM; }`;
|
|
371
|
+
newSrc += `export const registerServerReference = ReactDOMServerESM.registerServerReference;\n`;
|
|
359
372
|
|
|
360
373
|
if (mappings) {
|
|
361
374
|
mappings += ";;";
|
|
@@ -564,14 +577,16 @@ async function transformClientModule(
|
|
|
564
577
|
const names: any[] = [];
|
|
565
578
|
await parseExportNamesInto(body, names, url, loader);
|
|
566
579
|
|
|
567
|
-
|
|
568
580
|
if (names.length === 0) {
|
|
569
|
-
|
|
570
|
-
return "";
|
|
581
|
+
return null;
|
|
571
582
|
}
|
|
572
583
|
|
|
573
|
-
let newSrc =
|
|
574
|
-
|
|
584
|
+
let newSrc = `import ReactDOMServerESM from "react-server-dom-esm/server${
|
|
585
|
+
isDev ? ".node" : ""
|
|
586
|
+
}";\n`;
|
|
587
|
+
// check if the module is poisoned
|
|
588
|
+
newSrc += `if(ReactDOMServerESM instanceof Error){ throw new Error(ReactDOMServerESM); }`;
|
|
589
|
+
newSrc += `export const registerClientReference = ReactDOMServerESM.registerClientReference;\n`;
|
|
575
590
|
|
|
576
591
|
for (let i = 0; i < names.length; i++) {
|
|
577
592
|
const name = names[i];
|
|
@@ -685,13 +700,7 @@ export async function transformModuleIfNeeded(
|
|
|
685
700
|
|
|
686
701
|
if (node.directive === "use client") {
|
|
687
702
|
useClient = true;
|
|
688
|
-
|
|
689
|
-
port.postMessage({
|
|
690
|
-
type: "CLIENT_COMPONENT",
|
|
691
|
-
url,
|
|
692
|
-
source,
|
|
693
|
-
});
|
|
694
|
-
}
|
|
703
|
+
|
|
695
704
|
break;
|
|
696
705
|
}
|
|
697
706
|
if (node.directive === "use server") {
|
|
@@ -699,14 +708,19 @@ export async function transformModuleIfNeeded(
|
|
|
699
708
|
break;
|
|
700
709
|
}
|
|
701
710
|
}
|
|
711
|
+
if (useClient && useServer) {
|
|
712
|
+
throw new Error(
|
|
713
|
+
"Cannot use both use client and use server directives in the same module"
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
if (!useClient && !useServer) {
|
|
717
|
+
return source;
|
|
718
|
+
}
|
|
702
719
|
|
|
703
720
|
if (useClient) {
|
|
704
721
|
return transformClientModule(program, url, undefined, loader);
|
|
705
|
-
} else if (useServer) {
|
|
706
|
-
return transformServerModule(source, program, url, undefined, loader, port);
|
|
707
722
|
}
|
|
708
|
-
|
|
709
|
-
return source;
|
|
723
|
+
return transformServerModule(source, program, url, undefined, loader, port);
|
|
710
724
|
}
|
|
711
725
|
|
|
712
726
|
function readMappings(
|
|
@@ -881,7 +895,7 @@ function decodeVLQ(str: string): number[] {
|
|
|
881
895
|
// Initialize hook
|
|
882
896
|
export async function initialize(data: { port: MessagePort }) {
|
|
883
897
|
loaderPort = data.port; // Store port
|
|
884
|
-
data.port.postMessage({ type: "
|
|
898
|
+
data.port.postMessage({ type: "INITIALIZED_REACT_LOADER" });
|
|
885
899
|
data.port.unref();
|
|
886
900
|
}
|
|
887
901
|
|
|
@@ -900,17 +914,62 @@ export async function load(
|
|
|
900
914
|
context: LoadHookContext & LoaderContext,
|
|
901
915
|
nextLoad: any
|
|
902
916
|
) {
|
|
903
|
-
const result = await nextLoad(url,
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
917
|
+
const result = await nextLoad(url, {
|
|
918
|
+
...context,
|
|
919
|
+
env: env,
|
|
920
|
+
});
|
|
921
|
+
|
|
922
|
+
// If not a module, return as is
|
|
923
|
+
if (result.format !== "module") {
|
|
924
|
+
return result;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// Convert source to string if it's a Buffer or Uint8Array
|
|
928
|
+
let sourceStr: string;
|
|
929
|
+
if (typeof result.source === "string") {
|
|
930
|
+
sourceStr = result.source;
|
|
931
|
+
} else if (
|
|
932
|
+
result.source instanceof Uint8Array ||
|
|
933
|
+
Buffer.isBuffer(result.source)
|
|
934
|
+
) {
|
|
935
|
+
sourceStr = result.source.toString("utf-8");
|
|
936
|
+
} else {
|
|
937
|
+
console.warn(
|
|
938
|
+
`[react-loader] Unexpected source type: ${typeof result.source}`
|
|
939
|
+
);
|
|
940
|
+
return result;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// Transform the module if needed
|
|
944
|
+
const transformResult = await transformModuleIfNeeded(
|
|
945
|
+
sourceStr,
|
|
946
|
+
url,
|
|
947
|
+
nextLoad,
|
|
948
|
+
loaderPort ?? undefined
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
// Handle different return types from transformModuleIfNeeded
|
|
952
|
+
if (transformResult === null) {
|
|
953
|
+
return result;
|
|
954
|
+
} else if (typeof transformResult === "string") {
|
|
955
|
+
return { ...result, source: transformResult };
|
|
956
|
+
} else if (typeof transformResult === "object") {
|
|
957
|
+
// Type assertion for object with code and map properties
|
|
958
|
+
const typedResult = transformResult as { code: string; map?: any };
|
|
959
|
+
if (!("code" in typedResult)) {
|
|
960
|
+
throw new Error("Failed to transform module");
|
|
961
|
+
}
|
|
962
|
+
return {
|
|
963
|
+
...result,
|
|
964
|
+
source: typedResult.code,
|
|
965
|
+
map: typedResult.map || result.map,
|
|
966
|
+
};
|
|
967
|
+
} else {
|
|
968
|
+
console.warn(
|
|
969
|
+
`[react-loader] Unexpected transform result type: ${typeof transformResult}`
|
|
910
970
|
);
|
|
911
|
-
return
|
|
971
|
+
return result;
|
|
912
972
|
}
|
|
913
|
-
return result;
|
|
914
973
|
}
|
|
915
974
|
|
|
916
975
|
// Transform hook
|
|
@@ -924,18 +983,27 @@ export async function transformSource(
|
|
|
924
983
|
context,
|
|
925
984
|
defaultTransformSource
|
|
926
985
|
);
|
|
927
|
-
|
|
928
986
|
if (context.format === "module") {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
987
|
+
// Convert transformedSource to string if it's a Buffer or Uint8Array
|
|
988
|
+
let transformedSourceStr: string;
|
|
989
|
+
if (typeof transformed.source === "string") {
|
|
990
|
+
transformedSourceStr = transformed.source;
|
|
991
|
+
} else if (
|
|
992
|
+
transformed.source instanceof Uint8Array ||
|
|
993
|
+
Buffer.isBuffer(transformed.source)
|
|
994
|
+
) {
|
|
995
|
+
transformedSourceStr = transformed.source.toString("utf-8");
|
|
996
|
+
} else {
|
|
997
|
+
console.warn(
|
|
998
|
+
`[react-loader] Unexpected transformed source type: ${typeof transformed.source}`
|
|
999
|
+
);
|
|
1000
|
+
return transformed;
|
|
932
1001
|
}
|
|
933
1002
|
|
|
934
1003
|
const newSrc = await transformModuleIfNeeded(
|
|
935
|
-
|
|
1004
|
+
transformedSourceStr,
|
|
936
1005
|
context.url,
|
|
937
|
-
(url: string) =>
|
|
938
|
-
loadClientImport(url, defaultTransformSource),
|
|
1006
|
+
(url: string) => loadClientImport(url, defaultTransformSource),
|
|
939
1007
|
context.data?.port!
|
|
940
1008
|
);
|
|
941
1009
|
return { source: newSrc };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Create a shared map to store module references
|
|
2
|
+
export const moduleRefs = new Map<string, { id: string }>();
|
|
3
|
+
|
|
4
|
+
export function getModuleRef(id: string): { id: string } {
|
|
5
|
+
let moduleRef = moduleRefs.get(id);
|
|
6
|
+
if (!moduleRef) {
|
|
7
|
+
moduleRef = { id };
|
|
8
|
+
moduleRefs.set(id, moduleRef);
|
|
9
|
+
}
|
|
10
|
+
return moduleRef;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
2
|
+
import { reactTransformPlugin } from "./transformer/plugin.client.js";
|
|
3
|
+
import type { StreamPluginOptions } from "../types.js";
|
|
4
|
+
import { reactClientPlugin } from "./react-client/plugin.js";
|
|
5
|
+
|
|
6
|
+
export function vitePluginReactServer(options = {} as StreamPluginOptions): import("vite").Plugin[] {
|
|
7
|
+
return [
|
|
8
|
+
reactClientPlugin(options),
|
|
9
|
+
reactTransformPlugin(options),
|
|
10
|
+
reactPreservePlugin(options),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { reactPreservePlugin } from "./preserver/plugin.js";
|
|
2
|
+
import { reactStaticPlugin } from "./react-static/plugin.js";
|
|
3
|
+
import { reactTransformPlugin } from "./transformer/plugin.server.js";
|
|
4
|
+
import type { StreamPluginOptions } from "./types.js";
|
|
5
|
+
import { reactServerPlugin } from "./react-server/plugin.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export function vitePluginReactServer(
|
|
9
|
+
options = {} as StreamPluginOptions
|
|
10
|
+
): import("vite").Plugin[] {
|
|
11
|
+
if(!options.build?.pages || (Array.isArray(options.build.pages) && options.build.pages.length === 0)) {
|
|
12
|
+
// in this case we do not need the static plugin at all
|
|
13
|
+
return [
|
|
14
|
+
reactTransformPlugin(options),
|
|
15
|
+
reactServerPlugin(options),
|
|
16
|
+
reactPreservePlugin(options),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
return [
|
|
20
|
+
reactTransformPlugin(options),
|
|
21
|
+
reactServerPlugin(options),
|
|
22
|
+
reactStaticPlugin(options),
|
|
23
|
+
reactPreservePlugin(options),
|
|
24
|
+
];
|
|
25
|
+
}
|
package/plugin/plugin.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export { vitePluginReactServer } from "./react-server/index.js";
|
|
7
|
-
// the main plugin is version is the server version, if you want the client version, use the `vite-plugin-react-server/client` import
|
|
8
|
-
// this is because the workflow assumes main thread = react server condition
|
|
9
|
-
assertServerCondition(process);
|
|
1
|
+
import { getCondition } from './config/getCondition.js';
|
|
2
|
+
|
|
3
|
+
const condition = getCondition().slice(6); // remove react-
|
|
4
|
+
|
|
5
|
+
export const { vitePluginReactServer } = await import(`./plugin.${condition}.js`);
|
|
@@ -47,7 +47,7 @@ export function reactPreservePlugin(_options: StreamPluginOptions): import("vite
|
|
|
47
47
|
order: "post", // Ensure this runs last in transform phase
|
|
48
48
|
handler(code: string, id: string) {
|
|
49
49
|
// Skip node_modules and vite files
|
|
50
|
-
if (id.includes("node_modules") || id.includes("vite/dist") || !id.match(DEFAULT_CONFIG.
|
|
50
|
+
if (id.includes("node_modules") || id.includes("vite/dist") || !id.match(DEFAULT_CONFIG.MODULE_EXTENSION)) {
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { reactTransformPlugin } from "../transformer/plugin.js";
|
|
3
|
-
import type { StreamPluginOptions } from "../types.js";
|
|
4
|
-
import { reactClientPlugin } from "./plugin.js";
|
|
5
|
-
|
|
6
|
-
export function vitePluginReactClient(options = {} as StreamPluginOptions): import("vite").Plugin[] {
|
|
7
|
-
return [
|
|
8
|
-
reactClientPlugin(options),
|
|
9
|
-
reactTransformPlugin(options),
|
|
10
|
-
reactPreservePlugin(options),
|
|
11
|
-
];
|
|
12
|
-
}
|
|
1
|
+
export { reactClientPlugin } from "./plugin.js";
|