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.
- package/README.md +9 -5
- package/dist/package.json +5 -4
- package/dist/plugin/components/css-collector-elements.d.ts.map +1 -1
- package/dist/plugin/components/html.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/createGlobAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/customWorkerFiles.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/pageAndPropFiles.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.d.ts.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js +7 -12
- package/dist/plugin/config/autoDiscover/resolveAutoDiscover.js.map +1 -1
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js +2 -2
- package/dist/plugin/config/autoDiscover/resolveBuildPages.js.map +1 -1
- package/dist/plugin/config/createModuleID.d.ts.map +1 -1
- package/dist/plugin/config/defaults.d.ts +1 -1
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +18 -4
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/extMap.d.ts.map +1 -1
- package/dist/plugin/config/getCondition.d.ts.map +1 -1
- package/dist/plugin/config/getPaths.d.ts.map +1 -1
- package/dist/plugin/config/mimeTypes.d.ts.map +1 -1
- package/dist/plugin/config/mimeTypes.js +67 -0
- package/dist/plugin/config/mimeTypes.js.map +1 -1
- package/dist/plugin/config/resolveAutoDiscoverMatcher.d.ts.map +1 -1
- package/dist/plugin/config/resolveEnv.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +5 -5
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +39 -22
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/env/plugin.d.ts.map +1 -1
- package/dist/plugin/env/plugin.js +35 -2
- package/dist/plugin/env.js +37 -3
- package/dist/plugin/env.js.map +1 -1
- package/dist/plugin/error/toError.js +4 -4
- package/dist/plugin/error/toError.js.map +1 -1
- package/dist/plugin/helpers/cleanObject.js +2 -2
- package/dist/plugin/helpers/cleanObject.js.map +1 -1
- package/dist/plugin/helpers/collectManifestCss.js +2 -2
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +3 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +12 -1
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createEventHandler.d.ts.map +1 -1
- package/dist/plugin/helpers/createEventHandler.js +1 -1
- package/dist/plugin/helpers/getBundleManifest.js +1 -1
- package/dist/plugin/helpers/getRouteFiles.d.ts.map +1 -1
- package/dist/plugin/helpers/getRouteFiles.js +2 -2
- package/dist/plugin/helpers/getRouteFiles.js.map +1 -1
- package/dist/plugin/helpers/handleServerAction.d.ts +34 -0
- package/dist/plugin/helpers/handleServerAction.d.ts.map +1 -0
- package/dist/plugin/helpers/handleServerAction.js +48 -0
- package/dist/plugin/helpers/handleServerAction.js.map +1 -0
- package/dist/plugin/helpers/inputNormalizer.js +1 -1
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/requestInfo.js +1 -1
- package/dist/plugin/helpers/requestInfo.js.map +1 -1
- package/dist/plugin/helpers/resolvePage.d.ts.map +1 -1
- package/dist/plugin/helpers/resolveProps.d.ts.map +1 -1
- package/dist/plugin/helpers/serializeUserOptions.d.ts.map +1 -1
- package/dist/plugin/helpers/sourceMap.d.ts.map +1 -1
- package/dist/plugin/helpers/stashReturnValue.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.d.ts +3 -1
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +14 -8
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/handleExports.d.ts +16 -10
- package/dist/plugin/loader/handleExports.d.ts.map +1 -1
- package/dist/plugin/loader/handleExports.js +32 -16
- package/dist/plugin/loader/handleExports.js.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js +22 -12
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts +21 -0
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +398 -73
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -1
- package/dist/plugin/loader/types.d.ts +9 -3
- package/dist/plugin/loader/types.d.ts.map +1 -1
- package/dist/plugin/metrics/formatMetrics.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js +12 -73
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerServerAction.d.ts +12 -0
- package/dist/plugin/react-client/handleWorkerServerAction.d.ts.map +1 -0
- package/dist/plugin/react-client/handleWorkerServerAction.js +47 -0
- package/dist/plugin/react-client/handleWorkerServerAction.js.map +1 -0
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
- package/dist/plugin/react-server/configureReactServer.js +0 -12
- package/dist/plugin/react-server/configureReactServer.js.map +1 -1
- package/dist/plugin/react-server/handleServerAction.d.ts +1 -1
- package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
- package/dist/plugin/react-server/handleServerAction.js +42 -6
- package/dist/plugin/react-server/handleServerAction.js.map +1 -1
- package/dist/plugin/react-server/plugin.js +2 -2
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.d.ts.map +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js +1 -1
- package/dist/plugin/react-static/configurePreviewServer.js.map +1 -1
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +15 -16
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/renderPages.js +1 -1
- package/dist/plugin/react-static/renderPages.js.map +1 -1
- package/dist/plugin/source-map/createMappingsSerializer.d.ts.map +1 -1
- package/dist/plugin/source-map/createMappingsSerializer.js +128 -157
- package/dist/plugin/source-map/createMappingsSerializer.js.map +1 -0
- package/dist/plugin/transformer/plugin.server.d.ts +24 -0
- package/dist/plugin/transformer/plugin.server.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.server.js +18 -15
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +7 -7
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/utils/createCallServer.d.ts.map +1 -1
- package/dist/plugin/utils/envUrls.node.d.ts.map +1 -1
- package/dist/plugin/utils/urls.d.ts.map +1 -1
- package/dist/plugin/vendor/types.d.ts +2 -0
- package/dist/plugin/vendor/types.d.ts.map +1 -0
- package/dist/plugin/vendor/types.js +2 -0
- package/dist/plugin/worker/createWorker.js +1 -1
- package/dist/plugin/worker/createWorker.js.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +0 -1
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/handlers.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +1 -1
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +31 -17
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
- package/plugin/config/autoDiscover/resolveAutoDiscover.ts +6 -14
- package/plugin/config/defaults.tsx +5 -2
- package/plugin/config/mimeTypes.ts +75 -1
- package/plugin/config/resolveOptions.ts +9 -10
- package/plugin/config/resolveUserConfig.ts +46 -21
- package/plugin/env/plugin.ts +39 -3
- package/plugin/helpers/collectManifestCss.ts +2 -2
- package/plugin/helpers/collectViteModuleGraphCss.ts +3 -0
- package/plugin/helpers/createCssProps.tsx +20 -3
- package/plugin/helpers/handleServerAction.ts +79 -0
- package/plugin/helpers/requestInfo.ts +1 -1
- package/plugin/helpers/tryManifest.ts +20 -10
- package/plugin/loader/handleExports.ts +50 -40
- package/plugin/loader/transformModuleIfNeeded.ts +50 -18
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +496 -126
- package/plugin/loader/types.ts +12 -4
- package/plugin/react-client/configureWorkerRequestHandler.ts +12 -92
- package/plugin/react-client/handleWorkerServerAction.ts +74 -0
- package/plugin/react-server/configureReactServer.ts +1 -13
- package/plugin/react-server/handleServerAction.ts +49 -12
- package/plugin/react-server/plugin.ts +2 -2
- package/plugin/react-static/configurePreviewServer.ts +1 -2
- package/plugin/react-static/plugin.ts +30 -29
- package/plugin/transformer/plugin.server.ts +22 -15
- package/plugin/types.ts +12 -11
- package/plugin/vendor/types.ts +1 -0
- package/plugin/worker/rsc/handleRender.ts +0 -2
- package/plugin/worker/rsc/handlers.ts +3 -3
- 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
|
-
|
|
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
|
-
|
|
507
|
+
isServerFunctionCode?: (code: string, moduleId?: string) => boolean;
|
|
506
508
|
// default clientDirective regex
|
|
507
|
-
|
|
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 =
|
|
782
|
-
|
|
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(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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(
|
|
69
|
+
cssFiles.set(
|
|
47
70
|
id,
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|