vite-plugin-react-server 1.1.13 → 1.1.14

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 (159) hide show
  1. package/dist/package.json +3 -1
  2. package/dist/plugin/config/defaults.d.ts +2 -2
  3. package/dist/plugin/config/defaults.d.ts.map +1 -1
  4. package/dist/plugin/config/defaults.js +2 -2
  5. package/dist/plugin/config/defaults.js.map +1 -1
  6. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  7. package/dist/plugin/config/resolveOptions.js +98 -61
  8. package/dist/plugin/config/resolveOptions.js.map +1 -1
  9. package/dist/plugin/error/toError.d.ts.map +1 -1
  10. package/dist/plugin/error/toError.js +0 -1
  11. package/dist/plugin/error/toError.js.map +1 -1
  12. package/dist/plugin/helpers/collectManifestCss.d.ts +1 -2
  13. package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -1
  14. package/dist/plugin/helpers/collectManifestCss.js +3 -5
  15. package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
  16. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
  17. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  18. package/dist/plugin/helpers/collectViteModuleGraphCss.js +6 -2
  19. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  20. package/dist/plugin/helpers/createCssProps.d.ts +1 -1
  21. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  22. package/dist/plugin/helpers/createCssProps.js +11 -32
  23. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  24. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  25. package/dist/plugin/helpers/createRscStream.js +1 -0
  26. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  27. package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -1
  28. package/dist/plugin/loader/createDefaultLoader.js +68 -4
  29. package/dist/plugin/loader/css-loader.development.d.ts +2 -15
  30. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
  31. package/dist/plugin/loader/css-loader.development.js +16 -15
  32. package/dist/plugin/loader/css-loader.development.js.map +1 -1
  33. package/dist/plugin/loader/css-loader.production.d.ts +1 -1
  34. package/dist/plugin/loader/css-loader.production.d.ts.map +1 -1
  35. package/dist/plugin/loader/css-loader.production.js +1 -1
  36. package/dist/plugin/loader/css-loader.production.js.map +1 -1
  37. package/dist/plugin/loader/env-loader.development.d.ts +1 -0
  38. package/dist/plugin/loader/env-loader.development.d.ts.map +1 -1
  39. package/dist/plugin/loader/env-loader.development.js +17 -9
  40. package/dist/plugin/loader/handleExports.d.ts +1 -0
  41. package/dist/plugin/loader/handleExports.d.ts.map +1 -1
  42. package/dist/plugin/loader/handleExports.js +27 -8
  43. package/dist/plugin/loader/handleExports.js.map +1 -1
  44. package/dist/plugin/loader/react-loader.server.d.ts +2 -2
  45. package/dist/plugin/loader/react-loader.server.d.ts.map +1 -1
  46. package/dist/plugin/loader/react-loader.server.js +88 -26
  47. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
  48. package/dist/plugin/loader/transformModuleIfNeeded.js +1 -1
  49. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
  50. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -1
  51. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +86 -13
  52. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -1
  53. package/dist/plugin/plugin.client.d.ts.map +1 -1
  54. package/dist/plugin/plugin.client.js +0 -1
  55. package/dist/plugin/plugin.client.js.map +1 -1
  56. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
  57. package/dist/plugin/react-client/configureWorkerRequestHandler.js +85 -6
  58. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
  59. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  60. package/dist/plugin/react-client/createMessageHandlers.js +3 -0
  61. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
  62. package/dist/plugin/react-client/createWorkerStream.d.ts +2 -2
  63. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  64. package/dist/plugin/react-client/createWorkerStream.js +13 -2
  65. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  66. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
  67. package/dist/plugin/react-client/handleWorkerRscStream.js +10 -3
  68. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
  69. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  70. package/dist/plugin/react-client/restartWorker.js +2 -1
  71. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  72. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
  73. package/dist/plugin/react-server/configureReactServer.js +1 -2
  74. package/dist/plugin/react-server/configureReactServer.js.map +1 -1
  75. package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
  76. package/dist/plugin/react-server/handleServerAction.js +0 -16
  77. package/dist/plugin/react-server/handleServerAction.js.map +1 -1
  78. package/dist/plugin/react-static/createBuildLoader.d.ts.map +1 -0
  79. package/dist/plugin/react-static/createBuildLoader.js.map +1 -0
  80. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  81. package/dist/plugin/react-static/plugin.js +9 -12
  82. package/dist/plugin/react-static/plugin.js.map +1 -1
  83. package/dist/plugin/react-static/temporaryReferences.d.ts.map +1 -0
  84. package/dist/plugin/react-static/temporaryReferences.js.map +1 -0
  85. package/dist/plugin/transformer/plugin.server.js +2 -2
  86. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  87. package/dist/plugin/types.d.ts +14 -3
  88. package/dist/plugin/types.d.ts.map +1 -1
  89. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  90. package/dist/plugin/worker/rsc/handleRender.js +1 -0
  91. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  92. package/dist/plugin/worker/rsc/handlers.d.ts +3 -0
  93. package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -0
  94. package/dist/plugin/worker/rsc/handlers.js +223 -0
  95. package/dist/plugin/worker/rsc/handlers.js.map +1 -0
  96. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  97. package/dist/plugin/worker/rsc/messageHandler.js +5 -110
  98. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  99. package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -16
  100. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  101. package/dist/plugin/worker/rsc/state.d.ts +1 -2
  102. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  103. package/dist/plugin/worker/rsc/state.js +1 -2
  104. package/dist/plugin/worker/rsc/state.js.map +1 -1
  105. package/dist/plugin/worker/rsc/userOptions.d.ts +2 -0
  106. package/dist/plugin/worker/rsc/userOptions.d.ts.map +1 -0
  107. package/dist/plugin/worker/rsc/userOptions.js +17 -0
  108. package/dist/plugin/worker/rsc/userOptions.js.map +1 -0
  109. package/dist/plugin/worker/types.d.ts +2 -1
  110. package/dist/plugin/worker/types.d.ts.map +1 -1
  111. package/dist/tsconfig.tsbuildinfo +1 -1
  112. package/package.json +5 -1
  113. package/plugin/config/defaults.tsx +5 -2
  114. package/plugin/config/resolveOptions.ts +101 -67
  115. package/plugin/error/toError.ts +0 -2
  116. package/plugin/helpers/collectManifestCss.ts +2 -6
  117. package/plugin/helpers/collectViteModuleGraphCss.ts +6 -0
  118. package/plugin/helpers/createCssProps.tsx +17 -46
  119. package/plugin/helpers/createRscStream.tsx +1 -0
  120. package/plugin/loader/createDefaultLoader.ts +80 -4
  121. package/plugin/loader/css-loader.development.ts +17 -34
  122. package/plugin/loader/css-loader.production.ts +2 -4
  123. package/plugin/loader/env-loader.development.ts +38 -15
  124. package/plugin/loader/handleExports.ts +36 -13
  125. package/plugin/loader/react-loader.server.ts +110 -32
  126. package/plugin/loader/transformModuleIfNeeded.ts +2 -2
  127. package/plugin/loader/transformModuleWithPreservedFunctions.ts +128 -21
  128. package/plugin/plugin.client.ts +0 -2
  129. package/plugin/react-client/configureWorkerRequestHandler.ts +107 -4
  130. package/plugin/react-client/createMessageHandlers.ts +3 -0
  131. package/plugin/react-client/createWorkerStream.ts +15 -1
  132. package/plugin/react-client/handleWorkerRscStream.ts +12 -3
  133. package/plugin/react-client/restartWorker.ts +1 -0
  134. package/plugin/react-server/configureReactServer.ts +1 -2
  135. package/plugin/react-server/handleServerAction.ts +1 -19
  136. package/plugin/react-static/plugin.ts +9 -12
  137. package/plugin/transformer/plugin.server.ts +2 -2
  138. package/plugin/types.ts +25 -2
  139. package/plugin/worker/rsc/handleRender.ts +1 -0
  140. package/plugin/worker/rsc/handlers.ts +243 -0
  141. package/plugin/worker/rsc/messageHandler.tsx +4 -118
  142. package/plugin/worker/rsc/rsc-worker.development.ts +17 -20
  143. package/plugin/worker/rsc/state.ts +2 -6
  144. package/plugin/worker/rsc/userOptions.ts +8 -0
  145. package/plugin/worker/types.ts +2 -0
  146. package/dist/plugin/loader/createBuildLoader.d.ts.map +0 -1
  147. package/dist/plugin/loader/createBuildLoader.js.map +0 -1
  148. package/dist/plugin/loader/plugin.d.ts +0 -22
  149. package/dist/plugin/loader/plugin.d.ts.map +0 -1
  150. package/dist/plugin/loader/plugin.js +0 -27
  151. package/dist/plugin/loader/temporaryReferences.d.ts.map +0 -1
  152. package/dist/plugin/loader/temporaryReferences.js.map +0 -1
  153. package/plugin/loader/plugin.ts +0 -33
  154. /package/dist/plugin/{loader → react-static}/createBuildLoader.d.ts +0 -0
  155. /package/dist/plugin/{loader → react-static}/createBuildLoader.js +0 -0
  156. /package/dist/plugin/{loader → react-static}/temporaryReferences.d.ts +0 -0
  157. /package/dist/plugin/{loader → react-static}/temporaryReferences.js +0 -0
  158. /package/plugin/{loader → react-static}/createBuildLoader.ts +0 -0
  159. /package/plugin/{loader → react-static}/temporaryReferences.ts +0 -0
