vite-plugin-react-server 0.3.7 → 0.3.8
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 +1 -1
- package/dist/plugin/components.d.ts +2 -1
- package/dist/plugin/components.d.ts.map +1 -1
- package/dist/plugin/components.js +2 -2
- package/dist/plugin/components.js.map +1 -1
- package/dist/plugin/config/defaults.d.ts +4 -4
- package/dist/plugin/config/defaults.js +4 -4
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +6 -3
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +0 -1
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +2 -4
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +5 -20
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +1 -1
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +1 -2
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +2 -1
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +11 -34
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/resolveProps.d.ts.map +1 -1
- package/dist/plugin/resolveProps.js +0 -1
- package/dist/plugin/resolveProps.js.map +1 -1
- package/dist/plugin/worker/createWorker.js +2 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +3 -9
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugin/components.tsx +2 -2
- package/plugin/config/defaults.ts +4 -4
- package/plugin/config/resolveOptions.ts +35 -12
- package/plugin/config/resolveUserConfig.ts +0 -1
- package/plugin/helpers/inputNormalizer.ts +4 -6
- package/plugin/loader/createBuildLoader.ts +6 -27
- package/plugin/react-server/createHandler.ts +2 -3
- package/plugin/react-server/createRscStream.ts +3 -2
- package/plugin/react-server/plugin.ts +18 -39
- package/plugin/resolveProps.ts +0 -1
- package/plugin/worker/createWorker.ts +2 -2
- package/plugin/worker/html/renderPages.ts +4 -10
- package/scripts/check-react-version.mjs +0 -0
|
@@ -18,7 +18,7 @@ import { resolvePages } from "../config/resolvePages.js";
|
|
|
18
18
|
import { resolveUserConfig } from "../config/resolveUserConfig.js";
|
|
19
19
|
import { getModuleManifest } from "../helpers/getModuleManifest.js";
|
|
20
20
|
import { tryManifest } from "../helpers/tryManifest.js";
|
|
21
|
-
import { createBuildLoader } from
|
|
21
|
+
import { createBuildLoader } from "../loader/createBuildLoader.js";
|
|
22
22
|
import type {
|
|
23
23
|
BuildTiming,
|
|
24
24
|
CheckFilesExistReturn,
|
|
@@ -33,7 +33,10 @@ import { createHandler } from "./createHandler.js";
|
|
|
33
33
|
|
|
34
34
|
export function reactServerPlugin(
|
|
35
35
|
options: StreamPluginOptions
|
|
36
|
-
): import("vite").Plugin<{
|
|
36
|
+
): import("vite").Plugin<{
|
|
37
|
+
meta: ReactStreamPluginMeta;
|
|
38
|
+
addCssFile: (path: string) => void;
|
|
39
|
+
}> {
|
|
37
40
|
const timing: BuildTiming = {
|
|
38
41
|
start: performance.now(),
|
|
39
42
|
};
|
|
@@ -195,12 +198,7 @@ export function reactServerPlugin(
|
|
|
195
198
|
});
|
|
196
199
|
},
|
|
197
200
|
async config(config, configEnv): Promise<UserConfig> {
|
|
198
|
-
if (typeof config.root === "string" && config.root !== root) {
|
|
199
|
-
console.log(
|
|
200
|
-
"[vite-plugin-react-server] Root dir changed",
|
|
201
|
-
config.root,
|
|
202
|
-
root
|
|
203
|
-
);
|
|
201
|
+
if (typeof config.root === "string" && config.root !== root && config.root !== process.cwd() && config.root !== "") {
|
|
204
202
|
root = config.root;
|
|
205
203
|
}
|
|
206
204
|
const resolvedPages = await resolvePages(userOptions.build.pages);
|
|
@@ -253,7 +251,7 @@ export function reactServerPlugin(
|
|
|
253
251
|
let htmlWorkerPath = serverManifest["html-worker"]?.file;
|
|
254
252
|
|
|
255
253
|
if (options.htmlWorkerPath) {
|
|
256
|
-
htmlWorkerPath =
|
|
254
|
+
htmlWorkerPath = options.htmlWorkerPath;
|
|
257
255
|
} else {
|
|
258
256
|
htmlWorkerPath = join(
|
|
259
257
|
getPluginRoot(),
|
|
@@ -261,16 +259,9 @@ export function reactServerPlugin(
|
|
|
261
259
|
);
|
|
262
260
|
}
|
|
263
261
|
|
|
264
|
-
// Initialize worker with path from server directory
|
|
265
|
-
const workerPath = resolve(
|
|
266
|
-
root,
|
|
267
|
-
userOptions.build.server,
|
|
268
|
-
htmlWorkerPath
|
|
269
|
-
);
|
|
270
|
-
|
|
271
262
|
worker = await createWorker({
|
|
272
|
-
projectRoot:
|
|
273
|
-
workerPath,
|
|
263
|
+
projectRoot: root,
|
|
264
|
+
workerPath: htmlWorkerPath,
|
|
274
265
|
condition: "react-server",
|
|
275
266
|
reverseCondition: true,
|
|
276
267
|
mode: finalConfig.mode as "production" | "development",
|
|
@@ -283,7 +274,6 @@ export function reactServerPlugin(
|
|
|
283
274
|
throw resolvedPages.error;
|
|
284
275
|
}
|
|
285
276
|
const routes = resolvedPages.pages;
|
|
286
|
-
console.log("[plugin] Routes to render:", routes);
|
|
287
277
|
|
|
288
278
|
const entries = Object.values(serverManifest).filter(
|
|
289
279
|
(entry) => entry.isEntry
|
|
@@ -297,11 +287,16 @@ export function reactServerPlugin(
|
|
|
297
287
|
|
|
298
288
|
const { failedRoutes, completedRoutes } = await renderPages(routes, {
|
|
299
289
|
pipableStreamOptions: {
|
|
300
|
-
bootstrapModules: entries
|
|
290
|
+
bootstrapModules: entries
|
|
291
|
+
.filter((entry) =>
|
|
292
|
+
userOptions.autoDiscover.clientComponents.test(entry.file)
|
|
293
|
+
)
|
|
294
|
+
.filter((t)=> typeof t === "object" && t != null && "file" in t)
|
|
295
|
+
.map((entry) => "/" + entry.file.replace(userOptions.moduleBasePath, "")),
|
|
301
296
|
},
|
|
302
297
|
moduleBasePath: userOptions.moduleBasePath,
|
|
303
298
|
moduleBaseURL: userOptions.moduleBaseURL,
|
|
304
|
-
clientCss: css?.map((css) => "/" + css) ?? [],
|
|
299
|
+
clientCss: css?.filter((css) => typeof css === "string").map((css) => "/" + css.replace(userOptions.moduleBasePath, "")) ?? [],
|
|
305
300
|
userConfig,
|
|
306
301
|
pluginOptions: userOptions,
|
|
307
302
|
worker: worker,
|
|
@@ -309,25 +304,17 @@ export function reactServerPlugin(
|
|
|
309
304
|
loader,
|
|
310
305
|
onCssFile: (path: string) => {
|
|
311
306
|
if (buildCssFiles && path.endsWith(".css")) {
|
|
312
|
-
buildCssFiles.add(path);
|
|
307
|
+
buildCssFiles.add(path.replace(userOptions.moduleBasePath, ""));
|
|
313
308
|
}
|
|
314
309
|
},
|
|
315
310
|
});
|
|
316
311
|
|
|
317
|
-
// Debug render results
|
|
318
|
-
console.log("[vite-plugin-react-server] Render results:", {
|
|
319
|
-
failedRoutes,
|
|
320
|
-
completedRoutes,
|
|
321
|
-
});
|
|
322
|
-
|
|
323
312
|
if (failedRoutes.size) {
|
|
324
313
|
console.error(
|
|
325
314
|
"[vite-plugin-react-server] Failed to render routes:",
|
|
326
315
|
failedRoutes
|
|
327
316
|
);
|
|
328
317
|
}
|
|
329
|
-
console.log("[vite-plugin-react-server] Render complete");
|
|
330
|
-
console.log("[vite-plugin-react-server] Terminating worker");
|
|
331
318
|
if (worker) await worker.terminate();
|
|
332
319
|
|
|
333
320
|
timing.renderEnd = performance.now();
|
|
@@ -438,15 +425,7 @@ export function reactServerPlugin(
|
|
|
438
425
|
};
|
|
439
426
|
|
|
440
427
|
if (chunk.fileName.includes("html-worker")) {
|
|
441
|
-
const workerPath = resolve(
|
|
442
|
-
root,
|
|
443
|
-
userOptions.build.server,
|
|
444
|
-
chunk.fileName
|
|
445
|
-
);
|
|
446
|
-
console.log("Files in output dir:", {
|
|
447
|
-
files: readdirSync(resolve(root, userOptions.build.server)),
|
|
448
|
-
workerPath,
|
|
449
|
-
});
|
|
428
|
+
const workerPath = resolve(root, chunk.fileName);
|
|
450
429
|
|
|
451
430
|
// Don't initialize worker during build phase
|
|
452
431
|
if (finalConfig.command === "build") {
|
package/plugin/resolveProps.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Worker, type ResourceLimits } from "node:worker_threads";
|
|
2
2
|
import { getMode, getNodePath } from "../config/getPaths.js";
|
|
3
3
|
import { getCondition } from "../config/getCondition.js";
|
|
4
|
-
|
|
4
|
+
import { join } from "node:path";
|
|
5
5
|
type CreateWorkerOptions = {
|
|
6
6
|
projectRoot?: string;
|
|
7
7
|
condition?: "react-server" | "react-client";
|
|
@@ -45,7 +45,7 @@ export async function createWorker(options: CreateWorkerOptions) {
|
|
|
45
45
|
const maxRetries = 3;
|
|
46
46
|
for (let tries = 0; tries < maxRetries; tries++) {
|
|
47
47
|
try {
|
|
48
|
-
const worker = new Worker(workerPath, {
|
|
48
|
+
const worker = new Worker(workerPath.startsWith('/') ? workerPath : join(projectRoot, workerPath), {
|
|
49
49
|
env,
|
|
50
50
|
// Increase resource limits for stream handling
|
|
51
51
|
resourceLimits: resourceLimits
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
1
3
|
import { dirname, join, resolve as resolvePath } from "node:path";
|
|
2
4
|
import { Transform } from "node:stream";
|
|
3
5
|
import type { Worker } from "node:worker_threads";
|
|
4
6
|
import { createHandler } from "../../react-server/createHandler.js";
|
|
5
7
|
import type { ResolvedUserConfig, StreamPluginOptions } from "../../types.js";
|
|
6
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
-
import { mkdirSync } from "node:fs";
|
|
8
8
|
|
|
9
9
|
interface PipeableStreamOptions {
|
|
10
10
|
bootstrapModules?: string[];
|
|
@@ -57,10 +57,8 @@ export async function renderPages(
|
|
|
57
57
|
const moduleBaseURL = options.moduleBaseURL;
|
|
58
58
|
const htmlRoot = join(
|
|
59
59
|
options.userConfig.root,
|
|
60
|
-
options.
|
|
60
|
+
options.userConfig.build.outDir
|
|
61
61
|
);
|
|
62
|
-
console.log("[renderPages] HTML root:", htmlRoot);
|
|
63
|
-
|
|
64
62
|
const streamStarted = new Set<string>();
|
|
65
63
|
const completedRoutes = new Set<string>();
|
|
66
64
|
const htmlContent = new Map<string, string>();
|
|
@@ -68,9 +66,7 @@ export async function renderPages(
|
|
|
68
66
|
|
|
69
67
|
// Create a promise that resolves when all routes are complete
|
|
70
68
|
const allRoutesComplete = new Promise<void>((resolve, reject) => {
|
|
71
|
-
|
|
72
|
-
reject(new Error(`Render timeout - Started: ${streamStarted.size}, Completed: ${completedRoutes.size}`));
|
|
73
|
-
}, 5000);
|
|
69
|
+
|
|
74
70
|
|
|
75
71
|
options.worker.on("message", function messageHandler(msg: any) {
|
|
76
72
|
switch (msg.type) {
|
|
@@ -87,7 +83,6 @@ export async function renderPages(
|
|
|
87
83
|
|
|
88
84
|
if (completedRoutes.size === routes.length) {
|
|
89
85
|
options.worker.removeListener("message", messageHandler);
|
|
90
|
-
clearTimeout(timeout);
|
|
91
86
|
|
|
92
87
|
// Write all HTML files
|
|
93
88
|
for (const [route, html] of htmlContent) {
|
|
@@ -124,7 +119,6 @@ export async function renderPages(
|
|
|
124
119
|
await mkdir(htmlRoot, { recursive: true });
|
|
125
120
|
|
|
126
121
|
const renderPromises = routes.map(async (route) => {
|
|
127
|
-
console.log("[renderPages] Processing route:", route);
|
|
128
122
|
|
|
129
123
|
try {
|
|
130
124
|
const result = await createHandler(route, options.pluginOptions, {
|
|
File without changes
|