vite-plugin-react-server 1.4.2 → 1.4.4
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 +48 -313
- package/dist/package.json +123 -13
- package/dist/plugin/bundle/deferredStaticGeneration.js +14 -39
- package/dist/plugin/bundle/manifests.js +30 -48
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +4 -1
- package/dist/plugin/config/envPrefixFromConfig.js +12 -7
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.js +7 -5
- package/dist/plugin/dev-server/virtualRscHmrPlugin.js +23 -23
- package/dist/plugin/environments/createBuildEventPlugin.js +88 -98
- package/dist/plugin/environments/createEnvironmentPlugin.js +222 -250
- package/dist/plugin/helpers/createRscRenderHelpers.js +33 -34
- package/dist/plugin/helpers/createSharedLoader.d.ts.map +1 -1
- package/dist/plugin/helpers/createSharedLoader.js +4 -2
- package/dist/plugin/helpers/headlessStreamReuseHandler.js +30 -22
- package/dist/plugin/helpers/headlessStreamState.js +15 -28
- package/dist/plugin/helpers/resolveComponent.d.ts.map +1 -1
- package/dist/plugin/helpers/resolveComponent.js +4 -2
- package/dist/plugin/index.client.d.ts +5 -0
- package/dist/plugin/index.client.d.ts.map +1 -0
- package/dist/plugin/index.client.js +4 -0
- package/dist/plugin/index.d.ts +4 -3
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +10 -5
- package/dist/plugin/index.server.d.ts +5 -0
- package/dist/plugin/index.server.d.ts.map +1 -0
- package/dist/plugin/index.server.js +4 -0
- package/dist/plugin/metrics/createWorkerStartupMetrics.js +31 -13
- package/dist/plugin/orchestrator/createPluginOrchestrator.client.js +41 -38
- package/dist/plugin/orchestrator/createPluginOrchestrator.server.js +43 -46
- package/dist/plugin/plugin.client.js +2 -2
- package/dist/plugin/plugin.server.js +2 -2
- package/dist/plugin/react-static/createBuildLoader.client.js +12 -6
- package/dist/plugin/react-static/createBuildLoader.server.js +255 -235
- package/dist/plugin/react-static/plugin.client.js +684 -770
- package/dist/plugin/react-static/plugin.server.js +517 -603
- package/dist/plugin/react-static/processCssFilesForPages.js +103 -88
- package/dist/plugin/react-static/renderPage.client.js +455 -529
- package/dist/plugin/react-static/renderPage.server.js +485 -508
- package/dist/plugin/react-static/renderPagesBatched.js +277 -275
- package/dist/plugin/react-static/rscToHtmlStream.client.js +48 -29
- package/dist/plugin/react-static/rscToHtmlStream.server.js +62 -37
- package/dist/plugin/react-static/temporaryReferences.server.js +11 -2
- package/dist/plugin/stream/createMainThreadHandlers.js +40 -31
- package/dist/plugin/stream/renderRscStream.server.d.ts.map +1 -1
- package/dist/plugin/stream/renderRscStream.server.js +127 -144
- package/dist/plugin/transformer/createTransformerPlugin.js +226 -265
- package/dist/plugin/utils/checkReactVersion.d.ts +7 -0
- package/dist/plugin/utils/checkReactVersion.d.ts.map +1 -0
- package/dist/plugin/utils/checkReactVersion.js +23 -0
- package/dist/plugin/utils/envUrls.node.js +12 -11
- package/dist/plugin/vendor/vendor-alias.js +84 -114
- package/dist/plugin/vendor/vendor.client.d.ts.map +1 -1
- package/dist/plugin/vendor/vendor.client.js +1 -3
- package/dist/plugin/worker/rsc/handleRscRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRscRender.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +123 -13
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +4 -0
- package/plugin/config/getCondition.ts +6 -4
- package/plugin/helpers/createRscRenderHelpers.ts +1 -1
- package/plugin/helpers/createSharedLoader.ts +6 -1
- package/plugin/helpers/resolveComponent.ts +6 -1
- package/plugin/index.client.ts +4 -0
- package/plugin/index.server.ts +4 -0
- package/plugin/index.ts +12 -5
- package/plugin/plugin.client.ts +1 -1
- package/plugin/plugin.server.ts +1 -1
- package/plugin/stream/renderRscStream.server.ts +3 -0
- package/plugin/utils/checkReactVersion.ts +28 -0
- package/plugin/vendor/vendor.client.ts +0 -2
- package/plugin/worker/rsc/handleRscRender.ts +2 -0
- package/scripts/generate-toc.mjs +27 -294
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Vite plugin for React Server Components (RSC)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin/index.js",
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
"default": "./dist/plugin/utils/index.server.js"
|
|
41
41
|
},
|
|
42
42
|
"./metrics": "./dist/plugin/metrics/index.js",
|
|
43
|
-
"./stream":
|
|
43
|
+
"./stream": {
|
|
44
|
+
"react-server": "./dist/plugin/stream/index.server.js",
|
|
45
|
+
"default": "./dist/plugin/stream/index.client.js"
|
|
46
|
+
},
|
|
44
47
|
"./stream/client": "./dist/plugin/stream/index.client.js",
|
|
45
48
|
"./stream/server": "./dist/plugin/stream/index.server.js",
|
|
46
49
|
"./env": {
|
|
@@ -48,25 +51,128 @@
|
|
|
48
51
|
},
|
|
49
52
|
"./config": "./dist/plugin/config/index.js",
|
|
50
53
|
"./error": "./dist/plugin/error/index.js",
|
|
51
|
-
"./vendor":
|
|
54
|
+
"./vendor": {
|
|
55
|
+
"react-server": "./dist/plugin/vendor/vendor.server.js",
|
|
56
|
+
"default": "./dist/plugin/vendor/vendor.client.js"
|
|
57
|
+
},
|
|
52
58
|
"./vendor.server": "./dist/plugin/vendor/vendor.server.js",
|
|
53
59
|
"./vendor.client": "./dist/plugin/vendor/vendor.client.js",
|
|
54
60
|
"./vendor.static": "./dist/plugin/vendor/vendor.static.js",
|
|
55
61
|
"./file-preserver": "./dist/plugin/file-preserver/plugin.js",
|
|
56
62
|
"./loader": "./dist/plugin/loader/index.js",
|
|
57
63
|
"./helpers": "./dist/plugin/helpers/index.js",
|
|
58
|
-
"./helpers/resolveStreamElements":
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"./
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
"./helpers/resolveStreamElements": {
|
|
65
|
+
"react-server": "./dist/plugin/helpers/resolveStreamElements.server.js",
|
|
66
|
+
"default": "./dist/plugin/helpers/resolveStreamElements.client.js"
|
|
67
|
+
},
|
|
68
|
+
"./dev-server": {
|
|
69
|
+
"react-server": "./dist/plugin/dev-server/index.server.js",
|
|
70
|
+
"default": "./dist/plugin/dev-server/index.client.js"
|
|
71
|
+
},
|
|
72
|
+
"./dev-server/configureReactServer": {
|
|
73
|
+
"react-server": "./dist/plugin/dev-server/configureReactServer.server.js",
|
|
74
|
+
"default": "./dist/plugin/dev-server/configureReactServer.client.js"
|
|
75
|
+
},
|
|
76
|
+
"./dev-server/handleServerAction": {
|
|
77
|
+
"react-server": "./dist/plugin/dev-server/handleServerAction.server.js",
|
|
78
|
+
"default": "./dist/plugin/dev-server/handleServerAction.client.js"
|
|
79
|
+
},
|
|
80
|
+
"./stream/handleRscStream": {
|
|
81
|
+
"react-server": "./dist/plugin/stream/handleRscStream.server.js",
|
|
82
|
+
"default": "./dist/plugin/stream/handleRscStream.client.js"
|
|
83
|
+
},
|
|
84
|
+
"./stream/createRscStream": {
|
|
85
|
+
"react-server": "./dist/plugin/stream/createRscStream.server.js",
|
|
86
|
+
"default": "./dist/plugin/stream/createRscStream.client.js"
|
|
87
|
+
},
|
|
88
|
+
"./dev-server/restartWorker": {
|
|
89
|
+
"react-server": "./dist/plugin/dev-server/restartWorker.server.js",
|
|
90
|
+
"default": "./dist/plugin/dev-server/restartWorker.client.js"
|
|
91
|
+
},
|
|
92
|
+
"./dev-server/cleanupServerAction": {
|
|
93
|
+
"react-server": "./dist/plugin/dev-server/cleanupServerAction.server.js",
|
|
94
|
+
"default": "./dist/plugin/dev-server/cleanupServerAction.client.js"
|
|
95
|
+
},
|
|
66
96
|
"./env-loader": "./dist/plugin/loader/env-loader.js",
|
|
67
97
|
"./css-loader": "./dist/plugin/loader/css-loader.js",
|
|
68
98
|
"./directives": "./dist/plugin/loader/directives/index.js",
|
|
69
|
-
"./register": "./dist/plugin/vendor/register-vendor.js"
|
|
99
|
+
"./register": "./dist/plugin/vendor/register-vendor.js",
|
|
100
|
+
"./config/createHandlerOptions": {
|
|
101
|
+
"react-server": "./dist/plugin/config/createHandlerOptions.server.js",
|
|
102
|
+
"default": "./dist/plugin/config/createHandlerOptions.client.js"
|
|
103
|
+
},
|
|
104
|
+
"./dev-server/configureRequestHandler": {
|
|
105
|
+
"react-server": "./dist/plugin/dev-server/configureRequestHandler.server.js",
|
|
106
|
+
"default": "./dist/plugin/dev-server/configureRequestHandler.client.js"
|
|
107
|
+
},
|
|
108
|
+
"./env/plugin": {
|
|
109
|
+
"react-server": "./dist/plugin/env/plugin.server.js",
|
|
110
|
+
"default": "./dist/plugin/env/plugin.client.js"
|
|
111
|
+
},
|
|
112
|
+
"./helpers/handleServerAction": {
|
|
113
|
+
"react-server": "./dist/plugin/helpers/handleServerAction.server.js",
|
|
114
|
+
"default": "./dist/plugin/helpers/handleServerAction.client.js"
|
|
115
|
+
},
|
|
116
|
+
"./orchestrator/createPluginOrchestrator": {
|
|
117
|
+
"react-server": "./dist/plugin/orchestrator/createPluginOrchestrator.server.js",
|
|
118
|
+
"default": "./dist/plugin/orchestrator/createPluginOrchestrator.client.js"
|
|
119
|
+
},
|
|
120
|
+
"./plugin": {
|
|
121
|
+
"react-server": "./dist/plugin/plugin.server.js",
|
|
122
|
+
"default": "./dist/plugin/plugin.client.js"
|
|
123
|
+
},
|
|
124
|
+
"./react-client": {
|
|
125
|
+
"react-server": "./dist/plugin/react-client/index.server.js",
|
|
126
|
+
"default": "./dist/plugin/react-client/index.client.js"
|
|
127
|
+
},
|
|
128
|
+
"./react-client/plugin": {
|
|
129
|
+
"react-server": "./dist/plugin/react-client/plugin.server.js",
|
|
130
|
+
"default": "./dist/plugin/react-client/plugin.client.js"
|
|
131
|
+
},
|
|
132
|
+
"./react-server/plugin": {
|
|
133
|
+
"react-server": "./dist/plugin/react-server/plugin.server.js",
|
|
134
|
+
"default": "./dist/plugin/react-server/plugin.client.js"
|
|
135
|
+
},
|
|
136
|
+
"./react-static/createBuildLoader": {
|
|
137
|
+
"react-server": "./dist/plugin/react-static/createBuildLoader.server.js",
|
|
138
|
+
"default": "./dist/plugin/react-static/createBuildLoader.client.js"
|
|
139
|
+
},
|
|
140
|
+
"./react-static": {
|
|
141
|
+
"react-server": "./dist/plugin/react-static/index.server.js",
|
|
142
|
+
"default": "./dist/plugin/react-static/index.client.js"
|
|
143
|
+
},
|
|
144
|
+
"./react-static/plugin": {
|
|
145
|
+
"react-server": "./dist/plugin/react-static/plugin.server.js",
|
|
146
|
+
"default": "./dist/plugin/react-static/plugin.client.js"
|
|
147
|
+
},
|
|
148
|
+
"./react-static/renderPage": {
|
|
149
|
+
"react-server": "./dist/plugin/react-static/renderPage.server.js",
|
|
150
|
+
"default": "./dist/plugin/react-static/renderPage.client.js"
|
|
151
|
+
},
|
|
152
|
+
"./react-static/rscToHtmlStream": {
|
|
153
|
+
"react-server": "./dist/plugin/react-static/rscToHtmlStream.server.js",
|
|
154
|
+
"default": "./dist/plugin/react-static/rscToHtmlStream.client.js"
|
|
155
|
+
},
|
|
156
|
+
"./react-static/temporaryReferences": {
|
|
157
|
+
"react-server": "./dist/plugin/react-static/temporaryReferences.server.js",
|
|
158
|
+
"default": "./dist/plugin/react-static/temporaryReferences.client.js"
|
|
159
|
+
},
|
|
160
|
+
"./stream/createFromNodeStream": {
|
|
161
|
+
"react-server": "./dist/plugin/stream/createFromNodeStream.server.js",
|
|
162
|
+
"default": "./dist/plugin/stream/createFromNodeStream.client.js"
|
|
163
|
+
},
|
|
164
|
+
"./stream/createHtmlStream": {
|
|
165
|
+
"react-server": "./dist/plugin/stream/createHtmlStream.server.js",
|
|
166
|
+
"default": "./dist/plugin/stream/createHtmlStream.client.js"
|
|
167
|
+
},
|
|
168
|
+
"./stream/createRenderToPipeableStreamHandler": {
|
|
169
|
+
"react-server": "./dist/plugin/stream/createRenderToPipeableStreamHandler.server.js",
|
|
170
|
+
"default": "./dist/plugin/stream/createRenderToPipeableStreamHandler.client.js"
|
|
171
|
+
},
|
|
172
|
+
"./transformer/plugin": {
|
|
173
|
+
"react-server": "./dist/plugin/transformer/plugin.server.js",
|
|
174
|
+
"default": "./dist/plugin/transformer/plugin.client.js"
|
|
175
|
+
}
|
|
70
176
|
},
|
|
71
177
|
"typesVersions": {
|
|
72
178
|
"*": {
|
|
@@ -288,7 +394,6 @@
|
|
|
288
394
|
"supports-color": "^10.0.0",
|
|
289
395
|
"ts-node": "^10.9.2",
|
|
290
396
|
"tslib": "^2.8.1",
|
|
291
|
-
"tsx": "^4.19.2",
|
|
292
397
|
"typescript": "^5.7.3",
|
|
293
398
|
"typescript-eslint": "^8.33.1",
|
|
294
399
|
"vite": "^6.3.5",
|
|
@@ -298,5 +403,10 @@
|
|
|
298
403
|
"bin": {
|
|
299
404
|
"check-react-version": "./scripts/check-react-version.mjs",
|
|
300
405
|
"patch": "./bin/patch.mjs"
|
|
406
|
+
},
|
|
407
|
+
"dependencies": {
|
|
408
|
+
"acorn": "^8.16.0",
|
|
409
|
+
"picocolors": "^1.1.1",
|
|
410
|
+
"tsx": "^4.21.0"
|
|
301
411
|
}
|
|
302
412
|
}
|
|
@@ -177,6 +177,10 @@ export const resolveAutoDiscover: ResolveAutoDiscoverFn =
|
|
|
177
177
|
...clientEntry,
|
|
178
178
|
...cssInputs,
|
|
179
179
|
};
|
|
180
|
+
// If no client entries found, fall back to index.html so SSR environment has inputs
|
|
181
|
+
if (Object.keys(clientInputsCollection).length === 0) {
|
|
182
|
+
Object.assign(clientInputsCollection, indexHtmlInputs);
|
|
183
|
+
}
|
|
180
184
|
|
|
181
185
|
const serverInputsCollection = {
|
|
182
186
|
...clientInputsCollection,
|
|
@@ -203,9 +203,10 @@ export function assertReactServer(): asserts this is {
|
|
|
203
203
|
const currentCondition = getCurrentCondition();
|
|
204
204
|
if (currentCondition !== "react-server") {
|
|
205
205
|
// Debug-only: avoid Node-only APIs to keep this file browser-safe
|
|
206
|
-
|
|
207
|
-
`Condition mismatch
|
|
206
|
+
console.warn(
|
|
207
|
+
`[vite-plugin-react-server] Condition mismatch: expected react-server. Set NODE_OPTIONS="--conditions=react-server"`
|
|
208
208
|
);
|
|
209
|
+
return; // Don't throw — Vite 7 may load both condition variants during config bundling
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
|
|
@@ -215,9 +216,10 @@ export function assertNonReactServer(): asserts this is {
|
|
|
215
216
|
const currentCondition = getCurrentCondition();
|
|
216
217
|
if (currentCondition === "react-server") {
|
|
217
218
|
// Debug-only: avoid Node-only APIs to keep this file browser-safe
|
|
218
|
-
|
|
219
|
-
`Condition mismatch
|
|
219
|
+
console.warn(
|
|
220
|
+
`[vite-plugin-react-server] Condition mismatch: unexpected react-server condition on this module.`
|
|
220
221
|
);
|
|
222
|
+
return; // Don't throw — Vite 7 may load both condition variants during config bundling
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
|
|
@@ -38,7 +38,7 @@ export function createReactElement(
|
|
|
38
38
|
|
|
39
39
|
return createElementWithReact(React, {
|
|
40
40
|
...finalOptions,
|
|
41
|
-
|
|
41
|
+
HtmlComponent: isHeadless ? React.Fragment : finalOptions.HtmlComponent,
|
|
42
42
|
as: isHeadless ? React.Fragment : "div",
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -146,7 +146,12 @@ export async function createSharedLoader({
|
|
|
146
146
|
throw new Error(`Module "${moduleId}" has no exports, can't find ${exportName}`);
|
|
147
147
|
}
|
|
148
148
|
if (exportName && !(exportName in result)) {
|
|
149
|
-
throw new Error(
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Module "${moduleId}" does not export "${exportName}". ` +
|
|
151
|
+
(exportName !== 'default'
|
|
152
|
+
? `Did you use \`export default\`? Use \`export function ${exportName}(...)\` or set pageExportName: "default" in your plugin config.`
|
|
153
|
+
: `The module does not have a default export.`)
|
|
154
|
+
);
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
return result;
|
|
@@ -77,7 +77,12 @@ export async function resolveComponent<T = RootComponentType | HtmlComponentType
|
|
|
77
77
|
}
|
|
78
78
|
return {
|
|
79
79
|
type: "error",
|
|
80
|
-
error: new Error(
|
|
80
|
+
error: new Error(
|
|
81
|
+
`Export "${moduleExportName}" not found in module ${modulePath}. ` +
|
|
82
|
+
(moduleExportName !== "default"
|
|
83
|
+
? `Did you use \`export default\`? Use \`export function ${moduleExportName}(...)\` or set pageExportName: "default" in your plugin config.`
|
|
84
|
+
: `The module does not have a default export.`)
|
|
85
|
+
),
|
|
81
86
|
};
|
|
82
87
|
}
|
|
83
88
|
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { vitePluginReactServer } from './plugin.client.js';
|
|
2
|
+
export { vitePluginReactServer as vitePluginReactClient } from './plugin.client.js';
|
|
3
|
+
export { createPluginOrchestrator } from './orchestrator/createPluginOrchestrator.client.js';
|
|
4
|
+
export { getCondition } from './config/getCondition.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { vitePluginReactServer } from './plugin.server.js';
|
|
2
|
+
export { vitePluginReactServer as vitePluginReactClient } from './plugin.server.js';
|
|
3
|
+
export { createPluginOrchestrator } from './orchestrator/createPluginOrchestrator.server.js';
|
|
4
|
+
export { getCondition } from './config/getCondition.js';
|
package/plugin/index.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
// Conditional exports in package.json resolve to index.server.js or index.client.js.
|
|
2
|
+
// This barrel file is kept for backward compat with tools that don't support conditions.
|
|
1
3
|
import { getCondition } from './config/getCondition.js';
|
|
2
|
-
import { pluginRoot } from './root.js';
|
|
3
4
|
import type { VitePluginMainFn } from './types.js';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const condition = getCondition('');
|
|
7
|
+
const dir = new URL('./', import.meta.url).pathname.replace(/\/$/, '');
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
export
|
|
9
|
+
const mod = await import(`${dir}/plugin.${condition}.js`);
|
|
10
|
+
export const vitePluginReactServer: VitePluginMainFn = mod.vitePluginReactServer;
|
|
11
|
+
export const vitePluginReactClient: VitePluginMainFn = mod.vitePluginReactServer;
|
|
12
|
+
|
|
13
|
+
const orch = await import(`${dir}/orchestrator/createPluginOrchestrator.${condition === 'server' ? 'server' : 'client'}.js`);
|
|
14
|
+
export const createPluginOrchestrator = orch.createPluginOrchestrator;
|
|
15
|
+
|
|
16
|
+
export { getCondition } from './config/getCondition.js';
|
package/plugin/plugin.client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { VitePluginMainFn } from "./types.js";
|
|
2
|
-
import { createPluginOrchestrator } from "./orchestrator/createPluginOrchestrator.js";
|
|
2
|
+
import { createPluginOrchestrator } from "./orchestrator/createPluginOrchestrator.client.js";
|
|
3
3
|
import type { UserOptions, Strategy } from "./orchestrator/types.js";
|
|
4
4
|
import { assertNonReactServer } from "./config/getCondition.js";
|
|
5
5
|
|
package/plugin/plugin.server.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { VitePluginMainFn } from "./types.js";
|
|
|
2
2
|
import type { UserOptions, Strategy } from "./orchestrator/types.js";
|
|
3
3
|
|
|
4
4
|
import { assertReactServer } from "./config/getCondition.js";
|
|
5
|
-
import { createPluginOrchestrator } from "./orchestrator/createPluginOrchestrator.js";
|
|
5
|
+
import { createPluginOrchestrator } from "./orchestrator/createPluginOrchestrator.server.js";
|
|
6
6
|
|
|
7
7
|
assertReactServer();
|
|
8
8
|
|
|
@@ -3,6 +3,7 @@ import type { CreateHandlerOptions } from "../types.js";
|
|
|
3
3
|
import type { RscRenderResult } from "./renderRscStream.types.js";
|
|
4
4
|
import { createStreamMetrics } from "../metrics/createStreamMetrics.js";
|
|
5
5
|
import { createReactElement } from "../helpers/createRscRenderHelpers.js";
|
|
6
|
+
import { checkReactExperimental } from "../utils/checkReactVersion.js";
|
|
6
7
|
import { ReactDOMServer } from "../vendor/vendor.server.js";
|
|
7
8
|
import type { StreamHandlers } from "../worker/types.js";
|
|
8
9
|
|
|
@@ -78,6 +79,8 @@ export function renderRscStream(
|
|
|
78
79
|
logger?.info(`[renderRscStream:${route}] Creating React stream for element`);
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
checkReactExperimental();
|
|
83
|
+
|
|
81
84
|
// Render React to stream - let it flow naturally like the RSC worker
|
|
82
85
|
const reactStream = ReactDOMServer.renderToPipeableStream(
|
|
83
86
|
reactElement,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let checked = false;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verify React experimental is available. The vendored react-server-dom-esm
|
|
5
|
+
* transport requires Taint APIs that only exist in React experimental builds.
|
|
6
|
+
* Stable React 19.x causes: "Cannot read properties of undefined (reading 'add')"
|
|
7
|
+
*/
|
|
8
|
+
export function checkReactExperimental() {
|
|
9
|
+
if (checked) return;
|
|
10
|
+
checked = true;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
// Use require for sync access — React is always available at this point
|
|
14
|
+
const version: string = globalThis.process?.versions
|
|
15
|
+
? require("react").version
|
|
16
|
+
: "";
|
|
17
|
+
|
|
18
|
+
if (version && !version.includes("experimental")) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`[vite-plugin-react-server] React ${version} is not supported. ` +
|
|
21
|
+
`This plugin requires React experimental builds. ` +
|
|
22
|
+
`Install with: npm install react@experimental react-dom@experimental`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
} catch (e: unknown) {
|
|
26
|
+
if (e instanceof Error && e.message.includes("not supported")) throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -2,9 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
|
-
import { assertNonReactServer } from "../config/getCondition.js";
|
|
6
5
|
|
|
7
|
-
assertNonReactServer();
|
|
8
6
|
|
|
9
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
8
|
function findPkgRoot(): string {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type RenderToPipeableStreamOptions,
|
|
10
10
|
} from "../../vendor/vendor.server.js";
|
|
11
11
|
import { createElementWithReact } from "../../helpers/createElementWithReact.js";
|
|
12
|
+
import { checkReactExperimental } from "../../utils/checkReactVersion.js";
|
|
12
13
|
/**
|
|
13
14
|
* Handles the rendering of React Server Component streams in the RSC worker thread.
|
|
14
15
|
*
|
|
@@ -261,6 +262,7 @@ export const handleRscRender: HandleRscRenderFn = function _handleRscRender(
|
|
|
261
262
|
);
|
|
262
263
|
}
|
|
263
264
|
|
|
265
|
+
checkReactExperimental();
|
|
264
266
|
const { pipe } = ReactDOMServer.renderToPipeableStream(
|
|
265
267
|
element,
|
|
266
268
|
finalHandlerOptions.moduleBasePath,
|