vite-plugin-react-server 0.3.14 → 0.3.17

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 (43) hide show
  1. package/bin/patch.mjs +12 -19
  2. package/dist/package.json +8 -8
  3. package/dist/plugin/collect-css-manifest.js +5 -4
  4. package/dist/plugin/collect-css-manifest.js.map +1 -1
  5. package/dist/plugin/config/defaults.d.ts +3 -3
  6. package/dist/plugin/config/defaults.js +3 -3
  7. package/dist/plugin/config/defaults.js.map +1 -1
  8. package/dist/plugin/react-server/plugin.d.ts.map +1 -1
  9. package/dist/plugin/react-server/plugin.js +3 -9
  10. package/dist/plugin/react-server/plugin.js.map +1 -1
  11. package/dist/plugin/resolveProps.d.ts.map +1 -1
  12. package/dist/plugin/resolveProps.js +1 -0
  13. package/dist/plugin/resolveProps.js.map +1 -1
  14. package/dist/plugin/worker/createWorker.js +2 -2
  15. package/dist/plugin/worker/createWorker.js.map +1 -1
  16. package/dist/plugin/worker/html/html-worker.production.js +5 -0
  17. package/dist/plugin/worker/html/html-worker.production.js.map +1 -1
  18. package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
  19. package/dist/plugin/worker/html/messageHandler.js.map +1 -1
  20. package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
  21. package/dist/plugin/worker/html/renderPages.js +2 -2
  22. package/dist/plugin/worker/html/renderPages.js.map +1 -1
  23. package/dist/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +8 -8
  25. package/plugin/collect-css-manifest.ts +6 -6
  26. package/plugin/config/defaults.ts +3 -3
  27. package/plugin/react-server/plugin.ts +4 -9
  28. package/plugin/resolveProps.ts +1 -0
  29. package/plugin/worker/createWorker.ts +1 -1
  30. package/plugin/worker/html/html-worker.production.tsx +5 -0
  31. package/plugin/worker/html/messageHandler.ts +0 -2
  32. package/plugin/worker/html/renderPages.ts +2 -3
  33. package/scripts/check-react-version.mjs +8 -26
  34. package/scripts/react+0.0.0-experimental-eda36a1c-20250228.patch +57 -0
  35. package/scripts/react-dom+0.0.0-experimental-eda36a1c-20250228.patch +552 -0
  36. package/scripts/{react-server-dom-esm+0.0.0-experimental-b3a95caf-20250113.patch → react-server-dom-esm+0.0.0-experimental-eda36a1c-20250228.patch} +103 -82
  37. package/tsconfig.json +1 -1
  38. package/dist/plugin/server.d.ts +0 -2
  39. package/dist/plugin/server.d.ts.map +0 -1
  40. package/dist/plugin/server.js +0 -1
  41. package/plugin/server.tsx +0 -0
  42. package/scripts/react+0.0.0-experimental-b3a95caf-20250113.patch +0 -264
  43. package/scripts/react-dom+0.0.0-experimental-b3a95caf-20250113.patch +0 -32990
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-server",
3
- "version": "0.3.14",
3
+ "version": "0.3.17",
4
4
  "description": "Vite plugin for React Server Components (RSC)",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin/index.js",
@@ -62,12 +62,13 @@
62
62
  "test": "npm run build && npm run test:client && NODE_ENV=development npm run test:server",
63
63
  "test:coverage": "vitest run --coverage",
64
64
  "test:ui": "vitest --ui",
65
- "experimental:clean-install": "npm install react-server-dom-esm react@experimental react-dom@experimental",
65
+ "experimental:clean-install": "npm install react-server-dom-esm react@experimental react-dom@experimental && npm install react-server-dom-esm",
66
66
  "experimental:copy": "cp -r ./oss-experimental/* ./node_modules/",
67
67
  "experimental:patch": "npx patch-package react-server-dom-esm react react-dom --exclude 'nothing'",
68
68
  "experimental:move-patches": "mv patches/* ./scripts/",
69
- "experimental:setup": "rm -rf patches/* && npm run experimental:clean-install && npm run experimental:copy && npm run experimental:patch && npm run experimental:move-patches && node scripts/check-react-version.mjs",
70
- "postinstall": "npm install react-server-dom-esm && node scripts/check-react-version.mjs && patch-package"
69
+ "experimental:setup": "rm -rf patches/* && npm run experimental:clean-install && npm run experimental:copy && npm run experimental:patch && npm run experimental:move-patches",
70
+ "experimental:patch-react": "npm run experimental:clean-install && node scripts/check-react-version.mjs && node bin/patch.mjs",
71
+ "postinstall": "patch-package"
71
72
  },
