vite-plugin-react-server 0.3.11 → 0.3.12

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 (220) hide show
  1. package/dist/package.json +15 -11
  2. package/dist/plugin/checkFilesExist.d.ts +2 -2
  3. package/dist/plugin/checkFilesExist.d.ts.map +1 -1
  4. package/dist/plugin/checkFilesExist.js +39 -57
  5. package/dist/plugin/checkFilesExist.js.map +1 -1
  6. package/dist/plugin/collect-css-manifest.d.ts.map +1 -1
  7. package/dist/plugin/collect-css-manifest.js +5 -0
  8. package/dist/plugin/collect-css-manifest.js.map +1 -1
  9. package/dist/plugin/components.js +10 -15
  10. package/dist/plugin/config/createModuleIdGenerator.js +1 -1
  11. package/dist/plugin/config/createModuleIdGenerator.js.map +1 -1
  12. package/dist/plugin/config/defaults.d.ts +5 -14
  13. package/dist/plugin/config/defaults.d.ts.map +1 -1
  14. package/dist/plugin/config/defaults.js +12 -12
  15. package/dist/plugin/config/defaults.js.map +1 -1
  16. package/dist/plugin/config/getPaths.js +1 -1
  17. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  18. package/dist/plugin/config/resolveOptions.js +73 -52
  19. package/dist/plugin/config/resolveOptions.js.map +1 -1
  20. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  21. package/dist/plugin/config/resolveUserConfig.js +53 -65
  22. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  23. package/dist/plugin/helpers/getBundleManifest.d.ts +6 -1
  24. package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -1
  25. package/dist/plugin/helpers/getBundleManifest.js +48 -19
  26. package/dist/plugin/helpers/getBundleManifest.js.map +1 -1
  27. package/dist/plugin/helpers/inputNormalizer.d.ts +1 -2
  28. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  29. package/dist/plugin/helpers/inputNormalizer.js +52 -46
  30. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  31. package/dist/plugin/helpers/tryManifest.d.ts +1 -1
  32. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  33. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  34. package/dist/plugin/loader/createBuildLoader.d.ts +1 -1
  35. package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
  36. package/dist/plugin/loader/createBuildLoader.js +29 -26
  37. package/dist/plugin/loader/createBuildLoader.js.map +1 -1
  38. package/dist/plugin/loader/css-loader.d.ts +16 -0
  39. package/dist/plugin/loader/css-loader.d.ts.map +1 -0
  40. package/dist/plugin/loader/css-loader.js +70 -0
  41. package/dist/plugin/loader/css-loader.js.map +1 -0
  42. package/dist/plugin/loader/react-loader.d.ts +17 -0
  43. package/dist/plugin/loader/react-loader.d.ts.map +1 -0
  44. package/dist/plugin/loader/react-loader.js +647 -0
  45. package/dist/plugin/loader/react-loader.js.map +1 -0
  46. package/dist/plugin/loader/rsc/messageHandler.d.ts +2 -0
  47. package/dist/plugin/loader/rsc/messageHandler.d.ts.map +1 -0
  48. package/dist/plugin/loader/rsc/messageHandler.js +1 -0
  49. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts +2 -0
  50. package/dist/plugin/loader/rsc/rsc-worker.development.d.ts.map +1 -0
  51. package/dist/plugin/loader/rsc/rsc-worker.development.js +1 -0
  52. package/dist/plugin/react-client/index.js +2 -2
  53. package/dist/plugin/react-client/index.js.map +1 -1
  54. package/dist/plugin/react-client/plugin.d.ts.map +1 -1
  55. package/dist/plugin/react-client/plugin.js +202 -25
  56. package/dist/plugin/react-client/plugin.js.map +1 -1
  57. package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
  58. package/dist/plugin/react-server/createHandler.js +10 -4
  59. package/dist/plugin/react-server/createHandler.js.map +1 -1
  60. package/dist/plugin/react-server/createRscStream.d.ts +15 -3
  61. package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
  62. package/dist/plugin/react-server/createRscStream.js +52 -49
  63. package/dist/plugin/react-server/createRscStream.js.map +1 -1
  64. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  65. package/dist/plugin/react-server/plugin.js +24 -20
  66. package/dist/plugin/react-server/plugin.js.map +1 -1
  67. package/dist/plugin/transformer/plugin.d.ts.map +1 -1
  68. package/dist/plugin/transformer/plugin.js +65 -52
  69. package/dist/plugin/transformer/plugin.js.map +1 -1
  70. package/dist/plugin/types.d.ts +5 -0
  71. package/dist/plugin/types.d.ts.map +1 -1
  72. package/dist/plugin/utils/logger.d.ts +9 -0
  73. package/dist/plugin/utils/logger.d.ts.map +1 -0
  74. package/dist/plugin/utils/logger.js +68 -0
  75. package/dist/plugin/utils/logger.js.map +1 -0
  76. package/dist/plugin/worker/createWorker.d.ts +1 -0
  77. package/dist/plugin/worker/createWorker.d.ts.map +1 -1
  78. package/dist/plugin/worker/createWorker.js +23 -36
  79. package/dist/plugin/worker/createWorker.js.map +1 -1
  80. package/dist/plugin/worker/html/html-worker.production.js +5 -1
  81. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  82. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  83. package/dist/plugin/worker/html/messageHandler.js +10 -19
  84. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  85. package/dist/plugin/worker/html/renderPages.d.ts +2 -2
  86. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  87. package/dist/plugin/worker/html/renderPages.js +130 -131
  88. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  89. package/dist/plugin/worker/rsc/index.d.ts +1 -3
  90. package/dist/plugin/worker/rsc/index.d.ts.map +1 -1
  91. package/dist/plugin/worker/rsc/index.js +1 -9
  92. package/dist/plugin/worker/rsc/index.js.map +1 -1
  93. package/dist/plugin/worker/rsc/messageHandler.d.ts +3 -0
  94. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -0
  95. package/dist/plugin/worker/rsc/messageHandler.js +107 -0
  96. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -0
  97. package/dist/plugin/worker/rsc/plugin.d.ts.map +1 -1
  98. package/dist/plugin/worker/rsc/plugin.js +74 -80
  99. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts +32 -0
  100. package/dist/plugin/worker/rsc/rsc-worker.development.d.ts.map +1 -0
  101. package/dist/plugin/worker/rsc/rsc-worker.development.js +43 -0
  102. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -0
  103. package/dist/plugin/worker/rsc/rsc-worker.js +4 -106
  104. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts +2 -0
  105. package/dist/plugin/worker/rsc/rsc-worker.production.d.ts.map +1 -0
  106. package/dist/plugin/worker/rsc/rsc-worker.production.js +14 -0
  107. package/dist/plugin/worker/rsc/rsc-worker.production.js.map +1 -0
  108. package/dist/plugin/worker/rsc/state.d.ts +11 -0
  109. package/dist/plugin/worker/rsc/state.d.ts.map +1 -0
  110. package/dist/plugin/worker/rsc/state.js +12 -0
  111. package/dist/plugin/worker/rsc/state.js.map +1 -0
  112. package/dist/plugin/worker/types.d.ts +60 -46
  113. package/dist/plugin/worker/types.d.ts.map +1 -1
  114. package/dist/tsconfig.tsbuildinfo +1 -1
  115. package/package.json +15 -11
  116. package/plugin/checkFilesExist.ts +42 -62
  117. package/plugin/collect-css-manifest.ts +5 -1
  118. package/plugin/config/createModuleIdGenerator.ts +1 -1
  119. package/plugin/config/defaults.ts +13 -15
  120. package/plugin/config/resolveOptions.ts +134 -76
  121. package/plugin/config/resolveUserConfig.ts +75 -76
  122. package/plugin/helpers/getBundleManifest.ts +69 -31
  123. package/plugin/helpers/inputNormalizer.ts +82 -70
  124. package/plugin/helpers/tryManifest.ts +1 -1
  125. package/plugin/loader/createBuildLoader.ts +38 -41
  126. package/plugin/loader/css-loader.ts +96 -0
  127. package/plugin/loader/react-loader.ts +945 -0
  128. package/plugin/loader/rsc/messageHandler.tsx +1 -0
  129. package/plugin/loader/rsc/rsc-worker.development.ts +1 -0
  130. package/plugin/react-client/index.ts +1 -1
  131. package/plugin/react-client/plugin.ts +266 -41
  132. package/plugin/react-server/createHandler.ts +9 -5
  133. package/plugin/react-server/createRscStream.ts +75 -54
  134. package/plugin/react-server/plugin.ts +26 -21
  135. package/plugin/transformer/plugin.ts +67 -76
  136. package/plugin/types/global.d.ts +8 -0
  137. package/plugin/types.ts +2 -0
  138. package/plugin/utils/logger.ts +52 -0
  139. package/plugin/worker/createWorker.ts +43 -44
  140. package/plugin/worker/html/html-worker.production.tsx +7 -2
  141. package/plugin/worker/html/messageHandler.ts +13 -21
  142. package/plugin/worker/html/renderPages.ts +146 -179
  143. package/plugin/worker/rsc/index.ts +4 -13
  144. package/plugin/worker/rsc/messageHandler.tsx +143 -0
  145. package/plugin/worker/rsc/plugin.ts +38 -37
  146. package/plugin/worker/rsc/rsc-worker.development.ts +107 -0
  147. package/plugin/worker/rsc/rsc-worker.production.ts +13 -0
  148. package/plugin/worker/rsc/rsc-worker.tsx +5 -128
  149. package/plugin/worker/rsc/state.ts +37 -0
  150. package/plugin/worker/types.ts +79 -55
  151. package/scripts/check-react-version.mjs +17 -7
  152. package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +143 -4170
  153. package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +14271 -90079
  154. package/dist/plugin/components.js.map +0 -1
  155. package/dist/plugin/helpers/createClientInputNormalizer.d.ts +0 -8
  156. package/dist/plugin/helpers/createClientInputNormalizer.d.ts.map +0 -1
  157. package/dist/plugin/helpers/createClientInputNormalizer.js +0 -35
  158. package/dist/plugin/helpers/createServerInputNormalizer.d.ts +0 -9
  159. package/dist/plugin/helpers/createServerInputNormalizer.d.ts.map +0 -1
  160. package/dist/plugin/helpers/createServerInputNormalizer.js +0 -37
  161. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts +0 -7
  162. package/dist/plugin/helpers/createStaticInputNormalizer.d.ts.map +0 -1
  163. package/dist/plugin/helpers/createStaticInputNormalizer.js +0 -18
  164. package/dist/plugin/helpers/getModuleManifest.d.ts +0 -17
  165. package/dist/plugin/helpers/getModuleManifest.d.ts.map +0 -1
  166. package/dist/plugin/helpers/getModuleManifest.js +0 -23
  167. package/dist/plugin/helpers/inputNormalizerWorker.d.ts +0 -12
  168. package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +0 -1
  169. package/dist/plugin/helpers/inputNormalizerWorker.js +0 -33
  170. package/dist/plugin/helpers/normalizedRelativePath.d.ts +0 -11
  171. package/dist/plugin/helpers/normalizedRelativePath.d.ts.map +0 -1
  172. package/dist/plugin/helpers/normalizedRelativePath.js +0 -36
  173. package/dist/plugin/helpers/resolveFilePath.d.ts +0 -13
  174. package/dist/plugin/helpers/resolveFilePath.d.ts.map +0 -1
  175. package/dist/plugin/helpers/resolveFilePath.js +0 -74
  176. package/dist/plugin/helpers/resolveWorkerModule.d.ts +0 -6
  177. package/dist/plugin/helpers/resolveWorkerModule.d.ts.map +0 -1
  178. package/dist/plugin/helpers/resolveWorkerModule.js +0 -24
  179. package/dist/plugin/helpers/validateModuleBase.d.ts +0 -3
  180. package/dist/plugin/helpers/validateModuleBase.d.ts.map +0 -1
  181. package/dist/plugin/helpers/validateModuleBase.js +0 -16
  182. package/dist/plugin/helpers/validateResolvedConfig.d.ts +0 -3
  183. package/dist/plugin/helpers/validateResolvedConfig.d.ts.map +0 -1
  184. package/dist/plugin/helpers/validateResolvedConfig.js +0 -17
  185. package/dist/plugin/transformer/transformer-client-components.d.ts +0 -30
  186. package/dist/plugin/transformer/transformer-client-components.d.ts.map +0 -1
  187. package/dist/plugin/transformer/transformer-client-components.js +0 -122
  188. package/dist/plugin/transformer/transformer-client-components.js.map +0 -1
  189. package/dist/plugin/transformer/transformer-server-actions.d.ts +0 -29
  190. package/dist/plugin/transformer/transformer-server-actions.d.ts.map +0 -1
  191. package/dist/plugin/transformer/transformer-server-actions.js +0 -90
  192. package/dist/plugin/worker/rsc/createRscStream.d.ts +0 -5
  193. package/dist/plugin/worker/rsc/createRscStream.d.ts.map +0 -1
  194. package/dist/plugin/worker/rsc/createRscStream.js +0 -39
  195. package/dist/plugin/worker/rsc/createRscStream.js.map +0 -1
  196. package/dist/plugin/worker/rsc/development.d.ts +0 -5
  197. package/dist/plugin/worker/rsc/development.d.ts.map +0 -1
  198. package/dist/plugin/worker/rsc/development.js +0 -13
  199. package/dist/plugin/worker/rsc/development.js.map +0 -1
  200. package/dist/plugin/worker/rsc/plugin.js.map +0 -1
  201. package/dist/plugin/worker/rsc/production.d.ts +0 -5
  202. package/dist/plugin/worker/rsc/production.d.ts.map +0 -1
  203. package/dist/plugin/worker/rsc/production.js +0 -13
  204. package/dist/plugin/worker/rsc/production.js.map +0 -1
  205. package/plugin/helpers/createClientInputNormalizer.ts +0 -48
  206. package/plugin/helpers/createServerInputNormalizer.ts +0 -52
  207. package/plugin/helpers/createStaticInputNormalizer.ts +0 -26
  208. package/plugin/helpers/getModuleManifest.ts +0 -36
  209. package/plugin/helpers/inputNormalizerWorker.ts +0 -52
  210. package/plugin/helpers/normalizedRelativePath.ts +0 -59
  211. package/plugin/helpers/resolveFilePath.ts +0 -108
  212. package/plugin/helpers/resolveWorkerModule.ts +0 -41
  213. package/plugin/helpers/validateModuleBase.ts +0 -30
  214. package/plugin/helpers/validateResolvedConfig.ts +0 -21
  215. package/plugin/transformer/transformer-client-components.ts +0 -168
  216. package/plugin/transformer/transformer-server-actions.ts +0 -125
  217. package/plugin/worker/rsc/createRscStream.ts +0 -42
  218. package/plugin/worker/rsc/development.ts +0 -6
  219. package/plugin/worker/rsc/production.ts +0 -6
  220. package/scripts/react-server-dom-esm+0.0.1.patch +0 -24775
