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.
- package/dist/package.json +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +3 -14
- 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 +27 -5
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -8
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +2 -5
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/loader/sourceMap.d.ts.map +1 -1
- package/dist/plugin/loader/sourceMap.js +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js +1 -4
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
- package/dist/plugin/types.d.ts +6 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handlers.js +4 -2
- package/dist/plugin/worker/rsc/handlers.js.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +0 -1
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +1 -0
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugin/config/resolveOptions.ts +5 -24
- package/plugin/config/resolveUserConfig.ts +29 -5
- package/plugin/helpers/inputNormalizer.ts +4 -13
- package/plugin/loader/sourceMap.ts +1 -1
- package/plugin/react-client/configureWorkerRequestHandler.ts +0 -3
- package/plugin/types.ts +6 -0
- package/plugin/worker/rsc/handlers.ts +181 -178
- package/plugin/worker/rsc/messageHandler.tsx +0 -1
- 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
|
/**
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
27
|
-
chunk
|
|
90
|
+
id,
|
|
91
|
+
chunk,
|
|
28
92
|
});
|
|
29
|
-
}
|
|
30
|
-
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
passThrough.on("end", () => {
|
|
31
96
|
sendRscWorkerMessage({
|
|
32
97
|
type: "RSC_END",
|
|
33
|
-
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
|
-
|
|
58
|
-
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
passThrough.on("error", (error) => {
|
|
59
103
|
sendRscWorkerMessage({
|
|
60
|
-
type: "
|
|
104
|
+
type: "ERROR",
|
|
61
105
|
id,
|
|
62
|
-
|
|
63
|
-
source,
|
|
106
|
+
error: toError(error),
|
|
64
107
|
});
|
|
65
|
-
}
|
|
66
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
type: "RSC_CHUNK",
|
|
202
|
-
id,
|
|
203
|
-
chunk
|
|
204
|
-
});
|
|
205
|
-
});
|
|
199
|
+
const passThrough = new PassThrough();
|
|
200
|
+
stream.pipe(passThrough);
|
|
206
201
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
202
|
+
passThrough.on("data", (chunk) => {
|
|
203
|
+
sendRscWorkerMessage({
|
|
204
|
+
type: "RSC_CHUNK",
|
|
205
|
+
id,
|
|
206
|
+
chunk,
|
|
212
207
|
});
|
|
208
|
+
});
|
|
213
209
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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: "
|
|
219
|
+
type: "ERROR",
|
|
238
220
|
id,
|
|
239
|
-
|
|
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
|
+
};
|