vite-plugin-react-server 1.1.17 → 1.1.18

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 (124) hide show
  1. package/README.md +2 -2
  2. package/dist/package.json +5 -4
  3. package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
  4. package/dist/plugin/components/html.d.ts.map +1 -1
  5. package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -1
  6. package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -1
  7. package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -1
  8. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
  9. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +7 -12
  10. package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
  11. package/dist/plugin/config/autoDiscover/resolveBuildPages.js +2 -2
  12. package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
  13. package/dist/plugin/config/createModuleID.d.ts.map +1 -1
  14. package/dist/plugin/config/defaults.js +16 -2
  15. package/dist/plugin/config/defaults.js.map +1 -1
  16. package/dist/plugin/config/extMap.d.ts.map +1 -1
  17. package/dist/plugin/config/getCondition.d.ts.map +1 -1
  18. package/dist/plugin/config/getPaths.d.ts.map +1 -1
  19. package/dist/plugin/config/mimeTypes.d.ts.map +1 -1
  20. package/dist/plugin/config/mimeTypes.js +67 -0
  21. package/dist/plugin/config/mimeTypes.js.map +1 -1
  22. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -1
  23. package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
  24. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  25. package/dist/plugin/config/resolveOptions.js +1 -1
  26. package/dist/plugin/config/resolveOptions.js.map +1 -1
  27. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  28. package/dist/plugin/config/resolveUserConfig.js +39 -22
  29. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  30. package/dist/plugin/env/plugin.d.ts.map +1 -1
  31. package/dist/plugin/env/plugin.js +35 -2
  32. package/dist/plugin/env.js +37 -3
  33. package/dist/plugin/env.js.map +1 -1
  34. package/dist/plugin/error/toError.js +4 -4
  35. package/dist/plugin/error/toError.js.map +1 -1
  36. package/dist/plugin/helpers/cleanObject.js +2 -2
  37. package/dist/plugin/helpers/cleanObject.js.map +1 -1
  38. package/dist/plugin/helpers/collectManifestCss.js +2 -2
  39. package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
  40. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
  41. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  42. package/dist/plugin/helpers/collectViteModuleGraphCss.js +3 -1
  43. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  44. package/dist/plugin/helpers/createCssProps.d.ts +1 -1
  45. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  46. package/dist/plugin/helpers/createCssProps.js +12 -1
  47. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  48. package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -1
  49. package/dist/plugin/helpers/createEventHandler.js +1 -1
  50. package/dist/plugin/helpers/getBundleManifest.js +1 -1
  51. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
  52. package/dist/plugin/helpers/getRouteFiles.js +2 -2
  53. package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
  54. package/dist/plugin/helpers/inputNormalizer.js +1 -1
  55. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  56. package/dist/plugin/helpers/requestInfo.js +1 -1
  57. package/dist/plugin/helpers/requestInfo.js.map +1 -1
  58. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
  59. package/dist/plugin/helpers/resolveProps.d.ts.map +1 -1
  60. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
  61. package/dist/plugin/helpers/sourceMap.d.ts.map +1 -1
  62. package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -1
  63. package/dist/plugin/helpers/tryManifest.d.ts +3 -1
  64. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  65. package/dist/plugin/helpers/tryManifest.js +14 -8
  66. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  67. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
  68. package/dist/plugin/loader/transformModuleIfNeeded.js +1 -2
  69. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
  70. package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
  71. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
  72. package/dist/plugin/react-client/configureWorkerRequestHandler.js +14 -18
  73. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
  74. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  75. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
  76. package/dist/plugin/react-server/configureReactServer.js +0 -12
  77. package/dist/plugin/react-server/configureReactServer.js.map +1 -1
  78. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
  79. package/dist/plugin/react-static/configurePreviewServer.js +1 -1
  80. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
  81. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  82. package/dist/plugin/react-static/plugin.js +5 -14
  83. package/dist/plugin/react-static/plugin.js.map +1 -1
  84. package/dist/plugin/react-static/renderPages.js +1 -1
  85. package/dist/plugin/react-static/renderPages.js.map +1 -1
  86. package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -1
  87. package/dist/plugin/transformer/plugin.server.d.ts +24 -0
  88. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
  89. package/dist/plugin/transformer/plugin.server.js +18 -15
  90. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  91. package/dist/plugin/types.d.ts +4 -2
  92. package/dist/plugin/types.d.ts.map +1 -1
  93. package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
  94. package/dist/plugin/utils/envUrls.node.d.ts.map +1 -1
  95. package/dist/plugin/utils/urls.d.ts.map +1 -1
  96. package/dist/plugin/vendor/types.d.ts +2 -0
  97. package/dist/plugin/vendor/types.d.ts.map +1 -0
  98. package/dist/plugin/vendor/types.js +1 -0
  99. package/dist/plugin/worker/createWorker.js +1 -1
  100. package/dist/plugin/worker/createWorker.js.map +1 -1
  101. package/dist/plugin/worker/rsc/state.d.ts +1 -1
  102. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  103. package/dist/plugin/worker/rsc/state.js +31 -17
  104. package/dist/plugin/worker/rsc/state.js.map +1 -1
  105. package/dist/tsconfig.tsbuildinfo +1 -1
  106. package/package.json +5 -6
  107. package/plugin/config/autoDiscover/resolveAutoDiscover.ts +6 -14
  108. package/plugin/config/mimeTypes.ts +75 -1
  109. package/plugin/config/resolveUserConfig.ts +46 -21
  110. package/plugin/env/plugin.ts +39 -3
  111. package/plugin/helpers/collectManifestCss.ts +2 -2
  112. package/plugin/helpers/collectViteModuleGraphCss.ts +3 -0
  113. package/plugin/helpers/createCssProps.tsx +20 -3
  114. package/plugin/helpers/requestInfo.ts +1 -1
  115. package/plugin/helpers/tryManifest.ts +20 -10
  116. package/plugin/loader/transformModuleIfNeeded.ts +1 -4
  117. package/plugin/react-client/configureWorkerRequestHandler.ts +16 -20
  118. package/plugin/react-server/configureReactServer.ts +0 -12
  119. package/plugin/react-static/configurePreviewServer.ts +1 -2
  120. package/plugin/react-static/plugin.ts +20 -27
  121. package/plugin/transformer/plugin.server.ts +22 -15
  122. package/plugin/types.ts +8 -6
  123. package/plugin/vendor/types.ts +0 -0
  124. package/plugin/worker/rsc/state.ts +53 -28