@@ -0,0 +1,107 @@
1
+ // no offical types for node:module available yet (23.7.0)
2
+ declare module 'node:module' {
3
+ export interface ImportAttributes {
4
+ [key: string]: string | undefined;
5
+ }
6
+
7
+ export interface ResolveHookContext {
8
+ conditions: string[];
9
+ parentURL: string | undefined;
10
+ importAttributes: ImportAttributes;
11
+ }
12
+
13
+ export interface LoadHookContext {
14
+ conditions: string[];
15
+ format: ModuleFormat | null | undefined;
16
+ importAttributes: ImportAttributes;
17
+ shortCircuit?: boolean;
18
+ }
19
+
20
+ export interface ResolveResult {
21
+ url: string;
22
+ shortCircuit: boolean;
23
+ }
24
+
25
+ export interface LoadResult {
26
+ format: string;
27
+ source: string | SharedArrayBuffer | Uint8Array;
28
+ shortCircuit: boolean;
29
+ }
30
+
31
+ export interface HooksAPI {
32
+ resolve?: (
33
+ specifier: string,
34
+ context: ResolveHookContext,
35
+ nextResolve: (specifier: string, context: ResolveHookContext) => ResolveResult
36
+ ) => ResolveResult;
37
+
38
+ load?: (
39
+ url: string,
40
+ context: LoadHookContext,
41
+ nextLoad: (url: string, context: LoadHookContext) => LoadResult
42
+ ) => LoadResult;
43
+ }
44
+
45
+ export function registerHooks(hooks: HooksAPI): void;
46
+ }
47
+ //
48
+ import { parentPort, MessageChannel } from "node:worker_threads";
49
+ import { messageHandler } from "./messageHandler.js";
50
+ import { createLogger } from "../../utils/logger.js";
51
+ import {
52
+ registerHooks,
53
+ register,
54
+ type ResolveHookContext,
55
+ } from 'node:module';
56
+ import { register as registerTsx } from "tsx/esm/api";
57
+ import { join } from 'node:path';
58
+ import { getPluginRoot } from "../../config/getPaths.js";
59
+
60
+ const ports = new MessageChannel();
61
+ // Initialize worker
62
+ if (!parentPort) {
63
+ throw new Error("This module must be run as a worker");
64
+ }
65
+
66
+ // Create channels for each loader
67
+ const reactLoaderChannel = new MessageChannel();
68
+ const cssLoaderChannel = new MessageChannel();
69
+
70
+ // Listen for messages from loaders
71
+ reactLoaderChannel.port2.on('message', (msg) => {
72
+ messageHandler(msg);
73
+ });
74
+
75
+ cssLoaderChannel.port2.on('message', (msg) => {
76
+ messageHandler(msg);
77
+ });
78
+
79
+ const loaderPath = 'file://' + join(getPluginRoot(), 'loader/react-loader.js');
80
+ const cssLoaderPath = 'file://' + join(getPluginRoot(), 'loader/css-loader.js');
81
+ console.log('[worker] Full loader path:', loaderPath);
82
+
83
+ // Register react-loader
84
+ register(loaderPath, {
85
+ parentURL: getPluginRoot(),
86
+ data: { port: reactLoaderChannel.port1 },
87
+ transferList: [reactLoaderChannel.port1]
88
+ });
89
+ register(cssLoaderPath, {
90
+ parentURL: getPluginRoot(),
91
+ data: { port: cssLoaderChannel.port1 },
92
+ transferList: [cssLoaderChannel.port1]
93
+ });
94
+
95
+ // Register loaders
96
+ registerTsx();
97
+
98
+ // Set up message handling
99
+ parentPort.on("message", (message) => {
100
+ messageHandler(message);
101
+ });
102
+
103
+ // Signal ready
104
+ parentPort.postMessage({ type: "READY", env: "development" });
105
+
106
+
107
+
@@ -0,0 +1,13 @@
1
+ import { parentPort } from "node:worker_threads";
2
+ import { messageHandler } from "./messageHandler.js";
3
+
4
+
5
+ if (!parentPort) {
6
+ throw new Error("This module must be run as a worker");
7
+ }
8
+
9
+ // Handle incoming messages
10
+ parentPort.on("message", messageHandler);
11
+
12
+ // Signal ready
13
+ parentPort.postMessage({ type: "READY", env: "production" });
@@ -1,128 +1,5 @@
1
- import { createWriteStream } from "node:fs";
2
- import { mkdir } from "node:fs/promises";
3
- import { dirname } from "node:path";
4
- import type { Writable } from "node:stream";
5
- import { parentPort } from "node:worker_threads";
6
- import {
7
- registerClientReference,
8
- registerServerReference
9
- // @ts-ignore
10
- } from "react-server-dom-esm/server.node";
11
-
12
- import type {
13
- RscRenderState,
14
- RscWorkerMessage,
15
- RscWorkerResponse
16
- } from "../types.js";
17
- import { createRscStream } from "./createRscStream.js";
18
-
19
- if (!parentPort) {
20
- throw new Error("This module must be run as a worker");
21
- }
22
-
23
- // Track active renders
24
- const activeRenders = new Map<string, RscRenderState>();
25
- const activeStreams = new Map<string, ReturnType<typeof createRscStream>>();
26
- const activeWrites = new Map<string, Writable>();
27
-
28
- async function shutdown() {
29
- console.log("[RSC Worker] Shutting down forcefully");
30
- for (const stream of activeStreams.values()) {
31
- stream.abort();
32
- }
33
- for (const writeStream of activeWrites.values()) {
34
- writeStream.destroy();
35
- }
36
- process.exit(0);
37
- }
38
-
39
- function sendMessage(message: RscWorkerResponse) {
40
- parentPort?.postMessage(message);
41
- }
42
-
43
- // Handle incoming messages
44
- parentPort.on("message", async (message: RscWorkerMessage) => {
45
- if (message.type === "SHUTDOWN") {
46
- await shutdown();
47
- return;
48
- }
49
-
50
- try {
51
- switch (message.type) {
52
- case "RSC_RENDER": {
53
- const { id, pageImport, propsImport, outDir, moduleRootPath, moduleBaseURL, pipableStreamOptions } = message;
54
-
55
- // Skip if already rendered
56
- if (activeRenders.has(id)) return;
57
-
58
- // Create render state
59
- const renderState: RscRenderState = {
60
- id,
61
- outDir,
62
- moduleRootPath,
63
- moduleBaseURL,
64
- rscOutputPath: `${outDir}/${id}.rsc`,
65
- componentImport: pageImport,
66
- propsImport,
67
- pipableStreamOptions
68
- };
69
-
70
- // Ensure output directory exists
71
- await mkdir(dirname(renderState.rscOutputPath), { recursive: true });
72
- const writeStream = createWriteStream(renderState.rscOutputPath);
73
-
74
- // Create stream
75
- const stream = createRscStream(renderState, writeStream, parentPort);
76
-
77
- // Track active streams
78
- activeRenders.set(id, renderState);
79
- activeStreams.set(id, stream);
80
- activeWrites.set(id, writeStream);
81
- break;
82
- }
83
-
84
- case "RSC_END": {
85
- const { id } = message;
86
- activeRenders.delete(id);
87
- activeStreams.delete(id);
88
- activeWrites.delete(id);
89
- break;
90
- }
91
-
92
- case "CLIENT_REFERENCE": {
93
- const { id, location, key } = message;
94
- const ref = registerClientReference(id, location, key);
95
- sendMessage({
96
- type: "CLIENT_REFERENCE",
97
- id,
98
- location,
99
- key,
100
- ref
101
- });
102
- break;
103
- }
104
-
105
- case "SERVER_REFERENCE": {
106
- const { id, location, key } = message;
107
- const ref = registerServerReference(id, location, key);
108
- sendMessage({
109
- type: "SERVER_REFERENCE",
110
- id,
111
- location,
112
- key,
113
- ref
114
- });
115
- break;
116
- }
117
- }
118
- } catch (error) {
119
- sendMessage({
120
- type: "ERROR",
121
- id: message.type === "RSC_RENDER" ? message.id : "",
122
- error: error instanceof Error ? error.message : String(error)
123
- });
124
- }
125
- });
126
-
127
- // Signal ready
128
- parentPort.postMessage({ type: "READY" });
1
+ await(
2
+ process.env["NODE_ENV"] === "production"
3
+ ? import("./rsc-worker.production.js")
4
+ : import("./rsc-worker.development.js")
5
+ );
@@ -0,0 +1,37 @@
1
+ import { createLogger } from "../../utils/logger.js";
2
+
3
+
4
+ // Create shared CSS registry
5
+ export const cssFiles = new Map<string, string>();
6
+ export const clientFiles = new Set<string>();
7
+ export const serverActionFiles = new Set<string>();
8
+ // Helper functions
9
+ export function clearCssFiles() {
10
+ cssFiles.clear();
11
+ }
12
+
13
+ export function clearClientFiles() {
14
+ clientFiles.clear();
15
+ }
16
+
17
+ export function clearServerActionFiles() {
18
+ serverActionFiles.clear();
19
+ }
20
+
21
+ export function addCssFile(id: string, cssFile: string) {
22
+ cssFiles.set(id, cssFile);
23
+ }
24
+
25
+ export function addClientFile(url: string) {
26
+ clientFiles.add(url);
27
+ }
28
+
29
+ export function addServerActionFile(url: string) {
30
+ serverActionFiles.add(url);
31
+ }
32
+
33
+ export function clearAllFiles() {
34
+ clearCssFiles();
35
+ clearClientFiles();
36
+ clearServerActionFiles();
37
+ }
@@ -1,5 +1,11 @@
1
1
  import type { Manifest } from "vite";