@@ -0,0 +1,223 @@
1
+ /**
2
+ * vite-plugin-react-server
3
+ * Copyright (c) Nico Brinkkemper
4
+ * MIT License
5
+ */
6
+ import { sendRscWorkerMessage } from '../sendMessage.js';
7
+ import { toError } from '../../error/toError.js';
8
+ import { userOptions } from './userOptions.js';
9
+ import { addCssFileContent, addModuleId } from './state.js';
10
+ import { join } from 'path';
11
+ import { ReactDOMServer } from '../../vendor/vendor.server.js';
12
+ import { PassThrough } from 'node:stream';
13
+
14
+ const handlers = {
15
+ onError: (id, error, errorInfo) => {
16
+ sendRscWorkerMessage({
17
+ type: "ERROR",
18
+ id,
19
+ errorInfo,
20
+ error: toError(error)
21
+ });
22
+ sendRscWorkerMessage({
23
+ type: "RSC_END",
24
+ id
25
+ });
26
+ },
27
+ onData: (id, data) => {
28
+ sendRscWorkerMessage({
29
+ type: "RSC_CHUNK",
30
+ id,
31
+ chunk: data
32
+ });
33
+ },
34
+ onEnd: (id) => {
35
+ sendRscWorkerMessage({
36
+ type: "RSC_END",
37
+ id
38
+ });
39
+ },
40
+ onMetrics: (id, metrics) => {
41
+ sendRscWorkerMessage({
42
+ type: "RSC_METRICS",
43
+ id,
44
+ metrics
45
+ });
46
+ },
47
+ onHmrAccept: (id, routes) => {
48
+ sendRscWorkerMessage({
49
+ type: "HMR_ACCEPT",
50
+ id,
51
+ routes
52
+ });
53
+ },
54
+ onHmrUpdate: (id, routes) => {
55
+ sendRscWorkerMessage({
56
+ type: "HMR_UPDATE",
57
+ id,
58
+ routes
59
+ });
60
+ },
61
+ onServerModule: (id, url, source) => {
62
+ addModuleId(id, url);
63
+ sendRscWorkerMessage({
64
+ type: "SERVER_MODULE",
65
+ id,
66
+ url,
67
+ source
68
+ });
69
+ },
70
+ onServerActionResponse: (id, result) => {
71
+ const stream = ReactDOMServer.renderToPipeableStream(
72
+ {
73
+ type: "server-action-response",
74
+ returnValue: result
75
+ },
76
+ userOptions.moduleBasePath,
77
+ {
78
+ onError(error) {
79
+ sendRscWorkerMessage({
80
+ type: "ERROR",
81
+ id,
82
+ error: toError(error)
83
+ });
84
+ }
85
+ }
86
+ );
87
+ const passThrough = new PassThrough();
88
+ stream.pipe(passThrough);
89
+ passThrough.on("data", (chunk) => {
90
+ sendRscWorkerMessage({
91
+ type: "RSC_CHUNK",
92
+ id,
93
+ chunk
94
+ });
95
+ });
96
+ passThrough.on("end", () => {
97
+ sendRscWorkerMessage({
98
+ type: "RSC_END",
99
+ id
100
+ });
101
+ });
102
+ passThrough.on("error", (error) => {
103
+ sendRscWorkerMessage({
104
+ type: "ERROR",
105
+ id,
106
+ error: toError(error)
107
+ });
108
+ });
109
+ },
110
+ onServerAction: async (id, args) => {
111
+ try {
112
+ const [filePath, exportName] = id.split("#");
113
+ if (!filePath || !exportName) {
114
+ throw new Error(`Invalid server action ID format: ${id}. Expected format: "path/to/file.ts#exportName"`);
115
+ }
116
+ const actionPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
117
+ const fullPath = join(userOptions.projectRoot, actionPath);
118
+ const module = await import(fullPath);
119
+ const action = module[exportName];
120
+ if (typeof action !== "function") {
121
+ throw new Error(`Server action not found: ${id}`);
122
+ }
123
+ const result = await action(...args);
124
+ const stream = ReactDOMServer.renderToPipeableStream(
125
+ {
126
+ type: "server-action-response",
127
+ returnValue: result
128
+ },
129
+ userOptions.moduleBasePath,
130
+ {
131
+ onError(error) {
132
+ sendRscWorkerMessage({
133
+ type: "ERROR",
134
+ id,
135
+ error: toError(error)
136
+ });
137
+ }
138
+ }
139
+ );
140
+ const passThrough = new PassThrough();
141
+ stream.pipe(passThrough);
142
+ passThrough.on("data", (chunk) => {
143
+ sendRscWorkerMessage({
144
+ type: "RSC_CHUNK",
145
+ id,
146
+ chunk
147
+ });
148
+ });
149
+ passThrough.on("end", () => {
150
+ sendRscWorkerMessage({
151
+ type: "RSC_END",
152
+ id
153
+ });
154
+ });
155
+ passThrough.on("error", (error) => {
156
+ sendRscWorkerMessage({
157
+ type: "ERROR",
158
+ id,
159
+ error: toError(error)
160
+ });
161
+ });
162
+ } catch (error) {
163
+ const errorMessage = toError(error).message;
164
+ const stream = ReactDOMServer.renderToPipeableStream(
165
+ {
166
+ type: "server-action-response",
167
+ returnValue: { success: false, error: errorMessage }
168
+ },
169
+ userOptions.moduleBasePath,
170
+ {
171
+ onError(error2) {
172
+ sendRscWorkerMessage({
173
+ type: "ERROR",
174
+ id,
175
+ error: toError(error2)
176
+ });
177
+ }
178
+ }
179
+ );
180
+ const passThrough = new PassThrough();
181
+ stream.pipe(passThrough);
182
+ passThrough.on("data", (chunk) => {
183
+ sendRscWorkerMessage({
184
+ type: "RSC_CHUNK",
185
+ id,
186
+ chunk
187
+ });
188
+ });
189
+ passThrough.on("end", () => {
190
+ sendRscWorkerMessage({
191
+ type: "RSC_END",
192
+ id
193
+ });
194
+ });
195
+ passThrough.on("error", (error2) => {
196
+ sendRscWorkerMessage({
197
+ type: "ERROR",
198
+ id,
199
+ error: toError(error2)
200
+ });
201
+ });
202
+ }
203
+ },
204
+ onShutdown: (id) => {
205
+ sendRscWorkerMessage({
206
+ type: "SHUTDOWN_COMPLETE",
207
+ id
208
+ });
209
+ },
210
+ onCssFile: (id, code) => {
211
+ if (id) {
212
+ addCssFileContent(id, code, userOptions);
213
+ sendRscWorkerMessage({
214
+ type: "CSS_FILE",
215
+ id,
216
+ content: code
217
+ });
218
+ }
219
+ }
220
+ };
221
+
222
+ export { handlers };
223
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sources":["../../../../plugin/worker/rsc/handlers.ts"],"sourcesContent":["import { sendRscWorkerMessage } from \"../sendMessage.js\";\nimport type { StreamHandlers } from \"../types.js\";\nimport { toError } from \"../../error/toError.js\";\nimport { userOptions } from \"./userOptions.js\";\nimport { addCssFileContent, addModuleId } from \"./state.js\";\nimport { join } from \"path\";\nimport { ReactDOMServer } from \"../../vendor/vendor.server.js\";\nimport { PassThrough } from \"node:stream\";\n\nexport const handlers: Required<StreamHandlers> = {\n onError: (id, error, errorInfo) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id: id,\n errorInfo,\n error: toError(error),\n });\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onData: (id, data: any) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id: id,\n chunk: data,\n });\n },\n onEnd: (id: string) => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onMetrics: (id: string, metrics: any) => {\n sendRscWorkerMessage ({\n type: \"RSC_METRICS\",\n id: id,\n metrics,\n });\n },\n onHmrAccept: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_ACCEPT\",\n id: id,\n routes: routes,\n });\n },\n onHmrUpdate: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_UPDATE\",\n id: id,\n routes: routes,\n });\n },\n onServerModule: (id, url, source) => {\n addModuleId(id, url);\n sendRscWorkerMessage({\n type: \"SERVER_MODULE\",\n id,\n url,\n source,\n });\n },\n onServerActionResponse: (id, result) => {\n const stream = ReactDOMServer.renderToPipeableStream(\n {\n type: \"server-action-response\",\n returnValue: result\n },\n userOptions.moduleBasePath,\n {\n onError(error: Error) {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n }\n }\n );\n\n const passThrough = new PassThrough();\n stream.pipe(passThrough);\n\n passThrough.on(\"data\", (chunk) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id,\n chunk\n });\n });\n\n passThrough.on(\"end\", () => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id\n });\n });\n\n passThrough.on(\"error\", (error) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n });\n },\n onServerAction: async (id, args) => {\n try {\n // Parse the server action ID to get the file path and export name\n const [filePath, exportName] = id.split(\"#\");\n if (!filePath || !exportName) {\n throw new Error(`Invalid server action ID format: ${id}. Expected format: \"path/to/file.ts#exportName\"`);\n }\n\n // Convert the server action ID to a file path\n const actionPath = filePath.startsWith(\"/\") ? filePath.slice(1) : filePath;\n const fullPath = join(userOptions.projectRoot, actionPath);\n\n // Load the server action module\n const module = await import(fullPath);\n const action = module[exportName];\n\n if (typeof action !== \"function\") {\n throw new Error(`Server action not found: ${id}`);\n }\n\n // Execute the server action\n const result = await action(...args);\n\n // Send success response using RSC stream\n const stream = ReactDOMServer.renderToPipeableStream(\n {\n type: \"server-action-response\",\n returnValue: result\n },\n userOptions.moduleBasePath,\n {\n onError(error: Error) {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n }\n }\n );\n\n const passThrough = new PassThrough();\n stream.pipe(passThrough);\n\n passThrough.on(\"data\", (chunk) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id,\n chunk\n });\n });\n\n passThrough.on(\"end\", () => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id\n });\n });\n\n passThrough.on(\"error\", (error) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n });\n } catch (error: unknown) {\n const errorMessage = toError(error).message;\n // Send error response using RSC stream\n const stream = ReactDOMServer.renderToPipeableStream(\n {\n type: \"server-action-response\",\n returnValue: { success: false, error: errorMessage }\n },\n userOptions.moduleBasePath,\n {\n onError(error: Error) {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n }\n }\n );\n\n const passThrough = new PassThrough();\n stream.pipe(passThrough);\n\n passThrough.on(\"data\", (chunk) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id,\n chunk\n });\n });\n\n passThrough.on(\"end\", () => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id\n });\n });\n\n passThrough.on(\"error\", (error) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id,\n error: toError(error)\n });\n });\n }\n },\n onShutdown: (id: string) => {\n // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete\n sendRscWorkerMessage({\n type: \"SHUTDOWN_COMPLETE\",\n id: id,\n });\n },\n onCssFile: (id, code) => {\n if (id) {\n // Add to CSS registry\n addCssFileContent(id, code, userOptions);\n \n // Send CSS file message\n sendRscWorkerMessage({\n type: \"CSS_FILE\",\n id,\n content: code\n });\n }\n }, \n };"],"names":["error"],"mappings":";;;;;;;;;;;;;AASO,MAAM,QAAqC,GAAA;AAAA,EAC9C,OAAS,EAAA,CAAC,EAAI,EAAA,KAAA,EAAO,SAAc,KAAA;AACjC,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,OAAA;AAAA,MACN,EAAA;AAAA,MACA,SAAA;AAAA,MACA,KAAA,EAAO,QAAQ,KAAK;AAAA,KACrB,CAAA;AACD,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,SAAA;AAAA,MACN;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA,MAAA,EAAQ,CAAC,EAAA,EAAI,IAAc,KAAA;AACzB,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,WAAA;AAAA,MACN,EAAA;AAAA,MACA,KAAO,EAAA;AAAA,KACR,CAAA;AAAA,GACH;AAAA,EACA,KAAA,EAAO,CAAC,EAAe,KAAA;AACrB,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,SAAA;AAAA,MACN;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA,SAAA,EAAW,CAAC,EAAA,EAAY,OAAiB,KAAA;AACvC,IAAuB,oBAAA,CAAA;AAAA,MACrB,IAAM,EAAA,aAAA;AAAA,MACN,EAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA,WAAA,EAAa,CAAC,EAAA,EAAI,MAAW,KAAA;AAC3B,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,YAAA;AAAA,MACN,EAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA,WAAA,EAAa,CAAC,EAAA,EAAI,MAAW,KAAA;AAC3B,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAA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AY,WAAA,CAAA,EAAA,CAAG,MAAQ,EAAA,CAAC,KAAU,KAAA;AAChC,QAAqB,oBAAA,CAAA;AAAA,UACnB,IAAM,EAAA,WAAA;AAAA,UACN,EAAA;AAAA,UACA;AAAA,SACD,CAAA;AAAA,OACF,CAAA;AAED,MAAY,WAAA,CAAA,EAAA,CAAG,OAAO,MAAM;AAC1B,QAAqB,oBAAA,CAAA;AAAA,UACnB,IAAM,EAAA,SAAA;AAAA,UACN;AAAA,SACD,CAAA;AAAA,OACF,CAAA;AAED,MAAY,WAAA,CAAA,EAAA,CAAG,OAAS,EAAA,CAACA,MAAU,KAAA;AACjC,QAAqB,oBAAA,CAAA;AAAA,UACnB,IAAM,EAAA,OAAA;AAAA,UACN,EAAA;AAAA,UACA,KAAA,EAAO,QAAQA,MAAK;AAAA,SACrB,CAAA;AAAA,OACF,CAAA;AAAA;AACH,GACF;AAAA,EACA,UAAA,EAAY,CAAC,EAAe,KAAA;AAE1B,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,mBAAA;AAAA,MACN;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA,SAAA,EAAW,CAAC,EAAA,EAAI,IAAS,KAAA;AACvB,IAAA,IAAI,EAAI,EAAA;AAEN,MAAkB,iBAAA,CAAA,EAAA,EAAI,MAAM,WAAW,CAAA;AAGvC,MAAqB,oBAAA,CAAA;AAAA,QACnB,IAAM,EAAA,UAAA;AAAA,QACN,EAAA;AAAA,QACA,OAAS,EAAA;AAAA,OACV,CAAA;AAAA;AACH;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"messageHandler.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,qBAAqB,EAEtB,MAAM,aAAa,CAAC;AAwGrB,wBAAsB,cAAc,CAClC,GAAG,EAAE,qBAAqB,EAC1B,IAAI,8CAAa,iBA2FlB"}
1
+ {"version":3,"file":"messageHandler.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AASrB,wBAAsB,cAAc,CAClC,GAAG,EAAE,qBAAqB,EAC1B,IAAI,8CAAa,iBA2ElB"}
@@ -3,104 +3,14 @@
3
3
  * Copyright (c) Nico Brinkkemper
