vite-plugin-react-server 1.1.17 → 1.1.19

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 (167) hide show
  1. package/README.md +9 -5
  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.d.ts +1 -1
  15. package/dist/plugin/config/defaults.d.ts.map +1 -1
  16. package/dist/plugin/config/defaults.js +18 -4
  17. package/dist/plugin/config/defaults.js.map +1 -1
  18. package/dist/plugin/config/extMap.d.ts.map +1 -1
  19. package/dist/plugin/config/getCondition.d.ts.map +1 -1
  20. package/dist/plugin/config/getPaths.d.ts.map +1 -1
  21. package/dist/plugin/config/mimeTypes.d.ts.map +1 -1
  22. package/dist/plugin/config/mimeTypes.js +67 -0
  23. package/dist/plugin/config/mimeTypes.js.map +1 -1
  24. package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -1
  25. package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
  26. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  27. package/dist/plugin/config/resolveOptions.js +5 -5
  28. package/dist/plugin/config/resolveOptions.js.map +1 -1
  29. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  30. package/dist/plugin/config/resolveUserConfig.js +39 -22
  31. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  32. package/dist/plugin/env/plugin.d.ts.map +1 -1
  33. package/dist/plugin/env/plugin.js +35 -2
  34. package/dist/plugin/env.js +37 -3
  35. package/dist/plugin/env.js.map +1 -1
  36. package/dist/plugin/error/toError.js +4 -4
  37. package/dist/plugin/error/toError.js.map +1 -1
  38. package/dist/plugin/helpers/cleanObject.js +2 -2
  39. package/dist/plugin/helpers/cleanObject.js.map +1 -1
  40. package/dist/plugin/helpers/collectManifestCss.js +2 -2
  41. package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
  42. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
  43. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  44. package/dist/plugin/helpers/collectViteModuleGraphCss.js +3 -1
  45. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  46. package/dist/plugin/helpers/createCssProps.d.ts +1 -1
  47. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  48. package/dist/plugin/helpers/createCssProps.js +12 -1
  49. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  50. package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -1
  51. package/dist/plugin/helpers/createEventHandler.js +1 -1
  52. package/dist/plugin/helpers/getBundleManifest.js +1 -1
  53. package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
  54. package/dist/plugin/helpers/getRouteFiles.js +2 -2
  55. package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
  56. package/dist/plugin/helpers/handleServerAction.d.ts +34 -0
  57. package/dist/plugin/helpers/handleServerAction.d.ts.map +1 -0
  58. package/dist/plugin/helpers/handleServerAction.js +48 -0
  59. package/dist/plugin/helpers/handleServerAction.js.map +1 -0
  60. package/dist/plugin/helpers/inputNormalizer.js +1 -1
  61. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  62. package/dist/plugin/helpers/requestInfo.js +1 -1
  63. package/dist/plugin/helpers/requestInfo.js.map +1 -1
  64. package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
  65. package/dist/plugin/helpers/resolveProps.d.ts.map +1 -1
  66. package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
  67. package/dist/plugin/helpers/sourceMap.d.ts.map +1 -1
  68. package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -1
  69. package/dist/plugin/helpers/tryManifest.d.ts +3 -1
  70. package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
  71. package/dist/plugin/helpers/tryManifest.js +14 -8
  72. package/dist/plugin/helpers/tryManifest.js.map +1 -1
  73. package/dist/plugin/loader/handleExports.d.ts +16 -10
  74. package/dist/plugin/loader/handleExports.d.ts.map +1 -1
  75. package/dist/plugin/loader/handleExports.js +32 -16
  76. package/dist/plugin/loader/handleExports.js.map +1 -1
  77. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
  78. package/dist/plugin/loader/transformModuleIfNeeded.js +22 -12
  79. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
  80. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +21 -0
  81. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -1
  82. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +398 -73
  83. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -1
  84. package/dist/plugin/loader/types.d.ts +9 -3
  85. package/dist/plugin/loader/types.d.ts.map +1 -1
  86. package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
  87. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
  88. package/dist/plugin/react-client/configureWorkerRequestHandler.js +12 -73
  89. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
  90. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  91. package/dist/plugin/react-client/handleWorkerServerAction.d.ts +12 -0
  92. package/dist/plugin/react-client/handleWorkerServerAction.d.ts.map +1 -0
  93. package/dist/plugin/react-client/handleWorkerServerAction.js +47 -0
  94. package/dist/plugin/react-client/handleWorkerServerAction.js.map +1 -0
  95. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
  96. package/dist/plugin/react-server/configureReactServer.js +0 -12
  97. package/dist/plugin/react-server/configureReactServer.js.map +1 -1
  98. package/dist/plugin/react-server/handleServerAction.d.ts +1 -1
  99. package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
  100. package/dist/plugin/react-server/handleServerAction.js +42 -6
  101. package/dist/plugin/react-server/handleServerAction.js.map +1 -1
  102. package/dist/plugin/react-server/plugin.js +2 -2
  103. package/dist/plugin/react-server/plugin.js.map +1 -1
  104. package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
  105. package/dist/plugin/react-static/configurePreviewServer.js +1 -1
  106. package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
  107. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  108. package/dist/plugin/react-static/plugin.js +15 -16
  109. package/dist/plugin/react-static/plugin.js.map +1 -1
  110. package/dist/plugin/react-static/renderPages.js +1 -1
  111. package/dist/plugin/react-static/renderPages.js.map +1 -1
  112. package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -1
  113. package/dist/plugin/source-map/createMappingsSerializer.js +128 -157
  114. package/dist/plugin/source-map/createMappingsSerializer.js.map +1 -0
  115. package/dist/plugin/transformer/plugin.server.d.ts +24 -0
  116. package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
  117. package/dist/plugin/transformer/plugin.server.js +18 -15
  118. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  119. package/dist/plugin/types.d.ts +7 -7
  120. package/dist/plugin/types.d.ts.map +1 -1
  121. package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
  122. package/dist/plugin/utils/envUrls.node.d.ts.map +1 -1
  123. package/dist/plugin/utils/urls.d.ts.map +1 -1
  124. package/dist/plugin/vendor/types.d.ts +2 -0
  125. package/dist/plugin/vendor/types.d.ts.map +1 -0
  126. package/dist/plugin/vendor/types.js +2 -0
  127. package/dist/plugin/worker/createWorker.js +1 -1
  128. package/dist/plugin/worker/createWorker.js.map +1 -1
  129. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  130. package/dist/plugin/worker/rsc/handleRender.js +0 -1
  131. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  132. package/dist/plugin/worker/rsc/handlers.js.map +1 -1
  133. package/dist/plugin/worker/rsc/state.d.ts +1 -1
  134. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  135. package/dist/plugin/worker/rsc/state.js +31 -17
  136. package/dist/plugin/worker/rsc/state.js.map +1 -1
  137. package/dist/tsconfig.tsbuildinfo +1 -1
  138. package/package.json +5 -6
  139. package/plugin/config/autoDiscover/resolveAutoDiscover.ts +6 -14
  140. package/plugin/config/defaults.tsx +5 -2
  141. package/plugin/config/mimeTypes.ts +75 -1
  142. package/plugin/config/resolveOptions.ts +9 -10
  143. package/plugin/config/resolveUserConfig.ts +46 -21
  144. package/plugin/env/plugin.ts +39 -3
  145. package/plugin/helpers/collectManifestCss.ts +2 -2
  146. package/plugin/helpers/collectViteModuleGraphCss.ts +3 -0
  147. package/plugin/helpers/createCssProps.tsx +20 -3
  148. package/plugin/helpers/handleServerAction.ts +79 -0
  149. package/plugin/helpers/requestInfo.ts +1 -1
  150. package/plugin/helpers/tryManifest.ts +20 -10
  151. package/plugin/loader/handleExports.ts +50 -40
  152. package/plugin/loader/transformModuleIfNeeded.ts +50 -18
  153. package/plugin/loader/transformModuleWithPreservedFunctions.ts +496 -126
  154. package/plugin/loader/types.ts +12 -4
  155. package/plugin/react-client/configureWorkerRequestHandler.ts +12 -92
  156. package/plugin/react-client/handleWorkerServerAction.ts +74 -0
  157. package/plugin/react-server/configureReactServer.ts +1 -13
  158. package/plugin/react-server/handleServerAction.ts +49 -12
  159. package/plugin/react-server/plugin.ts +2 -2
  160. package/plugin/react-static/configurePreviewServer.ts +1 -2
  161. package/plugin/react-static/plugin.ts +30 -29
  162. package/plugin/transformer/plugin.server.ts +22 -15
  163. package/plugin/types.ts +12 -11
  164. package/plugin/vendor/types.ts +1 -0
  165. package/plugin/worker/rsc/handleRender.ts +0 -2
  166. package/plugin/worker/rsc/handlers.ts +3 -3
  167. package/plugin/worker/rsc/state.ts +53 -28
