vite-plugin-react-server 0.3.9 → 0.3.11
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/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json +2 -4
- package/dist/plugin/assertServerCondition.d.ts +5 -1
- package/dist/plugin/assertServerCondition.d.ts.map +1 -1
- package/dist/plugin/assertServerCondition.js +1 -3
- package/dist/plugin/checkFilesExist.js +10 -7
- package/dist/plugin/checkFilesExist.js.map +1 -1
- package/dist/plugin/components.js +1 -1
- package/dist/plugin/components.js.map +1 -1
- package/dist/plugin/config/createModuleIdGenerator.d.ts +11 -0
- package/dist/plugin/config/createModuleIdGenerator.d.ts.map +1 -0
- package/dist/plugin/config/createModuleIdGenerator.js +44 -0
- package/dist/plugin/config/createModuleIdGenerator.js.map +1 -0
- package/dist/plugin/config/defaults.d.ts +31 -19
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +22 -27
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +202 -16
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolvePages.d.ts +2 -0
- package/dist/plugin/config/resolvePages.d.ts.map +1 -1
- package/dist/plugin/config/resolvePages.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts +2 -2
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +161 -50
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/helpers/getBundleManifest.d.ts +20 -0
- package/dist/plugin/helpers/getBundleManifest.d.ts.map +1 -0
- package/dist/plugin/helpers/getBundleManifest.js +43 -0
- package/dist/plugin/helpers/getBundleManifest.js.map +1 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts +5 -0
- package/dist/plugin/helpers/getModuleManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/getModuleManifest.js +20 -21
- package/dist/plugin/helpers/inputNormalizer.d.ts +15 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +122 -16
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts +2 -1
- package/dist/plugin/helpers/inputNormalizerWorker.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizerWorker.js +10 -7
- package/dist/plugin/helpers/tryManifest.d.ts +2 -0
- package/dist/plugin/helpers/tryManifest.d.ts.map +1 -1
- package/dist/plugin/helpers/tryManifest.js +1 -1
- package/dist/plugin/helpers/tryManifest.js.map +1 -1
- package/dist/plugin/loader/createBuildLoader.d.ts +6 -2
- package/dist/plugin/loader/createBuildLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createBuildLoader.js +35 -10
- package/dist/plugin/loader/createBuildLoader.js.map +1 -1
- package/dist/plugin/loader/createPageLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createPageLoader.js +0 -7
- package/dist/plugin/plugin.d.ts +0 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/preserver/plugin.d.ts.map +1 -1
- package/dist/plugin/preserver/plugin.js +3 -2
- package/dist/plugin/preserver/plugin.js.map +1 -1
- package/dist/plugin/react-client/index.d.ts +2 -1
- package/dist/plugin/react-client/index.d.ts.map +1 -1
- package/dist/plugin/react-client/index.js +19 -1
- package/dist/plugin/react-client/index.js.map +1 -0
- package/dist/plugin/react-client/plugin.d.ts +2 -2
- package/dist/plugin/react-client/plugin.d.ts.map +1 -1
- package/dist/plugin/react-client/plugin.js +106 -10
- package/dist/plugin/react-client/plugin.js.map +1 -1
- package/dist/plugin/react-server/createHandler.d.ts +2 -2
- package/dist/plugin/react-server/createHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createHandler.js +5 -5
- package/dist/plugin/react-server/createHandler.js.map +1 -1
- package/dist/plugin/react-server/createRscStream.d.ts.map +1 -1
- package/dist/plugin/react-server/createRscStream.js +15 -1
- package/dist/plugin/react-server/createRscStream.js.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.d.ts +2 -2
- package/dist/plugin/react-server/createSsrHandler.d.ts.map +1 -1
- package/dist/plugin/react-server/createSsrHandler.js +5 -12
- package/dist/plugin/react-server/index.js +18 -9
- package/dist/plugin/react-server/index.js.map +1 -0
- package/dist/plugin/react-server/plugin.d.ts.map +1 -1
- package/dist/plugin/react-server/plugin.js +133 -127
- package/dist/plugin/react-server/plugin.js.map +1 -1
- package/dist/plugin/transformer/plugin.d.ts +2 -1
- package/dist/plugin/transformer/plugin.d.ts.map +1 -1
- package/dist/plugin/transformer/plugin.js +52 -72
- package/dist/plugin/transformer/plugin.js.map +1 -1
- package/dist/plugin/transformer/transformer-client-components.d.ts +12 -3
- package/dist/plugin/transformer/transformer-client-components.d.ts.map +1 -1
- package/dist/plugin/transformer/transformer-client-components.js +71 -10
- package/dist/plugin/transformer/transformer-client-components.js.map +1 -1
- package/dist/plugin/transformer/transformer-server-actions.d.ts +3 -3
- package/dist/plugin/transformer/transformer-server-actions.d.ts.map +1 -1
- package/dist/plugin/transformer/transformer-server-actions.js +80 -66
- package/dist/plugin/transformer/types.d.ts +4 -0
- package/dist/plugin/transformer/types.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +51 -20
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/html/messageHandler.js +37 -23
- package/dist/plugin/worker/html/messageHandler.js.map +1 -1
- package/dist/plugin/worker/html/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/html/plugin.js +10 -5
- package/dist/plugin/worker/html/renderPages.d.ts +7 -6
- package/dist/plugin/worker/html/renderPages.d.ts.map +1 -1
- package/dist/plugin/worker/html/renderPages.js +112 -57
- package/dist/plugin/worker/html/renderPages.js.map +1 -1
- package/dist/plugin/worker/loader.d.ts +1 -11
- package/dist/plugin/worker/loader.d.ts.map +1 -1
- package/dist/plugin/worker/loader.js +2 -2
- package/dist/plugin/worker/loader.js.map +1 -1
- package/dist/plugin/worker/plugin.d.ts +10 -1
- package/dist/plugin/worker/plugin.d.ts.map +1 -1
- package/dist/plugin/worker/plugin.js +10 -1
- package/dist/plugin/worker/types.d.ts +17 -4
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/plugin/assertServerCondition.ts +2 -3
- package/plugin/checkFilesExist.ts +10 -10
- package/plugin/components.tsx +1 -1
- package/plugin/config/createModuleIdGenerator.ts +52 -0
- package/plugin/config/defaults.ts +24 -15
- package/plugin/config/resolveOptions.ts +253 -25
- package/plugin/config/resolvePages.ts +1 -1
- package/plugin/config/resolveUserConfig.ts +197 -62
- package/plugin/helpers/getBundleManifest.ts +75 -0
- package/plugin/helpers/getModuleManifest.ts +5 -0
- package/plugin/helpers/inputNormalizer.ts +175 -26
- package/plugin/helpers/inputNormalizerWorker.ts +13 -8
- package/plugin/helpers/tryManifest.ts +2 -0
- package/plugin/loader/createBuildLoader.ts +54 -10
- package/plugin/loader/createPageLoader.ts +1 -7
- package/plugin/plugin.ts +2 -1
- package/plugin/preserver/plugin.ts +2 -1
- package/plugin/react-client/index.ts +12 -1
- package/plugin/react-client/plugin.ts +127 -12
- package/plugin/react-server/createHandler.ts +7 -13
- package/plugin/react-server/createRscStream.ts +14 -2
- package/plugin/react-server/createSsrHandler.ts +7 -26
- package/plugin/react-server/plugin.ts +176 -144
- package/plugin/transformer/plugin.ts +69 -94
- package/plugin/transformer/transformer-client-components.ts +98 -24
- package/plugin/transformer/transformer-server-actions.ts +22 -7
- package/plugin/transformer/types.ts +4 -0
- package/plugin/types.ts +118 -64
- package/plugin/worker/html/messageHandler.ts +46 -31
- package/plugin/worker/html/plugin.ts +15 -11
- package/plugin/worker/html/renderPages.ts +175 -88
- package/plugin/worker/loader.ts +4 -13
- package/plugin/worker/plugin.ts +10 -1
- package/plugin/worker/types.ts +24 -3
- package/dist/node_modules/magic-string/dist/magic-string.es.js +0 -1283
- package/dist/node_modules/magic-string/dist/magic-string.es.js.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.d.ts +0 -3
- package/dist/plugin/build/createClientBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createClientBuildConfig.js +0 -14
- package/dist/plugin/build/createServerBuildConfig.d.ts +0 -12
- package/dist/plugin/build/createServerBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createServerBuildConfig.js +0 -40
- package/dist/plugin/build/createSharedBuildConfig.d.ts +0 -5
- package/dist/plugin/build/createSharedBuildConfig.d.ts.map +0 -1
- package/dist/plugin/build/createSharedBuildConfig.js +0 -28
- package/dist/plugin/build/mergeInputs.d.ts +0 -9
- package/dist/plugin/build/mergeInputs.d.ts.map +0 -1
- package/dist/plugin/build/mergeInputs.js +0 -56
- package/dist/plugin/config/moduleIdDefault.d.ts +0 -8
- package/dist/plugin/config/moduleIdDefault.d.ts.map +0 -1
- package/dist/plugin/config/moduleIdDefault.js +0 -23
- package/dist/plugin/config/moduleIdDefault.js.map +0 -1
- package/dist/plugin/helpers/getModuleManifest.js.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.d.ts +0 -8
- package/dist/plugin/react-server/createDevMiddleware.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevMiddleware.js +0 -68
- package/dist/plugin/react-server/createDevServer.d.ts +0 -4
- package/dist/plugin/react-server/createDevServer.d.ts.map +0 -1
- package/dist/plugin/react-server/createDevServer.js +0 -4
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts +0 -10
- package/dist/plugin/react-server/createReactNodeStreamer.d.ts.map +0 -1
- package/dist/plugin/react-server/createReactNodeStreamer.js +0 -7
- package/dist/plugin/transformer/transformer-server-actions.js.map +0 -1
- package/plugin/build/createClientBuildConfig.ts +0 -21
- package/plugin/build/createServerBuildConfig.ts +0 -66
- package/plugin/build/createSharedBuildConfig.ts +0 -35
- package/plugin/build/mergeInputs.ts +0 -58
- package/plugin/config/moduleIdDefault.ts +0 -23
- package/plugin/react-server/createDevMiddleware.ts +0 -91
- package/plugin/react-server/createDevServer.ts +0 -9
- package/plugin/react-server/createReactNodeStreamer.ts +0 -26
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import type { ResolvedUserConfig, ResolvedUserOptions } from "../types.js";
|
|
3
|
-
import type { UserConfig } from "vite";
|
|
4
|
-
|
|
5
|
-
interface CreateServerBuildConfigProps {
|
|
6
|
-
condition: string;
|
|
7
|
-
userConfig: ResolvedUserConfig;
|
|
8
|
-
userOptions: ResolvedUserOptions;
|
|
9
|
-
mode: string;
|
|
10
|
-
inputNormalizer: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function createServerBuildConfig({
|
|
14
|
-
userConfig,
|
|
15
|
-
userOptions,
|
|
16
|
-
mode,
|
|
17
|
-
}: CreateServerBuildConfigProps): Promise<UserConfig> {
|
|
18
|
-
const { build, appType, mode: configMode, ...restUserConfig } = userConfig;
|
|
19
|
-
const { outDir, ssr, target, assetsDir, manifest, ssrManifest, ssrEmitAssets, rollupOptions, ...restBuildOptions } = build ?? {};
|
|
20
|
-
const { input, output, ...restRollupOptions } = rollupOptions ?? {};
|
|
21
|
-
const {
|
|
22
|
-
format,
|
|
23
|
-
preserveModules,
|
|
24
|
-
hoistTransitiveImports,
|
|
25
|
-
esModule,
|
|
26
|
-
entryFileNames,
|
|
27
|
-
chunkFileNames,
|
|
28
|
-
assetFileNames,
|
|
29
|
-
...restOutputOptions
|
|
30
|
-
} = output && !Array.isArray(output) ? output : {};
|
|
31
|
-
|
|
32
|
-
const resolvedBuildConfig = {
|
|
33
|
-
build: {
|
|
34
|
-
ssr: ssr ?? true,
|
|
35
|
-
target: target ?? 'es2020',
|
|
36
|
-
outDir: outDir ?? userOptions.build.server,
|
|
37
|
-
assetsDir: assetsDir ?? '',
|
|
38
|
-
manifest: manifest ?? true,
|
|
39
|
-
ssrManifest: ssrManifest ?? true,
|
|
40
|
-
ssrEmitAssets: ssrEmitAssets ?? true,
|
|
41
|
-
rollupOptions: {
|
|
42
|
-
input: {
|
|
43
|
-
'client': join(userOptions.projectRoot, userOptions.clientEntry)
|
|
44
|
-
},
|
|
45
|
-
output: {
|
|
46
|
-
format: format ?? 'esm',
|
|
47
|
-
preserveModules: preserveModules ?? true,
|
|
48
|
-
hoistTransitiveImports: hoistTransitiveImports ?? false,
|
|
49
|
-
esModule: esModule ?? true,
|
|
50
|
-
entryFileNames: entryFileNames ?? '[name].js',
|
|
51
|
-
chunkFileNames: chunkFileNames ?? '[name].js',
|
|
52
|
-
assetFileNames: assetFileNames ?? '[name][extname]',
|
|
53
|
-
...restOutputOptions
|
|
54
|
-
},
|
|
55
|
-
...restRollupOptions
|
|
56
|
-
},
|
|
57
|
-
...restBuildOptions
|
|
58
|
-
},
|
|
59
|
-
appType: appType ?? 'mpa',
|
|
60
|
-
mode: mode ?? 'production',
|
|
61
|
-
...restUserConfig
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
console.log('resolvedBuildConfig', resolvedBuildConfig);
|
|
65
|
-
return resolvedBuildConfig;
|
|
66
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { InputOption } from "rollup";
|
|
2
|
-
import type { UserConfig } from "vite";
|
|
3
|
-
|
|
4
|
-
export function validateModuleBase(
|
|
5
|
-
input: InputOption,
|
|
6
|
-
moduleBase: string,
|
|
7
|
-
moduleBaseExceptions: string[]
|
|
8
|
-
) {
|
|
9
|
-
for (const [key, value] of Object.entries(input)) {
|
|
10
|
-
const isException = moduleBaseExceptions.includes(key) || ["/index", "index"].includes(key);
|
|
11
|
-
if (!key.includes("/")) return;
|
|
12
|
-
if (value.startsWith("//")) {
|
|
13
|
-
throw new Error(`Path shouldn't start with //`);
|
|
14
|
-
}
|
|
15
|
-
if (!key.startsWith(moduleBase) && !isException) {
|
|
16
|
-
throw new Error(`Invalid input: ${key} does not start with ${moduleBase}`);
|
|
17
|
-
}
|
|
18
|
-
if (!value.startsWith("/" + moduleBase) && !isException) {
|
|
19
|
-
throw new Error(`Invalid value: ${value} does not start with ${moduleBase}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function createSharedBuildConfig(config: UserConfig, rollupOptions: any): UserConfig {
|
|
25
|
-
return {
|
|
26
|
-
...config,
|
|
27
|
-
build: {
|
|
28
|
-
...config.build,
|
|
29
|
-
rollupOptions: {
|
|
30
|
-
...config.build?.rollupOptions,
|
|
31
|
-
...rollupOptions
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { InputOption } from "rollup";
|
|
2
|
-
import type { InputNormalizer, InputNormalizerWorker } from "../types.js";
|
|
3
|
-
|
|
4
|
-
export const mergeInputsAsync = async (
|
|
5
|
-
input: { [key: string]: string },
|
|
6
|
-
input2: InputOption | undefined,
|
|
7
|
-
inputNormalizer: InputNormalizerWorker
|
|
8
|
-
): Promise<Record<string, string>> => {
|
|
9
|
-
if(typeof input === "undefined"){
|
|
10
|
-
throw new Error("The first input can not be undefined");
|
|
11
|
-
} else if(typeof input2 === "undefined") {
|
|
12
|
-
return input;
|
|
13
|
-
} else if(Array.isArray(input2)) {
|
|
14
|
-
const inputsFromArray = Object.fromEntries(await Promise.all(input2.map(async (input)=>inputNormalizer(input))))
|
|
15
|
-
return {
|
|
16
|
-
...input,
|
|
17
|
-
...inputsFromArray,
|
|
18
|
-
}
|
|
19
|
-
} else if(typeof input2 === "object" && input2 != null) {
|
|
20
|
-
return { ...input, ...input2 };
|
|
21
|
-
} else if (typeof input2 === "string") {
|
|
22
|
-
const [key, value] = await inputNormalizer(input2)
|
|
23
|
-
return {
|
|
24
|
-
...input,
|
|
25
|
-
[key]: value,
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error(`Invalid input: ${input2}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const mergeInputs = (
|
|
33
|
-
input: { [key: string]: string },
|
|
34
|
-
input2: InputOption | undefined,
|
|
35
|
-
inputNormalizer: InputNormalizer
|
|
36
|
-
): Record<string, string> => {
|
|
37
|
-
if(typeof input === "undefined"){
|
|
38
|
-
throw new Error("The first input can not be undefined");
|
|
39
|
-
} else if(typeof input2 === "undefined") {
|
|
40
|
-
return input;
|
|
41
|
-
} else if(Array.isArray(input2)) {
|
|
42
|
-
const inputsFromArray = Object.fromEntries(input2.map(inputNormalizer))
|
|
43
|
-
return {
|
|
44
|
-
...input,
|
|
45
|
-
...inputsFromArray,
|
|
46
|
-
}
|
|
47
|
-
} else if(typeof input2 === "object" && input2 != null) {
|
|
48
|
-
return { ...input, ...input2 };
|
|
49
|
-
} else if (typeof input2 === "string") {
|
|
50
|
-
const [key, value] = inputNormalizer(input2)
|
|
51
|
-
return {
|
|
52
|
-
...input,
|
|
53
|
-
[key]: value,
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
throw new Error(`Invalid input: ${input2}`);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { normalizePath } from "vite";
|
|
2
|
-
import { DEFAULT_CONFIG } from "./defaults.js";
|
|
3
|
-
|
|
4
|
-
export const moduleIdDefault =
|
|
5
|
-
({
|
|
6
|
-
projectRoot,
|
|
7
|
-
output: _,
|
|
8
|
-
isProduction,
|
|
9
|
-
}: {
|
|
10
|
-
isProduction: boolean;
|
|
11
|
-
projectRoot: string;
|
|
12
|
-
output: { dir: string };
|
|
13
|
-
}) =>
|
|
14
|
-
(moduleId: string) => {
|
|
15
|
-
const normalized = normalizePath(moduleId);
|
|
16
|
-
const noRoot = normalized.startsWith(projectRoot)
|
|
17
|
-
? normalized.slice(projectRoot.length)
|
|
18
|
-
: normalized;
|
|
19
|
-
if (!isProduction) {
|
|
20
|
-
return noRoot;
|
|
21
|
-
}
|
|
22
|
-
return noRoot.replace(DEFAULT_CONFIG.FILE_REGEX, ".js");
|
|
23
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from "http";
|
|
2
|
-
import type { ViteDevServer } from "vite";
|
|
3
|
-
import { type RequestHandler, type StreamPluginOptions } from "../types.js";
|
|
4
|
-
import { createHandler } from "./createHandler.js";
|
|
5
|
-
|
|
6
|
-
export type DevMiddlewareOptions = Required<
|
|
7
|
-
Pick<
|
|
8
|
-
StreamPluginOptions,
|
|
9
|
-
"moduleBase" | "moduleBasePath" | "moduleBaseURL" | "projectRoot"
|
|
10
|
-
>
|
|
11
|
-
> &
|
|
12
|
-
Pick<StreamPluginOptions, "Page" | "props" | "build" | "Html" | "pageExportName" | "propsExportName">;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates a request handler for development
|
|
16
|
-
*/
|
|
17
|
-
export function createDevMiddleware(
|
|
18
|
-
server: ViteDevServer,
|
|
19
|
-
options: DevMiddlewareOptions
|
|
20
|
-
): RequestHandler {
|
|
21
|
-
// Add HMR support
|
|
22
|
-
const hmr = server.hot;
|
|
23
|
-
|
|
24
|
-
hmr?.on('vite:beforeUpdate', () => {
|
|
25
|
-
// Clear module cache before updates
|
|
26
|
-
server.moduleGraph.invalidateAll();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return async (req: IncomingMessage, res: ServerResponse, next: any) => {
|
|
30
|
-
// Skip non-page requests
|
|
31
|
-
if (
|
|
32
|
-
!req.url ||
|
|
33
|
-
(req.url.includes(".") && !req.url.endsWith("/index.rsc"))
|
|
34
|
-
) {
|
|
35
|
-
return next();
|
|
36
|
-
}
|
|
37
|
-
const url = req.url.endsWith("/index.rsc")
|
|
38
|
-
? req.url.replace("/index.rsc", "/")
|
|
39
|
-
: req.url;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
console.log("[stream] Handling RSC stream");
|
|
43
|
-
|
|
44
|
-
const result = await createHandler(url, options, {
|
|
45
|
-
loader: (id)=>{
|
|
46
|
-
const mod = server.ssrLoadModule(id);
|
|
47
|
-
if(!mod) {
|
|
48
|
-
throw new Error(`[RSC] Module not found: ${id}`);
|
|
49
|
-
} else {
|
|
50
|
-
console.log('[RSC] Loaded module:', id);
|
|
51
|
-
}
|
|
52
|
-
return mod;
|
|
53
|
-
},
|
|
54
|
-
moduleGraph: server.moduleGraph,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (result.type === "error") {
|
|
58
|
-
if (
|
|
59
|
-
(result.error as Error).message?.includes(
|
|
60
|
-
"module runner has been closed"
|
|
61
|
-
)
|
|
62
|
-
) {
|
|
63
|
-
console.log("[RSC] Module runner closed, returning 503");
|
|
64
|
-
res.writeHead(503, { "Content-Type": "text/x-component" });
|
|
65
|
-
res.end('{"error":"Server restarting..."}');
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
console.error("[RSC] Stream error:", result.error);
|
|
69
|
-
res.writeHead(500, { "Content-Type": "text/x-component" });
|
|
70
|
-
res.end('{"error":"Internal Server Error"}');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (result.type !== "success") {
|
|
75
|
-
res.end();
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
res.setHeader("Content-Type", "text/x-component");
|
|
80
|
-
if (result.stream) result.stream.pipe(res);
|
|
81
|
-
} catch (error: any) {
|
|
82
|
-
if (error.message?.includes("module runner has been closed")) {
|
|
83
|
-
console.log("[RSC] Module runner closed, returning 503");
|
|
84
|
-
res.writeHead(503, { "Content-Type": "text/x-component" });
|
|
85
|
-
res.end('{"error":"Server restarting..."}');
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
next(error);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ViteDevServer } from "vite";
|
|
2
|
-
import { createDevMiddleware, type DevMiddlewareOptions } from "./createDevMiddleware.js";
|
|
3
|
-
|
|
4
|
-
export function createDevServer(
|
|
5
|
-
server: ViteDevServer,
|
|
6
|
-
options: DevMiddlewareOptions
|
|
7
|
-
) {
|
|
8
|
-
server.middlewares.use(createDevMiddleware(server, options));
|
|
9
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
createFromNodeStream,
|
|
4
|
-
type CreateFromNodeStreamOptions,
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
} from "react-server-dom-esm/client.node";
|
|
7
|
-
import type { Readable } from "stream";
|
|
8
|
-
|
|
9
|
-
export function createReactNodeStreamer({
|
|
10
|
-
stream,
|
|
11
|
-
moduleBasePath,
|
|
12
|
-
moduleBaseURL,
|
|
13
|
-
options,
|
|
14
|
-
}: {
|
|
15
|
-
stream: Readable;
|
|
16
|
-
moduleBasePath: string;
|
|
17
|
-
moduleBaseURL: string;
|
|
18
|
-
options?: CreateFromNodeStreamOptions;
|
|
19
|
-
}) {
|
|
20
|
-
return createFromNodeStream(
|
|
21
|
-
stream,
|
|
22
|
-
moduleBasePath,
|
|
23
|
-
moduleBaseURL,
|
|
24
|
-
options
|
|
25
|
-
) as React.Usable<React.ReactNode>;
|
|
26
|
-
}
|