4
4
  * MIT License
5
5
  */
6
- import { parentPort, workerData } from 'node:worker_threads';
7
- import { activeStreams, addModuleId, addCssFileContent, hmrState } from './state.js';
6
+ import { parentPort } from 'node:worker_threads';
7
+ import { activeStreams, hmrState } from './state.js';
8
8
  import { handleRender } from './handleRender.js';
9
- import { sendRscWorkerMessage } from '../sendMessage.js';
10
9
  import { toError } from '../../error/toError.js';
10
+ import { handlers } from './handlers.js';
11
11
 
12
12
  const isTestEnv = process.env["VITEST"] || process.env["NODE_ENV"] === "test";
13
13
  const isDevEnv = process.env["NODE_ENV"] !== "production";
14
- const handlers = {
15
- onError: (id, error, errorInfo) => {
16
- sendRscWorkerMessage({
17
- type: "ERROR",
18
- id,
19
- errorInfo,
20
- error: toError(error)
21
- });
22
- sendRscWorkerMessage({
23
- type: "RSC_END",
24
- id
25
- });
26
- },
27
- onData: (id, data) => {
28
- sendRscWorkerMessage({
29
- type: "RSC_CHUNK",
30
- id,
31
- chunk: data
32
- });
33
- },
34
- onEnd: (id) => {
35
- sendRscWorkerMessage({
36
- type: "RSC_END",
37
- id
38
- });
39
- },
40
- onMetrics: (id, metrics) => {
41
- sendRscWorkerMessage({
42
- type: "RSC_METRICS",
43
- id,
44
- metrics
45
- });
46
- },
47
- onHmrAccept: (id, routes) => {
48
- sendRscWorkerMessage({
49
- type: "HMR_ACCEPT",
50
- id,
51
- routes
52
- });
53
- },
54
- onHmrUpdate: (id, routes) => {
55
- sendRscWorkerMessage({
56
- type: "HMR_UPDATE",
57
- id,
58
- routes
59
- });
60
- },
61
- onServerModule: (id, url, source) => {
62
- sendRscWorkerMessage({
63
- type: "SERVER_MODULE",
64
- id,
65
- url,
66
- source
67
- });
68
- },
69
- onServerActionResponse: (id, result, error) => {
70
- sendRscWorkerMessage({
71
- type: "SERVER_ACTION_RESPONSE",
72
- id,
73
- result,
74
- error
75
- });
76
- },
77
- onServerAction: async (id, args) => {
78
- try {
79
- const serverAction = workerData.serverActions?.[id];
80
- if (!serverAction) {
81
- throw new Error(`Server action ${id} not found`);
82
- }
83
- const result = await serverAction(...args);
84
- sendRscWorkerMessage({
85
- type: "SERVER_ACTION_RESPONSE",
86
- id,
87
- result
88
- });
89
- } catch (error) {
90
- sendRscWorkerMessage({
91
- type: "SERVER_ACTION_RESPONSE",
92
- id,
93
- error: error instanceof Error ? error.message : String(error)
94
- });
95
- }
96
- },
97
- onShutdown: (id) => {
98
- sendRscWorkerMessage({
99
- type: "SHUTDOWN_COMPLETE",
100
- id
101
- });
102
- }
103
- };
104
14
  async function messageHandler(msg, port = parentPort) {
105
15
  try {
106
16
  if (!port) {
@@ -112,10 +22,9 @@ async function messageHandler(msg, port = parentPort) {
112
22
  case "SERVER_ACTION":
113
23
  return handlers.onServerAction(msg.id, msg.args);
114
24
  case "INITIALIZED_REACT_LOADER":
115
- return;
116
25
  case "INITIALIZED_CSS_LOADER":
117
- return;
118
26
  case "INITIALIZED_ENV_LOADER":
27
+ console.log("Initialized ", msg.id);
119
28
  return;
120
29
  case "HMR_UPDATE":
121
30
  hmrState.set(msg.id, {
@@ -130,23 +39,9 @@ async function messageHandler(msg, port = parentPort) {
130
39
  handlers.onHmrAccept(msg.id, msg.routes || []);
131
40
  return;
132
41
  case "CSS_FILE":
133
- if (msg.id) {
134
- const cssOptions = workerData.userOptions.css || {
135
- inlineThreshold: 1e3
136
- };
137
- addCssFileContent(msg.id, msg.content, {
138
- projectRoot: workerData.userOptions.projectRoot || process.cwd(),
139
- moduleBaseURL: workerData.userOptions.moduleBaseURL || "/",
140
- moduleBasePath: workerData.userOptions.moduleBasePath || "/",
141
- moduleRootPath: workerData.userOptions.moduleRootPath,
142
- css: cssOptions
143
- });
144
- }
42
+ handlers.onCssFile(msg.id, msg.content);
145
43
  return;
146
44
  case "SERVER_MODULE":
147
- if (msg.id && msg.url) {
148
- addModuleId(msg.id, msg.url);
149
- }
150
45
  handlers.onServerModule(msg.id, msg.url, msg.source);
151
46
  return;
152
47
  case "SHUTDOWN": {
@@ -1 +1 @@
1
- {"version":3,"file":"messageHandler.js","sources":["../../../../plugin/worker/rsc/messageHandler.tsx"],"sourcesContent":["import { parentPort, workerData } from \"node:worker_threads\";\nimport {\n activeStreams,\n addCssFileContent,\n hmrState,\n addModuleId,\n} from \"./state.js\";\nimport { handleRender } from \"./handleRender.js\";\nimport type {\n RscWorkerInputMessage,\n StreamHandlers,\n} from \"../types.js\";\nimport { sendRscWorkerMessage } from \"../sendMessage.js\";\nimport { toError } from \"../../error/toError.js\";\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\n\nconst handlers: Required<StreamHandlers> = {\n onError: (id, error, errorInfo) => {\n sendRscWorkerMessage({\n type: \"ERROR\",\n id: id,\n errorInfo,\n error: toError(error),\n });\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onData: (id, data: any) => {\n sendRscWorkerMessage({\n type: \"RSC_CHUNK\",\n id: id,\n chunk: data,\n });\n },\n onEnd: (id: string) => {\n sendRscWorkerMessage({\n type: \"RSC_END\",\n id: id,\n });\n },\n onMetrics: (id: string, metrics: any) => {\n sendRscWorkerMessage({\n type: \"RSC_METRICS\",\n id: id,\n metrics,\n });\n },\n onHmrAccept: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_ACCEPT\",\n id: id,\n routes: routes,\n });\n },\n onHmrUpdate: (id, routes) => {\n sendRscWorkerMessage({\n type: \"HMR_UPDATE\",\n id: id,\n routes: routes,\n });\n },\n onServerModule: (id, url, source) => {\n sendRscWorkerMessage({\n type: \"SERVER_MODULE\",\n id,\n url,\n source,\n });\n },\n onServerActionResponse: (id, result, error) => {\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n result,\n error,\n });\n },\n onServerAction: async (id, args) => {\n try {\n // Get the server action function from the worker data\n const serverAction = workerData.serverActions?.[id];\n if (!serverAction) {\n throw new Error(`Server action ${id} not found`);\n }\n // Execute the server action\n const result = await serverAction(...args);\n // Send the result back\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n result,\n });\n } catch (error) {\n // Send error back\n sendRscWorkerMessage({\n type: \"SERVER_ACTION_RESPONSE\",\n id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n },\n onShutdown: (id: string) => {\n // Send SHUTDOWN_COMPLETE message to signal that shutdown is complete\n sendRscWorkerMessage({\n type: \"SHUTDOWN_COMPLETE\",\n id: id,\n });\n },\n};\n\nexport async function messageHandler(\n msg: RscWorkerInputMessage,\n port = parentPort\n) {\n try {\n if (!port) {\n throw new Error(\"No port found\");\n }\n switch (msg.type) {\n case \"RSC_RENDER\":\n return await handleRender(msg, handlers);\n case \"SERVER_ACTION\":\n return handlers.onServerAction(msg.id, msg.args);\n case \"INITIALIZED_REACT_LOADER\":\n return;\n case \"INITIALIZED_CSS_LOADER\":\n return;\n case \"INITIALIZED_ENV_LOADER\":\n return;\n case \"HMR_UPDATE\":\n // Mark the module as invalidated\n hmrState.set(msg.id, {\n timestamp: msg.timestamp || Date.now(),\n invalidated: true,\n routes: msg.routes || [],\n });\n // Notify the main thread that we've processed the update\n handlers.onHmrUpdate(msg.id, msg.routes || []);\n return;\n case \"HMR_CLEANUP\":\n // Clear the invalidation state\n hmrState.delete(msg.id);\n // Notify the main thread that we've processed the cleanup\n handlers.onHmrAccept(msg.id, msg.routes || []);\n return;\n case \"CSS_FILE\":\n if (msg.id) {\n const cssOptions = workerData.userOptions.css || {\n inlineThreshold: 1000,\n };\n\n addCssFileContent(msg.id, msg.content, {\n projectRoot: workerData.userOptions.projectRoot || process.cwd(),\n moduleBaseURL: workerData.userOptions.moduleBaseURL || \"/\",\n moduleBasePath: workerData.userOptions.moduleBasePath || \"/\",\n moduleRootPath: workerData.userOptions.moduleRootPath,\n css: cssOptions,\n });\n }\n return;\n case \"SERVER_MODULE\":\n if (msg.id && msg.url) {\n addModuleId(msg.id, msg.url);\n }\n handlers.onServerModule(msg.id, msg.url, msg.source);\n return;\n case \"SHUTDOWN\": {\n // If id is \"*\", clean up all render states\n if (msg.id === \"*\") {\n activeStreams.forEach((stream, renderId) => {\n stream.end();\n activeStreams.delete(renderId);\n });\n parentPort?.removeAllListeners();\n } else {\n activeStreams.delete(msg.id);\n }\n handlers.onShutdown(msg.id);\n return;\n }\n default: {\n console.log(\"Unknown message\", msg);\n return;\n }\n }\n } catch (error) {\n const err = toError(error);\n if (isDevEnv) {\n console.error(err);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n port?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: err,\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw err;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAgBA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAE7C,MAAM,QAAqC,GAAA;AAAA,EACzC,OAAS,EAAA,CAAC,EAAI,EAAA,KAAA,EAAO,SAAc,KAAA;AACjC,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,OAAA;AAAA,MACN,EAAA;AAAA,MACA,SAAA;AAAA,MACA,KAAA,EAAO,QAAQ,KAAK;AAAA,KACrB,CAAA;AACD,IAAqB,oBAAA,CAAA;AAAA,MACnB,IAAM,EAAA,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node:worker_threads\";\nimport {\n activeStreams,\n hmrState,\n} from \"./state.js\";\nimport { handleRender } from \"./handleRender.js\";\nimport type {\n RscWorkerInputMessage,\n} from \"../types.js\";\nimport { toError } from \"../../error/toError.js\";\nimport { handlers } from \"./handlers.js\";\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\n\n\nexport async function messageHandler(\n msg: RscWorkerInputMessage,\n port = parentPort\n) {\n try {\n if (!port) {\n throw new Error(\"No port found\");\n }\n switch (msg.type) {\n case \"RSC_RENDER\":\n return await handleRender(msg, handlers);\n case \"SERVER_ACTION\":\n return handlers.onServerAction(msg.id, msg.args);\n case \"INITIALIZED_REACT_LOADER\":\n case \"INITIALIZED_CSS_LOADER\":\n case \"INITIALIZED_ENV_LOADER\":\n console.log(\"Initialized \", msg.id);\n return;\n case \"HMR_UPDATE\":\n // Mark the module as invalidated\n hmrState.set(msg.id, {\n timestamp: msg.timestamp || Date.now(),\n invalidated: true,\n routes: msg.routes || [],\n });\n // Notify the main thread that we've processed the update\n handlers.onHmrUpdate(msg.id, msg.routes || []);\n return;\n case \"HMR_CLEANUP\":\n // Clear the invalidation state\n hmrState.delete(msg.id);\n // Notify the main thread that we've processed the cleanup\n handlers.onHmrAccept(msg.id, msg.routes || []);\n return;\n case \"CSS_FILE\":\n handlers.onCssFile(msg.id, msg.content);\n return;\n case \"SERVER_MODULE\":\n handlers.onServerModule(msg.id, msg.url, msg.source);\n return;\n case \"SHUTDOWN\": {\n // If id is \"*\", clean up all render states\n if (msg.id === \"*\") {\n activeStreams.forEach((stream, renderId) => {\n stream.end();\n activeStreams.delete(renderId);\n });\n parentPort?.removeAllListeners();\n } else {\n activeStreams.delete(msg.id);\n }\n handlers.onShutdown(msg.id);\n return;\n }\n default: {\n console.log(\"Unknown message\", msg);\n return;\n }\n }\n } catch (error) {\n const err = toError(error);\n if (isDevEnv) {\n console.error(err);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n port?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: err,\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw err;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAaA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAG7C,eAAsB,cAAA,CACpB,GACA,EAAA,IAAA,GAAO,UACP,EAAA;AACA,EAAI,IAAA;AACF,IAAA,IAAI,CAAC,IAAM,EAAA;AACT,MAAM,MAAA,IAAI,MAAM,eAAe,CAAA;AAAA;AAEjC,IAAA,QAAQ,IAAI,IAAM;AAAA,MAChB,KAAK,YAAA;AACH,QAAO,OAAA,MAAM,YAAa,CAAA,GAAA,EAAK,QAAQ,CAAA;AAAA,MACzC,KAAK,eAAA;AACH,QAAA,OAAO,QAAS,CAAA,cAAA,CAAe,GAAI,CAAA,EAAA,EAAI,IAAI,IAAI,CAAA;AAAA,MACjD,KAAK,0BAAA;AAAA,MACL,KAAK,wBAAA;AAAA,MACL,KAAK,wBAAA;AACH,QAAQ,OAAA,CAAA,GAAA,CAAI,cAAgB,EAAA,GAAA,CAAI,EAAE,CAAA;AAClC,QAAA;AAAA,MACF,KAAK,YAAA;AAEH,QAAS,QAAA,CAAA,GAAA,CAAI,IAAI,EAAI,EAAA;AAAA,UACnB,SAAW,EAAA,GAAA,CAAI,SAAa,IAAA,IAAA,CAAK,GAAI,EAAA;AAAA,UACrC,WAAa,EAAA,IAAA;AAAA,UACb,MAAA,EAAQ,GAAI,CAAA,MAAA,IAAU;AAAC,SACxB,CAAA;AAED,QAAA,QAAA,CAAS,YAAY,GAAI,CAAA,EAAA,EAAI,GA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,IAAM,EAAA,OAAA;AAAA,QACN,EAAI,EAAA,YAAA;AAAA,QACJ,KAAO,EAAA;AAAA,OACR,CAAA;AAAA;AAEH,IAAI,IAAA,CAAC,YAAY,SAAW,EAAA;AAE1B,MAAM,MAAA,GAAA;AAAA;AACR;AAEJ;;;;"}
@@ -9,7 +9,6 @@ import { register } from 'node:module';
9
9
  import { register as register$1 } from 'tsx/esm/api';
10
10
  import { join } from 'node:path';
11
11
  import { pluginRoot } from '../../root.js';
12
- import { deserializeRegExp } from '../../helpers/serializeUserOptions.js';
13
12
  import { toError } from '../../error/toError.js';
14
13
 
15
14
  if (!parentPort) {
@@ -48,37 +47,35 @@ const developmentReactLoaderMessageHandler = (msg) => {
48
47
  messageHandler(msg);
49
48
  };
50
49
  try {
51
- if (workerData) {
52
- workerData.userOptions = deserializeRegExp(workerData.userOptions);
53
- }
54
50
  const reactLoaderChannel = new MessageChannel();
55
51
  const cssLoaderChannel = new MessageChannel();
56
52
  const envLoaderChannel = new MessageChannel();
57
- reactLoaderChannel.port1.on("message", developmentReactLoaderMessageHandler);
58
- cssLoaderChannel.port1.on("message", developmentCssLoaderMessageHandler);
59
- envLoaderChannel.port1.on("message", developmentEnvLoaderMessageHandler);
53
+ reactLoaderChannel.port2.on("message", developmentReactLoaderMessageHandler);
54
+ cssLoaderChannel.port2.on("message", developmentCssLoaderMessageHandler);
55
+ envLoaderChannel.port2.on("message", developmentEnvLoaderMessageHandler);
60
56
  const reactLoaderPath = "file://" + join(pluginRoot, "loader/react-loader.server.js");
61
57
  const cssLoaderPath = "file://" + join(pluginRoot, "loader/css-loader.development.js");
62
58
  const envLoaderPath = "file://" + join(pluginRoot, "loader/env-loader.development.js");
63
- register(reactLoaderPath, {
64
- parentURL: pluginRoot,
65
- data: {
66
- id: "react-loader",
67
- port: reactLoaderChannel.port1,
68
- userOptions: workerData.userOptions
69
- },
70
- transferList: [reactLoaderChannel.port1]
71
- });
72
59
  register(cssLoaderPath, {
73
60
  parentURL: pluginRoot,
74
61
  data: {
75
62
  id: "css-loader",
76
63
  port: cssLoaderChannel.port1,
64
+ userOptions: workerData.userOptions,
77
65
  resolvedConfig: workerData.resolvedConfig
78
66
  },
79
67
  transferList: [cssLoaderChannel.port1]
80
68
  });
81
69
  register$1();
70
+ register(reactLoaderPath, {
71
+ parentURL: pluginRoot,
72
+ data: {
73
+ id: "react-loader",
74
+ port: reactLoaderChannel.port1,
75
+ userOptions: workerData.userOptions
76
+ },
77
+ transferList: [reactLoaderChannel.port1]
78
+ });
82
79
  register(envLoaderPath, {
83
80
  parentURL: pluginRoot,
84
81
  data: {
@@ -1 +1 @@
1
- {"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["import { parentPort, MessageChannel, workerData } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport { deserializeRegExp } from \"../../helpers/serializeUserOptions.js\";\nimport type {\n HmrAcceptMessage,\n HmrUpdateMessage,\n ReadyMessage,\n} from \"../types.js\";\nimport { toError } from \"../../error/toError.js\";\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\nconst verbose = workerData.verbose;\n\nconst developmentMessageHandler = (msg: any) => {\n if (verbose) {\n if (\"chunk\" in msg) {\n let preview = Buffer.from(msg.chunk).toString(\"utf-8\");\n console.log(`[rsc-worker:${msg.type}] ${preview}`);\n } else {\n console.log(`[rsc-worker:${msg.type}] ${JSON.stringify(msg)}`);\n }\n }\n messageHandler(msg);\n};\n\nconst developmentCssLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[css-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentEnvLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[env-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentReactLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[react-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\ntry {\n // Deserialize workerData to restore RegExp objects\n if (workerData) {\n workerData.userOptions = deserializeRegExp(workerData.userOptions);\n }\n\n // Create channels for each loader\n const reactLoaderChannel = new MessageChannel();\n const cssLoaderChannel = new MessageChannel();\n const envLoaderChannel = new MessageChannel();\n\n // Set up message handlers before transferring ports\n reactLoaderChannel.port1.on(\"message\", developmentReactLoaderMessageHandler);\n cssLoaderChannel.port1.on(\"message\", developmentCssLoaderMessageHandler);\n envLoaderChannel.port1.on(\"message\", developmentEnvLoaderMessageHandler);\n\n const reactLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/react-loader.server.js\");\n const cssLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/css-loader.development.js\");\n const envLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/env-loader.development.js\");\n\n // Register loaders with their ports\n register(reactLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"react-loader\",\n port: reactLoaderChannel.port1,\n userOptions: workerData.userOptions,\n },\n transferList: [reactLoaderChannel.port1],\n });\n register(cssLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"css-loader\",\n port: cssLoaderChannel.port1,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [cssLoaderChannel.port1],\n });\n\n // Register loaders\n registerTsx();\n\n // Register env-loader (ensure this the last)\n register(envLoaderPath, {\n parentURL: pluginRoot,\n data: {\n port: envLoaderChannel.port1,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [envLoaderChannel.port1],\n });\n\n // Set up message handling\n parentPort!.on(\"message\", developmentMessageHandler);\n\n const { hmrPort } = workerData;\n if (hmrPort) {\n // Start the message port\n hmrPort.start();\n\n // Listen for HMR messages\n hmrPort.on(\"message\", (message: any) => {\n if (message.type === \"HMR_UPDATE\") {\n // Invalidate the module in the worker\n parentPort!.postMessage({\n type: \"HMR_UPDATE\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrUpdateMessage);\n } else if (message.type === \"HMR_ACCEPT\") {\n // Handle the update\n parentPort!.postMessage({\n type: \"HMR_ACCEPT\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrAcceptMessage);\n }\n });\n }\n\n // Notify parent that we're ready\n parentPort!.postMessage({\n type: \"READY\",\n env: process.env[\"NODE_ENV\"],\n pid: process.pid,\n id: \"rsc-worker\",\n } satisfies ReadyMessage);\n\n if (process.env[\"NODE_ENV\"] === \"production\") {\n throw new Error(\"This module should not run in production mode.\");\n }\n} catch (error) {\n if (isDevEnv) {\n console.error(error);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n parentPort?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: toError(error),\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw error;\n }\n}\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;;;AAcA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAC7C,MAAM,UAAU,UAAW,CAAA,OAAA;AAE3B,MAAM,yBAAA,GAA4B,CAAC,GAAa,KAAA;AAC9C,EAAA,IAAI,OAAS,EAAA;AACX,IAAA,IAAI,WAAW,GAAK,EAAA;AAClB,MAAA,IAAI,UAAU,MAAO,CAAA,IAAA,CAA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AAA,OAAS,KAAO,EAAA;AACd,EAAA,IAAI,QAAU,EAAA;AACZ,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAGrB,EAAA,IAAI,UAAY,EAAA;AACd,IAAA,UAAA,EAAY,WAAY,CAAA;AAAA,MACtB,IAAM,EAAA,OAAA;AAAA,MACN,EAAI,EAAA,YAAA;AAAA,MACJ,KAAA,EAAO,QAAQ,KAAK;AAAA,KACrB,CAAA;AAAA;AAEH,EAAI,IAAA,CAAC,YAAY,SAAW,EAAA;AAE1B,IAAM,MAAA,KAAA;AAAA;AAEV"}
1
+ {"version":3,"file":"rsc-worker.development.js","sources":["../../../../plugin/worker/rsc/rsc-worker.development.ts"],"sourcesContent":["import { parentPort, MessageChannel, workerData } from \"node:worker_threads\";\nimport { messageHandler } from \"./messageHandler.js\";\nimport { register } from \"node:module\";\nimport { register as registerTsx } from \"tsx/esm/api\";\nimport { join } from \"node:path\";\nimport { pluginRoot } from \"../../root.js\";\nimport type {\n HmrAcceptMessage,\n HmrUpdateMessage,\n ReadyMessage,\n} from \"../types.js\";\nimport { toError } from \"../../error/toError.js\";\n\n// Initialize worker\nif (!parentPort) {\n throw new Error(\"This module must be run as a worker\");\n}\n\n// In test mode, we want errors to propagate up immediately\nconst isTestEnv = process.env[\"VITEST\"] || process.env[\"NODE_ENV\"] === \"test\";\nconst isDevEnv = process.env[\"NODE_ENV\"] !== \"production\";\nconst verbose = workerData.verbose;\n\nconst developmentMessageHandler = (msg: any) => {\n if (verbose) {\n if (\"chunk\" in msg) {\n let preview = Buffer.from(msg.chunk).toString(\"utf-8\");\n console.log(`[rsc-worker:${msg.type}] ${preview}`);\n } else {\n console.log(`[rsc-worker:${msg.type}] ${JSON.stringify(msg)}`);\n }\n }\n messageHandler(msg);\n};\n\nconst developmentCssLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[css-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentEnvLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[env-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\nconst developmentReactLoaderMessageHandler = (msg: any) => {\n if (verbose) {\n console.log(`[react-loader:${msg.type}] ${JSON.stringify(msg)}`);\n }\n messageHandler(msg);\n};\n\ntry {\n // Create channels for each loader\n const reactLoaderChannel = new MessageChannel();\n const cssLoaderChannel = new MessageChannel();\n const envLoaderChannel = new MessageChannel();\n\n // Set up message handlers before transferring ports\n reactLoaderChannel.port2.on(\"message\", developmentReactLoaderMessageHandler);\n cssLoaderChannel.port2.on(\"message\", developmentCssLoaderMessageHandler);\n envLoaderChannel.port2.on(\"message\", developmentEnvLoaderMessageHandler);\n\n const reactLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/react-loader.server.js\");\n const cssLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/css-loader.development.js\");\n const envLoaderPath =\n \"file://\" + join(pluginRoot, \"loader/env-loader.development.js\");\n\n register(cssLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"css-loader\",\n port: cssLoaderChannel.port1,\n userOptions: workerData.userOptions,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [cssLoaderChannel.port1],\n });\n\n // Register tsx\n registerTsx();\n\n // Register loaders with their ports\n register(reactLoaderPath, {\n parentURL: pluginRoot,\n data: {\n id: \"react-loader\",\n port: reactLoaderChannel.port1,\n userOptions: workerData.userOptions,\n },\n transferList: [reactLoaderChannel.port1],\n });\n\n // Register env-loader (ensure this the last)\n register(envLoaderPath, {\n parentURL: pluginRoot,\n data: {\n port: envLoaderChannel.port1,\n resolvedConfig: workerData.resolvedConfig,\n },\n transferList: [envLoaderChannel.port1],\n });\n\n // Set up message handling\n parentPort!.on(\"message\", developmentMessageHandler);\n\n const { hmrPort } = workerData;\n if (hmrPort) {\n // Start the message port\n hmrPort.start();\n\n // Listen for HMR messages\n hmrPort.on(\"message\", (message: any) => {\n if (message.type === \"HMR_UPDATE\") {\n // Invalidate the module in the worker\n parentPort!.postMessage({\n type: \"HMR_UPDATE\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrUpdateMessage);\n } else if (message.type === \"HMR_ACCEPT\") {\n // Handle the update\n parentPort!.postMessage({\n type: \"HMR_ACCEPT\",\n id: message.id,\n routes: message.routes,\n } satisfies HmrAcceptMessage);\n }\n });\n }\n\n // Notify parent that we're ready\n parentPort!.postMessage({\n type: \"READY\",\n env: process.env[\"NODE_ENV\"],\n pid: process.pid,\n id: \"rsc-worker\",\n } satisfies ReadyMessage);\n\n if (process.env[\"NODE_ENV\"] === \"production\") {\n throw new Error(\"This module should not run in production mode.\");\n }\n} catch (error) {\n if (isDevEnv) {\n console.error(error);\n }\n // In dev mode, try to send error message before exiting\n if (parentPort) {\n parentPort?.postMessage({\n type: \"ERROR\",\n id: \"rsc-worker\",\n error: toError(error),\n });\n }\n if (!isDevEnv || isTestEnv) {\n // In test mode or production mode, just throw the error to fail fast\n throw error;\n }\n}\n"],"names":["registerTsx"],"mappings":";;;;;;;;;;;;;AAcA,IAAI,CAAC,UAAY,EAAA;AACf,EAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AACvD;AAGA,MAAM,SAAA,GAAY,QAAQ,GAAI,CAAA,QAAQ,KAAK,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAM,KAAA,MAAA;AACvE,MAAM,QAAW,GAAA,OAAA,CAAQ,GAAI,CAAA,UAAU,CAAM,KAAA,YAAA;AAC7C,MAAM,UAAU,UAAW,CAAA,OAAA;AAE3B,MAAM,yBAAA,GAA4B,CAAC,GAAa,KAAA;AAC9C,EAAA,IAAI,OAAS,EAAA;AACX,IAAA,IAAI,WAAW,GAAK,EAAA;AAClB,MAAA,IAAI,UAAU,MAAO,CAAA,IAAA,CAAK,IAAI,KAAK,CAAA,CAAE,SAAS,OAAO,CAAA;AACrD,MAAA,OAAA,CAAQ,IAAI,CAAe,YAAA,EAAA,GAAA,CAAI,IAAI,C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EAAA,OAAA;AAAA,MACN,EAAI,EAAA,YAAA;AAAA,MACJ,KAAA,EAAO,QAAQ,KAAK;AAAA,KACrB,CAAA;AAAA;AAEH,EAAI,IAAA,CAAC,YAAY,SAAW,EAAA;AAE1B,IAAM,MAAA,KAAA;AAAA;AAEV"}
@@ -10,8 +10,7 @@ export declare function clearCssFiles(): void;
10
10
  export declare function getCssFiles(): MapIterator<[string, CssContent]>;
11
11
  export declare function clearClientFiles(): void;
12
12
  export declare function clearServerActionFiles(): void;
13
- export declare function addCssFile(id: string, cssFile: CssContent): void;
14
- export declare function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, "projectRoot" | "moduleBaseURL" | "moduleBasePath" | "moduleRootPath" | "css">): void;
13
+ export declare function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, "projectRoot" | "moduleBaseURL" | "moduleBasePath" | "moduleRootPath" | "css" | "normalizer" | "moduleID">): void;
15
14
  export declare function addClientFile(url: string): void;
16
15
  export declare function addServerActionFile(url: string): void;
17
16
  export declare function clearAllFiles(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,eAAO,MAAM,aAAa,0BAAiC,CAAC;AAG5D,eAAO,MAAM,QAAQ,yBAAgC,CAAC;AAGtD,eAAO,MAAM,SAAS,qBAA4B,CAAC;AAEnD,eAAO,MAAM,QAAQ,uBAA8B,CAAC;AAyBpD,eAAO,MAAM,WAAW,aAAoB,CAAC;AAC7C,eAAO,MAAM,iBAAiB,aAAoB,CAAC;AAGnD,wBAAgB,aAAa,SAE5B;AAED,wBAAgB,WAAW,sCAE1B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBA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wBAAgB,WAAW,sCAE1B;AAED,wBAAgB,gBAAgB,SAE/B;AAED,wBAAgB,sBAAsB,SAErC;AAID,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,KAAK,GAAG,YAAY,GAAG,UAAU,CAAC,QAS5M;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,QAExC;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,QAE9C;AAED,wBAAgB,aAAa,SAI5B;AAGD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGzD;AAGD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEhD;AAGD,wBAAgB,qBAAqB,IAAI,MAAM,EAAE,CAIhD;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAElD;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE1D"}
@@ -34,8 +34,7 @@ function addCssFileContent(id, code, userOptions) {
34
34
  if (typeof code !== "string") {
35
35
  throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);
36
36
  }
37
- const normalizeId = id.startsWith(userOptions.moduleRootPath) ? id.slice(userOptions.moduleRootPath.length) : id;
38
- cssFiles.set(normalizeId, createCssProps({
37
+ cssFiles.set(id, createCssProps({
39
38
  id,
40
39
  code,
41
40
  userOptions
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["import { workerData } from \"node:worker_threads\";\nimport { createCssProps } from \"../../helpers/createCssProps.js\";\nimport type { CssContent, ResolvedUserOptions, HmrState } from \"../../types.js\";\nimport type { PassThrough } from \"node:stream\";\nimport { relative } from \"node:path\";\n\n\n// Track active RSC streams\nexport const activeStreams = new Map<string, PassThrough>();\n\n// Track CSS files\nexport const cssFiles = new Map<string, CssContent>();\n\n// Track module IDs\nexport const moduleIds = new Map<string, string>();\n\nexport const hmrState = new Map<string, HmrState>();\n\nif(workerData) {\n if(workerData.hmrPort) {\n workerData.hmrPort.on('message', (msg: { type: string; path: string; routes?: string[] }) => {\n if(msg.type === 'HMR_UPDATE') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.set(normalizedPath, { \n timestamp: Date.now(), \n invalidated: true,\n routes: msg.routes || []\n });\n } else if(msg.type === 'HMR_ACCEPT') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.delete(normalizedPath);\n }\n });\n }\n} else {\n throw new Error(\"This module must be run with workerData\");\n}\n\n// Create shared CSS registry\nexport const clientFiles = new Set<string>();\nexport const serverActionFiles = new Set<string>();\n\n// Helper functions\nexport function clearCssFiles() {\n cssFiles.clear();\n}\n\nexport function getCssFiles() {\n return cssFiles.entries();\n}\n\nexport function clearClientFiles() {\n clientFiles.clear();\n}\n\nexport function clearServerActionFiles() {\n serverActionFiles.clear();\n}\n\nexport function addCssFile(id: string, cssFile: CssContent) {\n cssFiles.set(id, cssFile);\n}\n\n\nexport function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, \"projectRoot\" | \"moduleBaseURL\" | \"moduleBasePath\" | \"moduleRootPath\" | \"css\">) {\n if(typeof code !== \"string\"){\n throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);\n }\n const normalizeId = id.startsWith(userOptions.moduleRootPath) ? id.slice(userOptions.moduleRootPath.length) : id;\n cssFiles.set(normalizeId, createCssProps({\n id,\n code,\n userOptions\n }));\n} \n\nexport function addClientFile(url: string) {\n clientFiles.add(url);\n}\n\nexport function addServerActionFile(url: string) {\n serverActionFiles.add(url);\n}\n\nexport function clearAllFiles() {\n clearCssFiles();\n clearClientFiles();\n clearServerActionFiles();\n}\n\n// Helper to check if a module is invalidated\nexport function isModuleInvalidated(path: string): boolean {\n const state = hmrState.get(path);\n return state?.invalidated || false;\n}\n\n// Helper to clear HMR state for a module\nexport function clearHmrState(path: string): void {\n hmrState.delete(path);\n}\n\n// Helper to get all invalidated modules\nexport function getInvalidatedModules(): string[] {\n return Array.from(hmrState.entries())\n .filter(([_, state]) => state.invalidated)\n .map(([path]) => path);\n}\n\nexport function addModuleId(id: string, url: string) {\n moduleIds.set(id, url);\n}\n\nexport function getModuleId(id: string): string | undefined {\n return moduleIds.get(id);\n} "],"names":[],"mappings":";;;;;;;;;AAQa,MAAA,aAAA,uBAAoB,GAAyB;AAG7C,MAAA,QAAA,uBAAe,GAAwB;AAGvC,MAAA,SAAA,uBAAgB,GAAoB;AAEpC,MAAA,QAAA,uBAAe,GAAsB;AAElD,IAAG,UAAY,EAAA;AACb,EAAA,IAAG,WAAW,OAAS,EAAA;AACrB,IAAA,UAAA,CAAW,OAAQ,CAAA,EAAA,CAAG,SAAW,EAAA,CAAC,GAA2D,KAAA;AAC3F,MAAG,IAAA,GAAA,CAAI,SAAS,YAAc,EAAA;AAE5B,QAAA,MAAM,iBAAiB,QAAS,CAAA,UAAA,CAAW,WAAY,CAAA,WAAA,EAAa,IAAI,IAAI,CAAA;AAC5E,QAAA,QAAA,CAAS,IAAI,cAAgB,EAAA;AAAA,UAC3B,SAAA,EAAW,KAAK,GAAI,EAAA;AAAA,UACpB,WAAa,EAAA,IAAA;AAAA,UACb,MAAA,EAAQ,GAAI,CAAA,MAAA,IAAU;AAAC,SACxB,CAAA;AAAA,OACH,MAAA,IAAU,GAAI,CAAA,IAAA,KAAS,YAAc,EAAA;AAEnC,QAAA,MAAM,iBAAiB,QAAS,CAAA,UAAA,CAAW,WAAY,CAAA,WAAA,EAAa,IAAI,IAAI,CAAA;AAC5E,QAAA,QAAA,CAAS,OAAO,cAAc,CAAA;AAAA;AAChC,KACD,CAAA;AAAA;AAEL,CAAO,MAAA;AACL,EAAM,MAAA,IAAI,MAAM,yCAAyC,CAAA;AAC3D;AA4BO,SAAS,iBAAA,CAAkB,EAAY,EAAA,IAAA,EAAc,WAAuH,EAAA;AACjL,EAAG,IAAA,OAAO,SAAS,QAAS,EAAA;AAC1B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAkD,+CAAA,EAAA,OAAO,IAAI,CAAE,CAAA,CAAA;AAAA;AAEjF,EAAM,MAAA,WAAA,GAAc,EAAG,CAAA,UAAA,CAAW,WAAY,CAAA,cAAc,CAAI,GAAA,EAAA,CAAG,KAAM,CAAA,WAAA,CAAY,cAAe,CAAA,MAAM,CAAI,GAAA,EAAA;AAC9G,EAAS,QAAA,CAAA,GAAA,CAAI,aAAa,cAAe,CAAA;AAAA,IACvC,EAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,GACD,CAAC,CAAA;AACJ;AAkCO,SAAS,WAAA,CAAY,IAAY,GAAa,EAAA;AACnD,EAAU,SAAA,CAAA,GAAA,CAAI,IAAI,GAAG,CAAA;AACvB;;;;"}
1
+ {"version":3,"file":"state.js","sources":["../../../../plugin/worker/rsc/state.ts"],"sourcesContent":["import { workerData } from \"node:worker_threads\";\nimport { createCssProps } from \"../../helpers/createCssProps.js\";\nimport type { CssContent, ResolvedUserOptions, HmrState } from \"../../types.js\";\nimport type { PassThrough } from \"node:stream\";\nimport { relative } from \"node:path\";\n\n\n// Track active RSC streams\nexport const activeStreams = new Map<string, PassThrough>();\n\n// Track CSS files\nexport const cssFiles = new Map<string, CssContent>();\n\n// Track module IDs\nexport const moduleIds = new Map<string, string>();\n\nexport const hmrState = new Map<string, HmrState>();\n\nif(workerData) {\n if(workerData.hmrPort) {\n workerData.hmrPort.on('message', (msg: { type: string; path: string; routes?: string[] }) => {\n if(msg.type === 'HMR_UPDATE') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.set(normalizedPath, { \n timestamp: Date.now(), \n invalidated: true,\n routes: msg.routes || []\n });\n } else if(msg.type === 'HMR_ACCEPT') {\n // Normalize the path relative to project root\n const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);\n hmrState.delete(normalizedPath);\n }\n });\n }\n} else {\n throw new Error(\"This module must be run with workerData\");\n}\n\n// Create shared CSS registry\nexport const clientFiles = new Set<string>();\nexport const serverActionFiles = new Set<string>();\n\n// Helper functions\nexport function clearCssFiles() {\n cssFiles.clear();\n}\n\nexport function getCssFiles() {\n return cssFiles.entries();\n}\n\nexport function clearClientFiles() {\n clientFiles.clear();\n}\n\nexport function clearServerActionFiles() {\n serverActionFiles.clear();\n}\n\n\n\nexport function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, \"projectRoot\" | \"moduleBaseURL\" | \"moduleBasePath\" | \"moduleRootPath\" | \"css\" | \"normalizer\" | \"moduleID\">) {\n if(typeof code !== \"string\"){\n throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);\n }\n cssFiles.set(id, createCssProps({\n id,\n code,\n userOptions\n }));\n} \n\nexport function addClientFile(url: string) {\n clientFiles.add(url);\n}\n\nexport function addServerActionFile(url: string) {\n serverActionFiles.add(url);\n}\n\nexport function clearAllFiles() {\n clearCssFiles();\n clearClientFiles();\n clearServerActionFiles();\n}\n\n// Helper to check if a module is invalidated\nexport function isModuleInvalidated(path: string): boolean {\n const state = hmrState.get(path);\n return state?.invalidated || false;\n}\n\n// Helper to clear HMR state for a module\nexport function clearHmrState(path: string): void {\n hmrState.delete(path);\n}\n\n// Helper to get all invalidated modules\nexport function getInvalidatedModules(): string[] {\n return Array.from(hmrState.entries())\n .filter(([_, state]) => state.invalidated)\n .map(([path]) => path);\n}\n\nexport function addModuleId(id: string, url: string) {\n moduleIds.set(id, url);\n}\n\nexport function getModuleId(id: string): string | undefined {\n return moduleIds.get(id);\n} "],"names":[],"mappings":";;;;;;;;;AAQa,MAAA,aAAA,uBAAoB,GAAyB;AAG7C,MAAA,QAAA,uBAAe,GA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AA,GAAA,CAAI,IAAI,GAAG,CAAA;AACvB;;;;"}
@@ -0,0 +1,2 @@
1
+ export declare const userOptions: import("../../types.js").ResolvedUserOptions<import("../../types.js").PagePropOpt, import("../../types.js").InlineCssOpt>;
2
+ //# sourceMappingURL=userOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userOptions.d.ts","sourceRoot":"","sources":["../../../../plugin/worker/rsc/userOptions.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW,2HAAgC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * vite-plugin-react-server
3
+ * Copyright (c) Nico Brinkkemper
4
+ * MIT License
5
+ */
6
+ import { resolveOptions } from '../../config/resolveOptions.js';
7
+ import { hydrateUserOptions } from '../../helpers/serializeUserOptions.js';
8
+ import { workerData } from 'node:worker_threads';
9
+
10
+ const userOptionsResult = resolveOptions(hydrateUserOptions(workerData.userOptions));
11
+ if (userOptionsResult.type === "error") {
12
+ throw userOptionsResult.error;
13
+ }
14
+ const userOptions = userOptionsResult.userOptions;
15
+
16
+ export { userOptions };
17
+ //# sourceMappingURL=userOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userOptions.js","sources":["../../../../plugin/worker/rsc/userOptions.ts"],"sourcesContent":["import { resolveOptions } from \"../../config/index.js\";\nimport { hydrateUserOptions } from \"../../helpers/index.js\";\nimport { workerData } from \"node:worker_threads\";\nconst userOptionsResult = resolveOptions(hydrateUserOptions(workerData.userOptions));\nif(userOptionsResult.type === \"error\") {\n throw userOptionsResult.error;\n}\nexport const userOptions = userOptionsResult.userOptions;"],"names":[],"mappings":";;;;;;;;;AAGA,MAAM,iBAAoB,GAAA,cAAA,CAAe,kBAAmB,CAAA,UAAA,CAAW,WAAW,CAAC,CAAA;AACnF,IAAG,iBAAA,CAAkB,SAAS,OAAS,EAAA;AACrC,EAAA,MAAM,iBAAkB,CAAA,KAAA;AAC1B;AACO,MAAM,cAAc,iBAAkB,CAAA;;;;"}
@@ -67,6 +67,7 @@ export type StreamHandlers = {
67
67
  onServerActionResponse?: (id: string, result?: unknown, error?: string) => void;
68
68
  onServerModule?: (id: string, url: string, source: string) => void;
69
69
  onShutdown?: (id: string) => void;
70
+ onCssFile?: (id: string, code: string) => void;
70
71
  };
71
72
  export type RscRenderMessage<T extends PagePropOpt = PagePropOpt> = WorkerMessage & {
72
73
  type: "RSC_RENDER";
@@ -189,7 +190,7 @@ export type HmrAcceptMessage = HmrMessage & {
189
190
  type: "HMR_ACCEPT";
190
191
  routes?: string[];
191
192
  };
192
- export type RscWorkerInputMessage = RscRenderMessage | CssFileMessage | ShutdownMessage | ChunkProcessedMessage | ClientComponentMessage | InitializedReactLoaderMessage | InitializedCssLoaderMessage | ModuleRequestMessage | InitializedRscWorkerLoaderMessage | InitializedEnvLoaderMessage | HmrUpdateMessage | HmrAcceptMessage | HmrCleanupMessage | CleanupCompleteMessage | ServerActionMessage | ServerModuleMessage;
193
+ export type RscWorkerInputMessage = RscRenderMessage | CssFileMessage | ShutdownMessage | ChunkProcessedMessage | ClientComponentMessage | InitializedReactLoaderMessage | InitializedCssLoaderMessage | ModuleRequestMessage | InitializedRscWorkerLoaderMessage | InitializedEnvLoaderMessage | HmrUpdateMessage | HmrAcceptMessage | HmrCleanupMessage | CleanupCompleteMessage | ServerActionMessage | ServerActionResponseMessage | ServerModuleMessage;
193
194
  export interface CssFileRequestMessage extends WorkerMessage {
194
195
  type: "CSS_FILE_REQUEST";
195
196
  id: string;