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.
- package/README.md +2 -2
- 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.js +16 -2
- 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 +1 -1
- 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/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/transformModuleIfNeeded.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js +1 -2
- package/dist/plugin/loader/transformModuleIfNeeded.js.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 +14 -18
- 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-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-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 +5 -14
- 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/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 +4 -2
- 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 +1 -0
- package/dist/plugin/worker/createWorker.js +1 -1
- package/dist/plugin/worker/createWorker.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/mimeTypes.ts +75 -1
- 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/requestInfo.ts +1 -1
- package/plugin/helpers/tryManifest.ts +20 -10
- package/plugin/loader/transformModuleIfNeeded.ts +1 -4
- package/plugin/react-client/configureWorkerRequestHandler.ts +16 -20
- package/plugin/react-server/configureReactServer.ts +0 -12
- package/plugin/react-static/configurePreviewServer.ts +1 -2
- package/plugin/react-static/plugin.ts +20 -27
- package/plugin/transformer/plugin.server.ts +22 -15
- package/plugin/types.ts +8 -6
- package/plugin/vendor/types.ts +0 -0
- 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
|
-
|
|
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
|
|
104
|
-
|
|
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 (
|
|
108
|
-
moduleID = staticManifest[
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
|
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(
|
|
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
|
+
}
|