package/plugin/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Readable } from "node:stream";
2
2
  import type { Worker } from "node:worker_threads";
3
3
  import type React from "react";
4
+ import type { ExoticComponent, FragmentProps } from "react";
4
5
  import type {
5
6
  NormalizedOutputOptions,
6
7
  OutputBundle,
@@ -444,7 +445,8 @@ export type PluginEventType = PluginEvent["type"];
444
445
 
445
446
  export interface StreamPluginOptions<
446
447
  T extends PagePropOpt = PagePropOpt,
447
- InlineCSS extends InlineCssOpt = InlineCssOpt
448
+ InlineCSS extends InlineCssOpt = InlineCssOpt,
449
+ As extends AsOpt = AsOpt
448
450
  > {
449
451
  projectRoot?: string; // defaults to process.cwd()
450
452
  moduleBase: string; // defaults to 'src'
@@ -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;
@@ -502,9 +504,9 @@ export interface StreamPluginOptions<
502
504
  // default: /\.rsc$/
503
505
  rscPattern?: RegExpOpt;
504
506
  // default serverDirective regex
505
- isServerFunction?: RegExpOpt;
507
+ isServerFunctionCode?: (code: string, moduleId?: string) => boolean;
506
508
  // default clientDirective regex
507
- isClientComponent?: RegExpOpt;
509
+ isClientComponentCode?: (code: string, moduleId?: string) => boolean;
508
510
  }
509
511
  | undefined;
510
512
  // Manual configuration
@@ -520,7 +522,7 @@ export interface StreamPluginOptions<
520
522
  loaderPath?: string;
521
523
  pageExportName?: string;
522
524
  propsExportName?: string;
523
- Html?: React.FC<HtmlProps<T, InlineCSS>>;
525
+ Html?: React.FC<HtmlProps<T, InlineCSS, As>> | typeof React.Fragment;
524
526
  CssCollector?: CssCollectorBoxedType<T, InlineCSS>;
525
527
  build?: BuildConfig;
526
528
  css?: CssCollectorOptions<InlineCSS>;
@@ -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
 
@@ -803,7 +805,6 @@ export type HtmlProps<
803
805
  manifest: Manifest;
804
806
  CssCollector: CssCollectorBoxedType<T, InlineCSS, As>;
805
807
  globalCss: Map<string, CssContent<InlineCSS>>;
806
- children?: React.ReactNode;
807
808
  as: As;
808
809
  };