72
73
  "keywords": [
73
74
  "vite",
@@ -90,8 +91,8 @@
90
91
  },
91
92
  "homepage": "https://github.com/nicobrinkkemper/vite-plugin-react-server#readme",
92
93
  "peerDependencies": {
93
- "react": "*",
94
- "react-dom": "*",
94
+ "react": "^0.0.0-experimental-d55cc79b-20250228",
95
+ "react-dom": "^0.0.0-experimental-d55cc79b-20250228",
95
96
  "vite": "*"
96
97
  },
97
98
  "peerDependenciesMeta": {
@@ -109,9 +110,8 @@
109
110
  "@types/react": "^19.0.8",
110
111
  "@types/react-dom": "^19.0.3",
111
112
  "acorn-loose": "^8.3.0",
113
+ "happy-dom": "^17.1.8",
112
114
  "patch-package": "^8.0.0",
113
- "react": "^0.0.0-experimental-e670e72f-20250214",
114
- "react-dom": "^0.0.0-experimental-e670e72f-20250214",
115
115
  "react-server-dom-esm": "^0.0.1",
116
116
  "rollup": "^4.34.0",
117
117
  "source-map": "^0.7.4",
@@ -33,13 +33,12 @@ export function collectManifestCss(
33
33
  onCss?: (path: string, parentUrl: string) => void,
34
34
  parentUrl?: string
35
35
  ) {
36
- const relativePagePath = pagePath.startsWith(root + "/")
37
- ? pagePath.slice(root.length + 1)
36
+ const relativePagePath = root !== "" && pagePath.startsWith(root.endsWith('/') ? root : root + '/')
37
+ ? pagePath.slice(root.length + (root.endsWith('/') ? 0 : 1))
38
38
  : pagePath;
39
- if (!relativePagePath) return new Map<string, string>();
40
39
  const cssFiles = new Map<string, string>();
41
40
  const seen = new Set<string>();
42
-
41
+ const manifestValues = Object.values(manifest);
43
42
  const walkManifestEntry = (id: string) => {
44
43
  if (seen.has(id)) return;
45
44
  seen.add(id);
@@ -54,13 +53,14 @@ export function collectManifestCss(
54
53
  return;
55
54
  }
56
55
  // Get the manifest entry
57
- const entry = manifest[id];
56
+ const entry = manifest[id] ?? manifestValues.find(e => e.file === id);
58
57
  if (!entry) return;
59
58
 
60
59
  // Add direct CSS
61
60
  if (entry.css) {
62
61
  entry.css.forEach((css: string) => {
63
- cssFiles.set(entry.file, css);
62
+ console.log('collectManifestCss', css, entry.src ?? entry.file ?? '');
63
+ cssFiles.set(entry.src ?? entry.file ?? '', css);
64
64
  onCss?.(css, parentUrl ?? pagePath);
65
65
  });
66
66
  }
@@ -11,9 +11,9 @@ export const DEFAULT_CONFIG = {
11
11
  SERVER_ENTRY: "src/server.tsx",
12
12
  PAGE_EXPORT_NAME: "Page",
13
13
  PROPS_EXPORT_NAME: "props",
14
- HTML_WORKER_PATH: `worker/html/html-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
15
- RSC_WORKER_PATH: `worker/rsc/rsc-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
16
- LOADER_PATH: 'worker/loader.js',
14
+ HTML_WORKER_PATH: `node_modules/vite-plugin-react-server/dist/plugin/worker/html/html-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
15
+ RSC_WORKER_PATH: `node_modules/vite-plugin-react-server/dist/plugin/worker/rsc/rsc-worker.${process.env['NODE_ENV'] === 'development' ? 'development' : 'production'}.js`,
16
+ LOADER_PATH: 'node_modules/vite-plugin-react-server/dist/plugin/worker/loader.js',
17
17
  RSC_EXTENSION: ".rsc",
18
18
  HTML: ({ children }: { children: any }) => children,
19
19
  COLLECT_CSS: true,
@@ -286,16 +286,11 @@ export function reactServerPlugin(
286
286
 
287
287
  const clientManifest = clientManifestResult.manifest;
288
288
 
289
- // Initialize worker
290
- const htmlWorkerPath = join(
291
- getPluginRoot(),
292
- DEFAULT_CONFIG.HTML_WORKER_PATH
293
- );
294
289
 
295
290
  worker = await createWorker({
296
291
  projectRoot: root,
297
- workerPath: htmlWorkerPath,
298
- condition: "react-server",
292
+ workerPath: userOptions.htmlWorkerPath,
293
+ condition: 'react-server',
299
294
  reverseCondition: true,
300
295
  mode: (resolvedConfig?.mode ?? "production") as
301
296
  | "production"
@@ -402,13 +397,13 @@ export function reactServerPlugin(
402
397
  {
403
398
  pipableStreamOptions: {
404
399
  bootstrapModules: clientManifest["index.html"]?.file
405
- ? [clientManifest["index.html"].file]
400
+ ? [clientManifest["index.html"].file.startsWith('/') ? clientManifest["index.html"].file : '/' + clientManifest["index.html"].file]
406
401
  : [],
407
402
  },
408
403
  moduleBasePath: "",
409
404
  moduleBaseURL: "",
410
405
  clientCss: clientManifest["index.html"]?.css
411
- ? clientManifest["index.html"].css
406
+ ? clientManifest["index.html"].css.map(css => css.startsWith('/') ? css : '/' + css)
412
407
  : [],
413
408
  userConfig,
414
409
  pluginOptions: userOptions,
@@ -81,6 +81,7 @@ export async function resolveProps({
81
81
  ),
82
82
  };
83
83
  } catch (error) {
84
+ console.trace(error);
84
85
  console.warn(found, "error in resolveProps", propsModule, url, path);
85
86
  return {
86
87
  type: "error",
@@ -53,7 +53,7 @@ export async function createWorker(options: CreateWorkerOptions) {
53
53
 
54
54
  // Create worker with proper environment
55
55
  const worker = new Worker(
56
- workerPath.startsWith("/") ? workerPath : join(projectRoot, workerPath),
56
+ workerPath.startsWith("/") ? workerPath : './' + workerPath,
57
57
  {
58
58
  env,
59
59
  resourceLimits,
@@ -1,5 +1,10 @@
1
1
  import { messageHandler } from "./messageHandler.js";
2
2
  import { parentPort } from "node:worker_threads";
3
+ import { Window } from 'happy-dom';
4
+ const window = new Window({ url: 'https://localhost:8080' });
5
+ const document = window.document;
6
+ globalThis.window = window as any;
7
+ globalThis.document = document as any;
3
8
 
4
9
  let ready = false;
5
10
  if (!parentPort) throw new Error("This module must be run as a worker");
@@ -13,8 +13,6 @@ import { join } from "path";
13
13
  const activeRenders = new Map<string, HtmlRenderState>();
14
14
  const htmlContent = new Map<string, string>();
15
15
  const htmlPromises = new Map<string, Promise<string>>();
16
-
17
-
18
16
  export const messageHandler = async (message: HtmlWorkerMessage) => {
19
17
  try {
20
18
  switch (message.type) {
@@ -92,7 +92,7 @@ export async function renderPages(
92
92
  });
93
93
  });
94
94
 
95
- collectManifestCss(
95
+ const newCssFiles = collectManifestCss(
96
96
  options.clientManifest,
97
97
  options.moduleBasePath,
98
98
  'index.html',
@@ -125,7 +125,6 @@ export async function renderPages(
125
125
  }
126
126
  }
127
127
  );
128
-
129
128
  // Create handler for pure RSC output
130
129
  const rscResult = await createHandler(route, {
131
130
  ...options.pluginOptions,
@@ -134,7 +133,7 @@ export async function renderPages(
134
133
  loader: options.loader,
135
134
  clientManifest: options.clientManifest,
136
135
  serverManifest: options.serverManifest,
137
- cssFiles: clientCss,
136
+ cssFiles: Array.from(newCssFiles.values()).concat(clientCss),
138
137
  pipableStreamOptions: {
139
138
  ...options.pipableStreamOptions,
140
139
  importMap: {
@@ -6,28 +6,18 @@ import React from 'react'
6
6
 
7
7
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
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
+ const TEMPLATE_VERSION = '0.0.0-experimental-eda36a1c-20250228'
13
10
  const STUB_VERSION = '0.0.1'
14
11
 
15
12
  async function main() {
16
13
  // Read installed React version
17
- const reactPkgPath = path.resolve(process.cwd(), 'node_modules/react/package.json')
18
- const reactPkg = JSON.parse(await fs.readFile(reactPkgPath, 'utf-8'))
19
- const userPkg = JSON.parse(await fs.readFile(path.resolve(process.cwd(), 'package.json'), 'utf-8'))
20
14
  const patchVersion = React.version
15
+ const PATCH_RECONCILER_VERSION = patchVersion.replace('19.1.0', '0.0.0')
16
+ if(TEMPLATE_VERSION === PATCH_RECONCILER_VERSION) {
17
+ console.log('React version is already patched')
18
+ return;
19
+ }
21
20
 
22
- let userVersion = userPkg.dependencies?.react ?? userPkg.devDependencies?.react ?? userPkg.peerDependencies?.react
23
- if(!userVersion) {
24
- throw new Error('React version not found in package.json')
25
- } else {
26
- userVersion = userVersion.replace('^', '')
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
- }
31
21
  // Define patches to process
32
22
  const patches = [
33
23
  {
@@ -36,11 +26,11 @@ async function main() {
36
26
  },
37
27
  {
38
28
  template: path.resolve(__dirname, `react+${TEMPLATE_VERSION}.patch`),
39
- output: `react+${userVersion}.patch`
29
+ output: `react+${PATCH_RECONCILER_VERSION}.patch`
40
30
  },
41
31
  {
42
32
  template: path.resolve(__dirname, `react-dom+${TEMPLATE_VERSION}.patch`),
43
- output: `react-dom+${userVersion}.patch`
33
+ output: `react-dom+${PATCH_RECONCILER_VERSION}.patch`
44
34
  }
45
35
  ]
46
36
 
@@ -57,14 +47,6 @@ async function main() {
57
47
  console.log(`Wrote patch file to ${outputPath}`)
58
48
  }
59
49
 
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
- `)
68
50
  }
69
51
 
70
52
  const PATCH = ``
@@ -0,0 +1,57 @@
1
+ diff --git a/node_modules/react/cjs/react.development.js b/node_modules/react/cjs/react.development.js
2
+ index 9aa7fdf..2bc8270 100644
3
+ --- a/node_modules/react/cjs/react.development.js
4
+ +++ b/node_modules/react/cjs/react.development.js
5
+ @@ -1277,7 +1277,7 @@
6
+ exports.useTransition = function () {
7
+ return resolveDispatcher().useTransition();
8
+ };
9
+ - exports.version = "19.1.0-experimental-d55cc79b-20250228";
10
+ + exports.version = "19.1.0-experimental-eda36a1c-20250228";
11
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
12
+ "function" ===
13
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
14
+ diff --git a/node_modules/react/cjs/react.production.js b/node_modules/react/cjs/react.production.js
15
+ index 3678d50..24d6e95 100644
16
+ --- a/node_modules/react/cjs/react.production.js
17
+ +++ b/node_modules/react/cjs/react.production.js
18
+ @@ -576,4 +576,4 @@ exports.useSyncExternalStore = function (
19
+ exports.useTransition = function () {
20
+ return ReactSharedInternals.H.useTransition();
21
+ };
22
+ -exports.version = "19.1.0-experimental-d55cc79b-20250228";
23
+ +exports.version = "19.1.0-experimental-eda36a1c-20250228";
24
+ diff --git a/node_modules/react/cjs/react.react-server.development.js b/node_modules/react/cjs/react.react-server.development.js
25
+ index 15d4371..8497113 100644
26
+ --- a/node_modules/react/cjs/react.react-server.development.js
27
+ +++ b/node_modules/react/cjs/react.react-server.development.js
28
+ @@ -981,5 +981,5 @@
29
+ exports.useMemo = function (create, deps) {
30
+ return resolveDispatcher().useMemo(create, deps);
31
+ };
32
+ - exports.version = "19.1.0-experimental-d55cc79b-20250228";
33
+ + exports.version = "19.1.0-experimental-eda36a1c-20250228";
34
+ })();
35
+ diff --git a/node_modules/react/cjs/react.react-server.production.js b/node_modules/react/cjs/react.react-server.production.js
36
+ index 6c7c438..694169d 100644
37
+ --- a/node_modules/react/cjs/react.react-server.production.js
38
+ +++ b/node_modules/react/cjs/react.react-server.production.js
39
+ @@ -561,4 +561,4 @@ exports.useId = function () {
40
+ exports.useMemo = function (create, deps) {
41
+ return ReactSharedInternals.H.useMemo(create, deps);
42
+ };
43
+ -exports.version = "19.1.0-experimental-d55cc79b-20250228";
44
+ +exports.version = "19.1.0-experimental-eda36a1c-20250228";
45
+ diff --git a/node_modules/react/package.json b/node_modules/react/package.json
46
+ index f7c9f76..b6e85b0 100644
47
+ --- a/node_modules/react/package.json
48
+ +++ b/node_modules/react/package.json
49
+ @@ -4,7 +4,7 @@
50
+ "keywords": [
51
+ "react"
52
+ ],
53
+ - "version": "0.0.0-experimental-d55cc79b-20250228",
54
+ + "version": "0.0.0-experimental-eda36a1c-20250228",
55
+ "homepage": "https://react.dev/",
56
+ "bugs": "https://github.com/facebook/react/issues",
57
+ "license": "MIT",