vite-plugin-react-server 1.1.14 → 1.1.15

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.
Files changed (37) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  3. package/dist/plugin/config/resolveOptions.js +3 -14
  4. package/dist/plugin/config/resolveOptions.js.map +1 -1
  5. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  6. package/dist/plugin/config/resolveUserConfig.js +27 -5
  7. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  8. package/dist/plugin/helpers/inputNormalizer.d.ts +1 -8
  9. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  10. package/dist/plugin/helpers/inputNormalizer.js +2 -5
  11. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  12. package/dist/plugin/loader/sourceMap.d.ts.map +1 -1
  13. package/dist/plugin/loader/sourceMap.js +1 -1
  14. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
  15. package/dist/plugin/react-client/configureWorkerRequestHandler.js +1 -4
  16. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
  17. package/dist/plugin/types.d.ts +6 -0
  18. package/dist/plugin/types.d.ts.map +1 -1
  19. package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -1
  20. package/dist/plugin/worker/rsc/handlers.js +4 -2
  21. package/dist/plugin/worker/rsc/handlers.js.map +1 -1
  22. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  23. package/dist/plugin/worker/rsc/messageHandler.js +0 -1
  24. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  25. package/dist/plugin/worker/rsc/rsc-worker.development.js +1 -0
  26. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +1 -1
  29. package/plugin/config/resolveOptions.ts +5 -24
  30. package/plugin/config/resolveUserConfig.ts +29 -5
  31. package/plugin/helpers/inputNormalizer.ts +4 -13
  32. package/plugin/loader/sourceMap.ts +1 -1
  33. package/plugin/react-client/configureWorkerRequestHandler.ts +0 -3
  34. package/plugin/types.ts +6 -0
  35. package/plugin/worker/rsc/handlers.ts +181 -178
  36. package/plugin/worker/rsc/messageHandler.tsx +0 -1
  37. package/plugin/worker/rsc/rsc-worker.development.ts +1 -0
@@ -1,5 +1,5 @@
1
+ import { createMappingsSerializer } from "../source-map/createMappingsSerializer.js";
1
2
  import type { SourceMap } from "../types/sourceMap.js";
2
- import createMappingsSerializer from 'webpack-sources/lib/helpers/createMappingsSerializer.js';
3
3
  import { basename } from "path";
4
4
 