809
810
 
@@ -0,0 +1 @@
1
+ //
@@ -46,8 +46,6 @@ export async function handleRender<
46
46
  if (hmrState.get(id)?.invalidated) {
47
47
  // Clear the HMR state for this module
48
48
  hmrState.delete(id);
49
- // Force a reload by using a unique query parameter
50
- console.log("LOADING", id);
51
49
  return import(join(projectRoot, id) + `?t=${Date.now()}`);
52
50
  }
53
51
  return import(join(projectRoot, id));
@@ -67,7 +67,7 @@ export const handlers: Required<StreamHandlers> = {
67
67
  const stream = ReactDOMServer.renderToPipeableStream(
68
68
  {
69
69
  type: "server-action-response",
70
- returnValue: result,
70
+ returnValue: result
71
71
  },
72
72
  userOptions.moduleBasePath,
73
73
  {
@@ -137,7 +137,7 @@ export const handlers: Required<StreamHandlers> = {
137
137
  const stream = ReactDOMServer.renderToPipeableStream(
138
138
  {
139
139
  type: "server-action-response",
140
- returnValue: result,
140
+ returnValue: result
141
141
  },
142
142
  userOptions.moduleBasePath,
143
143
  {
@@ -182,7 +182,7 @@ export const handlers: Required<StreamHandlers> = {
182
182
  const stream = ReactDOMServer.renderToPipeableStream(
183
183
  {
184
184
  type: "server-action-response",
185
- returnValue: { success: false, error: errorMessage },
185
+ returnValue: { success: false, error: errorMessage }
186
186
  },
187
187
  userOptions.moduleBasePath,
188
188
  {
@@ -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
+ }