@@ -36,19 +36,22 @@ import { logError } from "../error/toError.js";
36
36
  * });
37
37
  * ```
38
38
  */
39
- let isBuild = true;
40
- let isSSR = false;
41
39
 
42
40
  export function reactTransformPlugin<
43
41
  T extends PagePropOpt = PagePropOpt,
44
42
  InlineCSS extends InlineCssOpt = InlineCssOpt
45
43
  >(options: StreamPluginOptions<T, InlineCSS>): Plugin {
46
44
  let userOptions: ResolvedUserOptions<T, InlineCSS>;
45
+
47
46
  const resolvedOptionsResult = resolveOptions(options);
47
+
48
48
  if (resolvedOptionsResult.type === "error") throw resolvedOptionsResult.error;
49
+
49
50
  userOptions = resolvedOptionsResult.userOptions;
50
51
 
51
- let staticManifest: Manifest;
52
+ let staticManifest: Manifest = {};
53
+ let isBuild = true;
54
+ let isSSR = false;
52
55
 
53
56
  return {
54
57
  name: "vite:react-server-transform",
@@ -56,16 +59,21 @@ export function reactTransformPlugin<
56
59
  async configResolved(config) {
57
60
  isBuild = config.command === "build";
58
61
  isSSR = config.build?.ssr === true;
62
+
59
63
  if (isBuild && isSSR) {
60
64
  const staticManifestResult = await tryManifest({
61
65
  root: userOptions.projectRoot,
62
66
  ssrManifest: false,
63
67
  outDir: join(userOptions.build.outDir, userOptions.build.static),
68
+ manifestPath: config.build.manifest,
64
69
  });
70
+
65
71
  if (staticManifestResult.type === "error") {
66
72
  throw staticManifestResult.error;
67
73
  }
68
- staticManifest = staticManifestResult.manifest;
74
+ if (staticManifestResult.type === "success") {
75
+ staticManifest = staticManifestResult.manifest;
76
+ }
69
77
  }
70
78
  },
71
79
  async resolveId(
@@ -100,27 +108,28 @@ export function reactTransformPlugin<
100
108
  if (!options?.ssr || !userOptions.autoDiscover.modulePattern(id)) {
101
109
  return null;
102
110
  }
103
- const [, value] = userOptions.normalizer(id);
104
- let moduleID = value;
111
+ const isServerFunctionCode = userOptions.autoDiscover.isServerFunctionCode(code);
112
+ const isClientComponentCode = userOptions.autoDiscover.isClientComponentCode(code);
113
+ if(!isServerFunctionCode && !isClientComponentCode) {
114
+ return null;
115
+ }
116
+ let [, moduleID] = userOptions.normalizer(id);
105
117
  if (isBuild) {
106
118
  if (staticManifest) {
107
- if (value in staticManifest) {
108
- moduleID = staticManifest[value].file;
119
+ if (moduleID in staticManifest) {
120
+ moduleID = staticManifest[moduleID].file;
109
121
  }
110
122
  } else {
111
123
  throw new Error(`Static manifest not found during dev build.`);
112
124
  }
113
- } else {
114
- // For non-SSR builds, just use the normalized path
115
- moduleID = join(userOptions.moduleBasePath, value);
116
125
  }
117
126
  let finalID = userOptions.moduleID(moduleID);
118
127
  // Always transform in server context
119
128
  const transformed = transformModuleIfNeeded(
120
129
  code,
121
130
  finalID,
122
- userOptions.autoDiscover.isServerFunctionCode(code),
123
- userOptions.autoDiscover.isClientComponentCode(code),
131
+ isServerFunctionCode,
132
+ isClientComponentCode,
124
133
  true
125
134
  );
126
135
  if (userOptions.verbose)
@@ -145,14 +154,12 @@ export function reactTransformPlugin<
145
154
  }
146
155
  if (!transformed) {
147
156
  return {
148
- id: finalID,
149
157
  code: "",
150
158
  map: null,
151
159
  };
152
160
  }
153
161
 
154
162
  return {
155
- id: finalID,
156
163
  code: transformed,
157
164
  map: null,
158
165
  };
package/plugin/types.ts CHANGED
@@ -19,6 +19,8 @@ import type {
19
19
  ViteDevServer,
20
20
  } from "vite";
21
21
  import type { ReactServerDomEsmOptions } from "./worker/types.js";
22
+ import type { FragmentProps } from "react";
23
+ import type { ExoticComponent } from "react";
22
24
 
23
25
  export type OnEvent = (event: PluginEvent) => void;
24
26
 
@@ -457,7 +459,7 @@ export interface StreamPluginOptions<
457
459
  // Auto-discovery (zero-config)
458
460
  autoDiscover?:
459
461
  | {
460
- // default: /\.(m|c)?(j|t)sx?$/
462
+ // default: /\.(m|c)?(j|t)sx?$/
461
463
  moduleExtension?: RegExp;
462
464
  // default: /^"use server"[\s;]*\n?/m
463
465
  serverDirective?: RegExp;
@@ -561,12 +563,13 @@ export type CreateHandlerOptions<
561
563
  | "moduleRootPath"
562
564
  | "moduleBasePath"
563
565
  | "moduleBaseURL"
566
+ | "publicOrigin"
564
567
  | "pipeableStreamOptions"
565
568
  | "onEvent"
566
569
  | "onMetrics"
567
570
  | "projectRoot"
568
571
  | "normalizer"
569
- | "moduleID"
572
+ | "moduleID"
570
573
  > & {
571
574
  logger: Logger;
572
575
  loader: ModuleLoader;
@@ -778,10 +781,9 @@ export type InlineCssOpt = undefined | boolean;
778
781
  export type PagePropOpt = Record<string, unknown> | undefined;
779
782
  export type RegExpOpt = RegExp | string | ((path: string) => boolean);
780
783
 
781
- export type AsOpt = Exclude<
782
- keyof React.JSX.IntrinsicElements,
783
- "symbol" | "object"
784
- >;
784
+ export type AsOpt =
785
+ | ExoticComponent<FragmentProps>
786
+ | Exclude<keyof React.JSX.IntrinsicElements, "symbol" | "object">;
785
787
  export type PageComponentType<T extends PagePropOpt = PagePropOpt> =
786
788
  React.ComponentType<T & React.PropsWithChildren<{}>>;
787
789
 
File without changes
@@ -4,7 +4,6 @@ import type { CssContent, ResolvedUserOptions, HmrState } from "../../types.js";
4
4
  import type { PassThrough } from "node:stream";
5
5
  import { relative } from "node:path";
6
6
 
7
-
8
7
  // Track active RSC streams
9
8
  export const activeStreams = new Map<string, PassThrough>();
10
9
 
@@ -16,40 +15,66 @@ export const moduleIds = new Map<string, string>();
16
15
 
17
16
  export const hmrState = new Map<string, HmrState>();
18
17
 
19
- if(workerData) {
20
- if(workerData.hmrPort) {
21
- workerData.hmrPort.on('message', (msg: { type: string; path: string; routes?: string[] }) => {
22
- if(msg.type === 'HMR_UPDATE') {
23
- // Normalize the path relative to project root
24
- const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);
25
- hmrState.set(normalizedPath, {
26
- timestamp: Date.now(),
27
- invalidated: true,
28
- routes: msg.routes || []
29
- });
30
- } else if(msg.type === 'HMR_ACCEPT') {
31
- // Normalize the path relative to project root
32
- const normalizedPath = relative(workerData.userOptions.projectRoot, msg.path);
33
- hmrState.delete(normalizedPath);
18
+ if (workerData) {
19
+ if (workerData.hmrPort) {
20
+ workerData.hmrPort.on(
21
+ "message",
22
+ (msg: { type: string; path: string; routes?: string[] }) => {
23
+ if (msg.type === "HMR_UPDATE") {
24
+ // Normalize the path relative to project root
25
+ const normalizedPath = relative(
26
+ workerData.userOptions.projectRoot,
27
+ msg.path
28
+ );
29
+ hmrState.set(normalizedPath, {
30
+ timestamp: Date.now(),
31
+ invalidated: true,
32
+ routes: msg.routes || [],
33
+ });
34
+ } else if (msg.type === "HMR_ACCEPT") {
35
+ // Normalize the path relative to project root
36
+ const normalizedPath = relative(
37
+ workerData.userOptions.projectRoot,
38
+ msg.path
39
+ );
40
+ hmrState.delete(normalizedPath);
41
+ }
34
42
  }
35
- });
43
+ );
36
44
  }
37
45
  } else {
38
46
  throw new Error("This module must be run with workerData");
39
47
  }
40
48
 
41
-
42
- export function addCssFileContent(id: string, code: string, userOptions: Pick<ResolvedUserOptions, "projectRoot" | "moduleBaseURL" | "moduleBasePath" | "moduleRootPath" | "css" | "normalizer" | "moduleID">) {
43
- if(typeof code !== "string"){
44
- throw new Error(`Expected css to be loaded as a string, but got ${typeof code}`);
49
+ export function addCssFileContent(
50
+ id: string,
51
+ code: string,
52
+ userOptions: Pick<
53
+ ResolvedUserOptions,
54
+ | "projectRoot"
55
+ | "moduleBaseURL"
56
+ | "moduleBasePath"
57
+ | "moduleRootPath"
58
+ | "css"
59
+ | "normalizer"
60
+ | "moduleID"
61
+ | "publicOrigin"
62
+ >
63
+ ) {
64
+ if (typeof code !== "string") {
65
+ throw new Error(
66
+ `Expected css to be loaded as a string, but got ${typeof code}`
67
+ );
45
68
  }
46
- cssFiles.set(id, createCssProps({
69
+ cssFiles.set(
47
70
  id,
48
- code,
49
- userOptions
50
- }));
51
- }
52
-
71
+ createCssProps({
72
+ id,
73
+ code,
74
+ userOptions,
75
+ })
76
+ );
77
+ }
53
78
 
54
79
  // Helper to check if a module is invalidated
55
80
  export function isModuleInvalidated(path: string): boolean {
@@ -75,4 +100,4 @@ export function addModuleId(id: string, url: string) {
75
100
 
76
101
  export function getModuleId(id: string): string | undefined {
77
102
  return moduleIds.get(id);
78
- }
103
+ }