2
2
 
3
+ // Base message types
4
+ export interface WorkerMessage {
5
+ type: string;
6
+ id: string;
7
+ }
8
+
3
9
  export interface PipeableStreamOptions {
4
10
  bootstrapModules?: string[];
5
11
  bootstrapScripts?: string[];
@@ -17,6 +23,7 @@ export interface PipeableStreamOptions {
17
23
  };
18
24
  }
19
25
 
26
+ // Worker States
20
27
  export interface HtmlRenderState {
21
28
  chunks: string[];
22
29
  complete: boolean;
@@ -31,95 +38,111 @@ export interface HtmlRenderState {
31
38
 
32
39
  export interface RscRenderState {
33
40
  id: string;
34
- pipableStreamOptions: PipeableStreamOptions;
35
41
  outDir: string;
36
42
  moduleRootPath: string;
37
43
  moduleBaseURL: string;
38
44
  rscOutputPath: string;
39
45
  componentImport: string;
40
46
  propsImport: string;
41
- }
42
-
43
- export interface WorkerRscChunkMessage {
44
- type: "RSC_CHUNK";
45
- id: string;
46
- chunk: string;
47
- moduleRootPath: string;
48
- moduleBaseURL: string;
49
- outDir: string;
50
- htmlOutputPath: string;
51
47
  pipableStreamOptions: PipeableStreamOptions;
52
- clientManifest: Manifest; // Add client manifest
53
- serverManifest: Manifest; // Add server manifest
54
48
  }
55
49
 
56
- export interface ShutdownMessage {
50
+ // Common Messages
51
+ export interface ShutdownMessage extends WorkerMessage {
57
52
  type: "SHUTDOWN";
58
- id: string;
59
- }
60
-
61
- export interface ShellReadyMessage {
62
- type: "SHELL_READY";
63
- id: string;
64
53
  }
65
54
 
66
- export interface AllReadyMessage {
67
- type: "ALL_READY";
68
- id: string;
69
- outputPath: string;
70
- html: string;
71
- }
72
-
73
- export interface RscRenderMessage {
55
+ // RSC Messages
56
+ export interface RscRenderMessage extends WorkerMessage {
74
57
  type: "RSC_RENDER";
75
- id: string;
76
58
  pageImport: string;
77
59
  propsImport: string;
60
+ pageExportName: string;
61
+ propsExportName: string;
62
+ url: string;
78
63
  outDir: string;
64
+ projectRoot: string;
79
65
  moduleRootPath: string;
80
66
  moduleBaseURL: string;
67
+ moduleBasePath: string;
81
68
  pipableStreamOptions: PipeableStreamOptions;
69
+ cssFiles: string[];
82
70
  }
83
71
 
84
- export interface RscCompleteMessage {
85
- type: "RSC_COMPLETE";
86
- id: string;
87
- outputPath: string;
72
+ export interface RscChunkMessage extends WorkerMessage {
73
+ type: "RSC_CHUNK";
74
+ chunk: string;
75
+ moduleRootPath: string;
76
+ moduleBaseURL: string;
77
+ outDir: string;
78
+ rscOutputPath: string;
79
+ cssFiles: Array<[string, string]>;
88
80
  }
89
81
 
90
- export interface WorkerErrorMessage {
91
- type: "ERROR";
92
- id: string;
93
- error: string;
82
+ export interface RscShellReadyMessage extends WorkerMessage {
83
+ type: "SHELL_READY";
94
84
  }
95
85
 
96
- export interface RscWroteFileMessage {
97
- type: "WROTE_FILE";
98
- id: string;
86
+ export interface RscAllReadyMessage extends WorkerMessage {
87
+ type: "ALL_READY";
99
88
  outputPath: string;
89
+ contents: string;
100
90
  }
101
91
 
102
- export interface RscEndMessage {
92
+ export interface RscEndMessage extends WorkerMessage {
103
93
  type: "RSC_END";
104
- id: string;
105
94
  }
106
95
 
107
- export interface ClientReferenceMessage {
96
+ export interface RscErrorMessage extends WorkerMessage {
97
+ type: "ERROR";
98
+ error: string;
99
+ }
100
+
101
+ export interface ClientReferenceMessage extends WorkerMessage {
108
102
  type: "CLIENT_REFERENCE";
109
- id: string;
110
103
  location: string;
111
104
  key: string;
112
105
  ref: unknown;
113
106
  }
114
107
 
115
- export interface ServerReferenceMessage {
108
+ export interface ServerReferenceMessage extends WorkerMessage {
116
109
  type: "SERVER_REFERENCE";
117
- id: string;
118
110
  location: string;
119
111
  key: string;
120
112
  ref: unknown;
121
113
  }
122
114
 
115
+ // HTML Messages
116
+ export interface WorkerRscChunkMessage extends WorkerMessage {
117
+ type: "RSC_CHUNK";
118
+ chunk: string;
119
+ moduleRootPath: string;
120
+ moduleBaseURL: string;
121
+ outDir: string;
122
+ htmlOutputPath: string;
123
+ pipableStreamOptions: PipeableStreamOptions;
124
+ clientManifest: Manifest;
125
+ serverManifest: Manifest;
126
+ }
127
+
128
+ export interface ShellReadyMessage extends WorkerMessage {
129
+ type: "SHELL_READY";
130
+ }
131
+
132
+ export interface AllReadyMessage extends WorkerMessage {
133
+ type: "ALL_READY";
134
+ outputPath: string;
135
+ html: string;
136
+ }
137
+
138
+ export interface CssFileMessage extends WorkerMessage {
139
+ type: "CSS_FILE";
140
+ id: string;
141
+ cssFile: string;
142
+ moduleClasses?: Record<string, string>;
143
+ }
144
+
145
+ // Message Unions
123
146
  export type HtmlWorkerMessage =
124
147
  | WorkerRscChunkMessage
125
148
  | RscEndMessage
@@ -127,19 +150,20 @@ export type HtmlWorkerMessage =
127
150
 
128
151
  export type HtmlWorkerResponse =
129
152
  | ShellReadyMessage
130
- | AllReadyMessage
131
- | WorkerErrorMessage
132
-
153
+ | AllReadyMessage
154
+ | RscErrorMessage;
155
+
133
156
  export type RscWorkerMessage =
134
157
  | RscRenderMessage
158
+ | RscChunkMessage
135
159
  | RscEndMessage
136
160
  | ShutdownMessage
137
161
  | ClientReferenceMessage
138
- | ServerReferenceMessage;
162
+ | ServerReferenceMessage
163
+ | CssFileMessage;
139
164
 
140
165
  export type RscWorkerResponse =
141
- | RscCompleteMessage
142
- | WorkerErrorMessage
143
- | RscWroteFileMessage
144
- | ClientReferenceMessage
145
- | ServerReferenceMessage;
166
+ | RscShellReadyMessage
167
+ | RscAllReadyMessage
168
+ | RscErrorMessage
169
+ | CssFileMessage;
@@ -2,10 +2,14 @@
2
2
  import fs from 'node:fs/promises'
3
3
  import path from 'node:path'
4
4
  import { fileURLToPath } from 'node:url'
5
+ import React from 'react'
5
6
 
6
7
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
8
 
8
9
  const TEMPLATE_VERSION = '0.0.0-experimental-b3a95caf-20250113'
10
+ const ACTUAL_TEMPLATE_VERSION = '19.1.0-experimental-b3a95caf-20250113'
11
+ const TARGET_VERSION = '0.0.0-experimental-e670e72f-20250214'
12
+ const ACTUAL_TARGET_VERSION = '19.1.0-experimental-e670e72f-20250214'
9
13
  const STUB_VERSION = '0.0.1'
10
14
 
11
15
  async function main() {
@@ -13,13 +17,17 @@ async function main() {
13
17
  const reactPkgPath = path.resolve(process.cwd(), 'node_modules/react/package.json')
14
18
  const reactPkg = JSON.parse(await fs.readFile(reactPkgPath, 'utf-8'))
15
19
  const userPkg = JSON.parse(await fs.readFile(path.resolve(process.cwd(), 'package.json'), 'utf-8'))
16
- const patchVersion = reactPkg.version
20
+ const patchVersion = React.version
21
+
17
22
  let userVersion = userPkg.dependencies?.react ?? userPkg.devDependencies?.react ?? userPkg.peerDependencies?.react
18
23
  if(!userVersion) {
19
24
  throw new Error('React version not found in package.json')
20
25
  } else {
21
26
  userVersion = userVersion.replace('^', '')
22
27
  }
28
+ if(userVersion !== TARGET_VERSION) {
29
+ throw new Error(`React patch was made for version ${ACTUAL_TARGET_VERSION}, but you installed version ${userVersion}`)
30
+ }
23
31
  // Define patches to process
24
32
  const patches = [
25
33
  {
@@ -43,18 +51,20 @@ async function main() {
43
51
  // Process each patch
44
52
  for (const {template, output} of patches) {
45
53
  let patchContent = await fs.readFile(template, 'utf-8')
46
-
47
- // Replace versions
48
- patchContent = patchContent
49
- .replace(new RegExp(TEMPLATE_VERSION, 'g'), patchVersion)
50
-
51
54
  // Write patched file
52
55
  const outputPath = path.resolve(userPatchesDir, output)
53
56
  await fs.writeFile(outputPath, patchContent)
54
57
  console.log(`Wrote patch file to ${outputPath}`)
55
58
  }
56
59
 
57
- console.log(`Updated patches to match React version ${userVersion} (actual version: ${patchVersion})`)
60
+ console.log(`React version check result:
61
+ userVersion: ${userVersion}
62
+ patchVersion: ${patchVersion}
63
+ ACTUAL_TARGET_VERSION: ${ACTUAL_TARGET_VERSION}
64
+ ACTUAL_TEMPLATE_VERSION: ${ACTUAL_TEMPLATE_VERSION}
65
+ TARGET_VERSION: ${TARGET_VERSION}
66
+ TEMPLATE_VERSION: ${TEMPLATE_VERSION}
67
+ `)
58
68
  }
59
69
 
60
70
  const PATCH = ``