5
5
  /**
@@ -52,9 +52,6 @@ export async function configureWorkerRequestHandler<
52
52
  moduleBaseURL: server.config.base,
53
53
  moduleBasePath: server.config.base,
54
54
  projectRoot: server.config.root,
55
- moduleID: (id: string) => {
56
- return id
57
- }
58
55
  });
59
56
 
60
57
  // Start the worker
package/plugin/types.ts CHANGED
@@ -22,6 +22,12 @@ import type { ReactServerDomEsmOptions } from "./worker/types.js";
22
22
 
23
23
  export type OnEvent = (event: PluginEvent) => void;
24
24
 
25
+ export type CreateInputNormalizerProps = {
26
+ root: string;
27
+ preserveModulesRoot?: string | undefined;
28
+ removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
29
+ moduleBasePath: string | undefined;
30
+ };
25
31
  export type Serializable =
26
32
  | string
27
33
  | number
@@ -8,66 +8,136 @@ import { ReactDOMServer } from "../../vendor/vendor.server.js";
8
8
  import { PassThrough } from "node:stream";
9
9
 
10
10
  export const handlers: Required<StreamHandlers> = {
11
- onError: (id, error, errorInfo) => {
12
- sendRscWorkerMessage({
13
- type: "ERROR",
14
- id: id,
15
- errorInfo,
16
- error: toError(error),
17
- });
18
- sendRscWorkerMessage({
19
- type: "RSC_END",
20
- id: id,
21
- });
22
- },
23
- onData: (id, data: any) => {
11
+ onError: (id, error, errorInfo) => {
12
+ sendRscWorkerMessage({
13
+ type: "ERROR",
14
+ id: id,
15
+ errorInfo,
16
+ error: toError(error),
17
+ });
18
+ sendRscWorkerMessage({
19
+ type: "RSC_END",
20
+ id: id,
21
+ });
22
+ },
23
+ onData: (id, data: any) => {
24
+ sendRscWorkerMessage({
25
+ type: "RSC_CHUNK",
26
+ id: id,
27
+ chunk: data,
28
+ });
29
+ },
30
+ onEnd: (id: string) => {
31
+ sendRscWorkerMessage({
32
+ type: "RSC_END",
33
+ id: id,
34
+ });
35
+ },
36
+ onMetrics: (id: string, metrics: any) => {
37
+ sendRscWorkerMessage({
38
+ type: "RSC_METRICS",
39
+ id: id,
40
+ metrics,
41
+ });
42
+ },
43
+ onHmrAccept: (id, routes) => {
44
+ sendRscWorkerMessage({
45
+ type: "HMR_ACCEPT",
46
+ id: id,
47
+ routes: routes,
48
+ });
49
+ },
50
+ onHmrUpdate: (id, routes) => {
51
+ sendRscWorkerMessage({
52
+ type: "HMR_UPDATE",
53
+ id: id,
54
+ routes: routes,
55
+ });
56
+ },
57
+ onServerModule: (id, url, source) => {
58
+ addModuleId(id, url);
59
+ sendRscWorkerMessage({
60
+ type: "SERVER_MODULE",
61
+ id,
62
+ url,
63
+ source,
64
+ });
65
+ },
66
+ onServerActionResponse: (id, result) => {
67
+ const stream = ReactDOMServer.renderToPipeableStream(
68
+ {
69
+ type: "server-action-response",
70
+ returnValue: result,
71
+ },
72
+ userOptions.moduleBasePath,
73
+ {
74
+ onError(error: Error) {
75
+ sendRscWorkerMessage({
76
+ type: "ERROR",
77
+ id,
78
+ error: toError(error),
79
+ });
80
+ },
81
+ }
82
+ );
83
+
84
+ const passThrough = new PassThrough();
85
+ stream.pipe(passThrough);
86
+
87
+ passThrough.on("data", (chunk) => {
24
88
  sendRscWorkerMessage({
25
89
  type: "RSC_CHUNK",
26
- id: id,
27
- chunk: data,
90
+ id,
91
+ chunk,
28
92
  });
29
- },
30
- onEnd: (id: string) => {
93
+ });
94
+
95
+ passThrough.on("end", () => {
31
96
  sendRscWorkerMessage({
32
97
  type: "RSC_END",
33
- id: id,
34
- });
35
- },
36
- onMetrics: (id: string, metrics: any) => {
37
- sendRscWorkerMessage ({
38
- type: "RSC_METRICS",
39
- id: id,
40
- metrics,
41
- });
42
- },
43
- onHmrAccept: (id, routes) => {
44
- sendRscWorkerMessage({
45
- type: "HMR_ACCEPT",
46
- id: id,
47
- routes: routes,
48
- });
49
- },
50
- onHmrUpdate: (id, routes) => {
51
- sendRscWorkerMessage({
52
- type: "HMR_UPDATE",
53
- id: id,
54
- routes: routes,
98
+ id,
55
99
  });
56
- },
57
- onServerModule: (id, url, source) => {
58
- addModuleId(id, url);
100
+ });
101
+
102
+ passThrough.on("error", (error) => {
59
103
  sendRscWorkerMessage({
60
- type: "SERVER_MODULE",
104
+ type: "ERROR",
61
105
  id,
62
- url,
63
- source,
106
+ error: toError(error),
64
107
  });
65
- },
66
- onServerActionResponse: (id, result) => {
108
+ });
109
+ },
110
+ onServerAction: async (id, args) => {
111
+ try {
112
+ // Parse the server action ID to get the file path and export name
113
+ const [filePath, exportName] = id.split("#");
114
+ if (!filePath || !exportName) {
115
+ throw new Error(
116
+ `Invalid server action ID format: ${id}. Expected format: "path/to/file.ts#exportName"`
117
+ );
118
+ }
119
+ // Convert the server action ID to a file path
120
+ const actionPath = filePath.startsWith(userOptions.moduleBasePath)
121
+ ? filePath.slice(userOptions.moduleBasePath.length)
122
+ : filePath;
123
+ const fullPath = join(userOptions.projectRoot, actionPath);
124
+
125
+ // Load the server action module
126
+ const module = await import(fullPath);
127
+ const action = module[exportName];
128
+
129
+ if (typeof action !== "function") {
130
+ throw new Error(`Server action not found: ${id}`);
131
+ }
132
+
133
+ // Execute the server action
134
+ const result = await action(...args);
135
+
136
+ // Send success response using RSC stream
67
137
  const stream = ReactDOMServer.renderToPipeableStream(
68
138
  {
69
139
  type: "server-action-response",
70
- returnValue: result
140
+ returnValue: result,
71
141
  },
72
142
  userOptions.moduleBasePath,
73
143
  {
@@ -75,9 +145,9 @@ export const handlers: Required<StreamHandlers> = {
75
145
  sendRscWorkerMessage({
76
146
  type: "ERROR",
77
147
  id,
78
- error: toError(error)
148
+ error: toError(error),
79
149
  });
80
- }
150
+ },
81
151
  }
82
152
  );
83
153
 
@@ -88,14 +158,14 @@ export const handlers: Required<StreamHandlers> = {
88
158
  sendRscWorkerMessage({
89
159
  type: "RSC_CHUNK",
90
160
  id,
91
- chunk
161
+ chunk,
92
162
  });
93
163
  });
94
164
 
95
165
  passThrough.on("end", () => {
96
166
  sendRscWorkerMessage({
97
167
  type: "RSC_END",
98
- id
168
+ id,
99
169
  });
100
170
  });
101
171
 
@@ -103,141 +173,74 @@ export const handlers: Required<StreamHandlers> = {
103
173
  sendRscWorkerMessage({
104
174
  type: "ERROR",
105
175
  id,
106
- error: toError(error)
176
+ error: toError(error),
107
177
  });
108
178
  });
109
- },
110
- onServerAction: async (id, args) => {
111
- try {
112
- // Parse the server action ID to get the file path and export name
113
- const [filePath, exportName] = id.split("#");
114
- if (!filePath || !exportName) {
115
- throw new Error(`Invalid server action ID format: ${id}. Expected format: "path/to/file.ts#exportName"`);
116
- }
117
-
118
- // Convert the server action ID to a file path
119
- const actionPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
120
- const fullPath = join(userOptions.projectRoot, actionPath);
121
-
122
- // Load the server action module
123
- const module = await import(fullPath);
124
- const action = module[exportName];
125
-
126
- if (typeof action !== "function") {
127
- throw new Error(`Server action not found: ${id}`);
128
- }
129
-
130
- // Execute the server action
131
- const result = await action(...args);
132
-
133
- // Send success response using RSC stream
134
- const stream = ReactDOMServer.renderToPipeableStream(
135
- {
136
- type: "server-action-response",
137
- returnValue: result
138
- },
139
- userOptions.moduleBasePath,
140
- {
141
- onError(error: Error) {
142
- sendRscWorkerMessage({
143
- type: "ERROR",
144
- id,
145
- error: toError(error)
146
- });
147
- }
148
- }
149
- );
150
-
151
- const passThrough = new PassThrough();
152
- stream.pipe(passThrough);
153
-
154
- passThrough.on("data", (chunk) => {
155
- sendRscWorkerMessage({
156
- type: "RSC_CHUNK",
157
- id,
158
- chunk
159
- });
160
- });
161
-
162
- passThrough.on("end", () => {
163
- sendRscWorkerMessage({
164
- type: "RSC_END",
165
- id
166
- });
167
- });
168
-
169
- passThrough.on("error", (error) => {
170
- sendRscWorkerMessage({
171
- type: "ERROR",
172
- id,
173
- error: toError(error)
174
- });
175
- });
176
- } catch (error: unknown) {
177
- const errorMessage = toError(error).message;
178
- // Send error response using RSC stream
179
- const stream = ReactDOMServer.renderToPipeableStream(
180
- {
181
- type: "server-action-response",
182
- returnValue: { success: false, error: errorMessage }
179
+ } catch (error: unknown) {
180
+ const errorMessage = toError(error).message;
181
+ // Send error response using RSC stream
182
+ const stream = ReactDOMServer.renderToPipeableStream(
183
+ {
184
+ type: "server-action-response",
185
+ returnValue: { success: false, error: errorMessage },
186
+ },
187
+ userOptions.moduleBasePath,
188
+ {
189
+ onError(error: Error) {
190
+ sendRscWorkerMessage({
191
+ type: "ERROR",
192
+ id,
193
+ error: toError(error),
194
+ });
183
195
  },
184
- userOptions.moduleBasePath,
185
- {
186
- onError(error: Error) {
187
- sendRscWorkerMessage({
188
- type: "ERROR",
189
- id,
190
- error: toError(error)
191
- });
192
- }
193
- }
194
- );
195
-
196
- const passThrough = new PassThrough();
197
- stream.pipe(passThrough);
196
+ }
197
+ );
198
198
 
199
- passThrough.on("data", (chunk) => {
200
- sendRscWorkerMessage({
201
- type: "RSC_CHUNK",
202
- id,
203
- chunk
204
- });
205
- });
199
+ const passThrough = new PassThrough();
200
+ stream.pipe(passThrough);
206
201
 
207
- passThrough.on("end", () => {
208
- sendRscWorkerMessage({
209
- type: "RSC_END",
210
- id
211
- });
202
+ passThrough.on("data", (chunk) => {
203
+ sendRscWorkerMessage({
204
+ type: "RSC_CHUNK",
205
+ id,
206
+ chunk,
212
207
  });
208
+ });
213
209
 
214
- passThrough.on("error", (error) => {
215
- sendRscWorkerMessage({
216
- type: "ERROR",
217
- id,
218
- error: toError(error)
219
- });
210
+ passThrough.on("end", () => {
211
+ sendRscWorkerMessage({
212
+ type: "RSC_END",
213
+ id,
220
214
  });
221
- }
222
- },
223
- onShutdown: (id: string) => {
224
- // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
225
- sendRscWorkerMessage({
226
- type: "SHUTDOWN_COMPLETE",
227
- id: id,
228
215
  });
229
- },
230
- onCssFile: (id, code) => {
231
- if (id) {
232
- // Add to CSS registry
233
- addCssFileContent(id, code, userOptions);
234
-
235
- // Send CSS file message
216
+
217
+ passThrough.on("error", (error) => {
236
218
  sendRscWorkerMessage({
237
- type: "CSS_FILE",
219
+ type: "ERROR",
238
220
  id,
239
- content: code
221
+ error: toError(error),
240
222
  });
241
- }
242
- },
243
- };
223
+ });
224
+ }
225
+ },
226
+ onShutdown: (id: string) => {
227
+ // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete
228
+ sendRscWorkerMessage({
229
+ type: "SHUTDOWN_COMPLETE",
230
+ id: id,
231
+ });
232
+ },
233
+ onCssFile: (id, code) => {
234
+ if (id) {
235
+ // Add to CSS registry
236
+ addCssFileContent(id, code, userOptions);
237
+
238
+ // Send CSS file message
239
+ sendRscWorkerMessage({
240
+ type: "CSS_FILE",
241
+ id,
242
+ content: code,
243
+ });
244
+ }
245
+ },
246
+ };
@@ -31,7 +31,6 @@ export async function messageHandler(
31
31
  case "INITIALIZED_REACT_LOADER":
32
32
  case "INITIALIZED_CSS_LOADER":
33
33
  case "INITIALIZED_ENV_LOADER":
34
- console.log("Initialized ", msg.id);
35
34
  return;
36
35
  case "HMR_UPDATE":
37
36
  // Mark the module as invalidated
@@ -101,6 +101,7 @@ try {
101
101
  register(envLoaderPath, {
102
102
  parentURL: pluginRoot,
103
103
  data: {
104
+ id: "env-loader",
104
105
  port: envLoaderChannel.port1,
105
106
  resolvedConfig: workerData.resolvedConfig,
106
107
  },