vite-plugin-react-server 0.3.17 → 0.3.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-server",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "Vite plugin for React Server Components (RSC)",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin/index.js",
@@ -59,7 +59,6 @@ export function collectManifestCss(
59
59
  // Add direct CSS
60
60
  if (entry.css) {
61
61
  entry.css.forEach((css: string) => {
62
- console.log('collectManifestCss', css, entry.src ?? entry.file ?? '');
63
62
  cssFiles.set(entry.src ?? entry.file ?? '', css);
64
63
  onCss?.(css, parentUrl ?? pagePath);
65
64
  });
@@ -146,7 +146,7 @@ export function resolveUserConfig({
146
146
  userConfig: {
147
147
  ...config,
148
148
  root: root,
149
- mode: configEnv.command === "build" ? "production" : "development",
149
+ mode: configEnv.mode ?? configEnv.command === "build" ? "production" : "development",
150
150
  resolve: {
151
151
  external: ["react", "react-dom"],
152
152
  alias: {},
@@ -194,7 +194,7 @@ export function resolveUserConfig({
194
194
  userConfig: {
195
195
  ...config,
196
196
  root: root,
197
- mode: configEnv.command === "build" ? "production" : "development",
197
+ mode: configEnv.mode ?? configEnv.command === "build" ? "production" : "development",
198
198
  resolve: {
199
199
  alias: {},
200
200
  externalConditions: ["react-server"],
@@ -24,6 +24,7 @@ import type {
24
24
  RscWorkerResponse,
25
25
  } from "../worker/types.js";
26
26
  import { createLogger } from "../utils/logger.js";
27
+ import { readFileSync } from "node:fs";
27
28
 
28
29
  const log = createLogger("react-client");
29
30
  let userOptions: ResolvedUserOptions;
@@ -188,6 +189,7 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
188
189
  if (foundClient) {
189
190
  res.setHeader("Content-Type", "application/javascript");
190
191
  res.end(foundClient);
192
+ return;
191
193
  }
192
194
  const foundServer =
193
195
  serverManifest &&
@@ -207,6 +209,21 @@ export function reactClientPlugin(options: StreamPluginOptions): Plugin {
207
209
  next();
208
210
  }
209
211
  } else {
212
+ let html = '';
213
+ try {
214
+ const last = value.split('/').pop();
215
+ if(!last?.includes('.')) {
216
+ const isDir = await stat(join(fileRoot, value));
217
+ if (isDir.isDirectory()) {
218
+ html = readFileSync(join(fileRoot, value, 'index.html'), 'utf-8');
219
+ res.setHeader("Content-Type", "text/html");
220
+ res.end(html);
221
+ return;
222
+ }
223
+ }
224
+ } catch (error) {
225
+
226
+ }
210
227
  next();
211
228
  }
212
229
  });
@@ -21,7 +21,8 @@ function CssCollector({
21
21
  return React.createElement('link', {
22
22
  key: css,
23
23
  rel: 'stylesheet',
24
- href: url
24
+ href: url,
25
+ precedence: 'high'
25
26
  })
26
27
  }),
27
28
  children
@@ -68,6 +69,9 @@ export function createRscStream({
68
69
  moduleBasePath,
69
70
  {
70
71
  onError: (error: Error) => {
72
+ if(process.env['NODE_ENV'] === 'development') {
73
+ console.trace(error);
74
+ }
71
75
  logger.error(`Stream error at ${route}.`, {error});
72
76
  },
73
77
  onPostpone: logger.info ?? console.info,
@@ -33,6 +33,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
33
33
  import { getBundleManifest } from "../helpers/getBundleManifest.js";
34
34
  import type { ServerResponse } from "node:http";
35
35
  import { collectManifestCss } from "../collect-css-manifest.js";
36
+ import { cssFiles } from "../worker/rsc/state.js";
36
37
 
37
38
  let resolvedConfig: ResolvedConfig | null = null;
38
39
  let serverManifestPath: string | null = null;
@@ -428,14 +429,10 @@ export function reactServerPlugin(
428
429
 
429
430
  // Update stats to include CSS and client components
430
431
  const stats: BuildStats = {
431
- htmlFiles: userOptions.build.pages.length,
432
- clientComponents: Object.keys(clientManifest).filter(
433
- userOptions.autoDiscover.clientComponents
434
- ).length,
435
- cssFiles: Object.keys(clientManifest)
436
- .flatMap(userOptions.autoDiscover.cssPattern)
437
- .filter(Boolean).length,
438
- totalRoutes: userOptions.build.pages.length,
432
+ htmlFiles: files.urlMap.size,
433
+ clientComponents: clientComponents.size,
434
+ cssFiles: cssFiles.size,
435
+ totalRoutes: files.urlMap.size,
439
436
  timing: {
440
437
  config: ((timing.configResolved ?? 0) - timing.start) / 1000,
441
438
  build:
@@ -459,10 +456,8 @@ export function reactServerPlugin(
459
456
 
460
457
  console.log("\n[vite-plugin-react-server] Build Summary:");
461
458
  console.log("─".repeat(50));
462
- console.log(`�� Generated ${stats.htmlFiles} HTML files`);
463
- console.log(`🎯 Processed ${stats.clientComponents} client components`);
464
- console.log(`🎨 Included ${stats.cssFiles} CSS files`);
465
- console.log(`🛣️ Total routes: ${stats.totalRoutes}`);
459
+ console.log(`🎨 Included ${buildCssFiles.size} CSS files`);
460
+ console.log(`🛣️ Total routes: ${files.urlMap.size}`);
466
461
  console.log("─".repeat(50));
467
462
  console.log("⏱️ Timing:");
468
463
  console.log(` Config: ${formatDuration(stats.timing.config)}`);
@@ -1,27 +1,21 @@
1
- import { createWriteStream } from "node:fs";
2
- import { mkdir } from "node:fs/promises";
3
- import { dirname, join } from "node:path";
4
- import { parentPort } from "node:worker_threads";
1
+ import { join } from "node:path";
5
2
  import { PassThrough } from "node:stream";
3
+ import { parentPort } from "node:worker_threads";
4
+ import React from "react";
6
5
  import {
7
6
  renderToPipeableStream,
8
7
  // @ts-ignore
9
8
  } from "react-server-dom-esm/server.node";
9
+ import { createLogger } from "../../utils/logger.js";
10
10
  import type {
11
11
  RscChunkMessage,
12
12
  RscEndMessage,
13
13
  RscWorkerMessage,
14
14
  } from "../types.js";
15
- import { createLogger } from "../../utils/logger.js";
16
15
  import {
17
- cssFiles,
18
- clientFiles,
19
- serverActionFiles,
20
16
  addCssFile,
21
- clearCssFiles,
17
+ cssFiles
22
18
  } from "./state.js";
23
- import type { WriteStream } from "node:fs";
24
- import React from "react";
25
19
 
26
20
  const log = createLogger("rsc-worker");
27
21
 
@@ -85,6 +79,7 @@ export async function messageHandler(message: RscWorkerMessage) {
85
79
  moduleBaseURL,
86
80
  {
87
81
  onError: (error: Error) => {
82
+ console.log('onError', error);
88
83
  log.error(`Stream error at ${id}:`, error);
89
84
  parentPort?.postMessage({
90
85
  type: "ERROR",