veryfront 0.1.543 → 0.1.545
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/esm/deno.js +1 -1
- package/esm/src/agent/testing/live-evals/result.d.ts.map +1 -1
- package/esm/src/agent/testing/live-evals/result.js +10 -21
- package/esm/src/build/embedded/preset.d.ts.map +1 -1
- package/esm/src/build/embedded/preset.js +0 -6
- package/esm/src/html/dev-scripts.d.ts +1 -1
- package/esm/src/html/dev-scripts.d.ts.map +1 -1
- package/esm/src/html/dev-scripts.js +2 -4
- package/esm/src/mcp/server.d.ts.map +1 -1
- package/esm/src/mcp/server.js +22 -5
- package/esm/src/rendering/rsc/client-boot.ts +16 -3
- package/esm/src/rendering/rsc/hydrate-client.ts +0 -11
- package/esm/src/rendering/rsc/types.d.ts +1 -1
- package/esm/src/rendering/rsc/types.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/endpoints.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/endpoints.handler.js +0 -6
- package/esm/src/server/services/rsc/endpoints/endpoint-router.d.ts.map +1 -1
- package/esm/src/server/services/rsc/endpoints/endpoint-router.js +0 -3
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.d.ts.map +1 -1
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.js +2 -2
- package/esm/src/server/services/rsc/endpoints/script-handlers.d.ts.map +1 -1
- package/esm/src/server/services/rsc/endpoints/script-handlers.js +12 -3
- package/esm/src/server/services/rsc/orchestrators/handler.d.ts +0 -2
- package/esm/src/server/services/rsc/orchestrators/handler.d.ts.map +1 -1
- package/esm/src/server/services/rsc/orchestrators/handler.js +0 -6
- package/esm/src/server/services/rsc/orchestrators/page-handler.d.ts.map +1 -1
- package/esm/src/server/services/rsc/orchestrators/page-handler.js +1 -4
- package/esm/src/types/index.d.ts +1 -1
- package/esm/src/types/index.d.ts.map +1 -1
- package/esm/src/types/rsc.d.ts +0 -4
- package/esm/src/types/rsc.d.ts.map +1 -1
- package/esm/src/utils/constants/server.d.ts +0 -3
- package/esm/src/utils/constants/server.d.ts.map +1 -1
- package/esm/src/utils/constants/server.js +0 -3
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
- package/src/deno.js +1 -1
- package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +1 -1
- package/src/deps/esm.sh/@types/react-dom@19.2.3/static.d.ts +1 -1
- package/src/deps/esm.sh/@types/react@19.2.3/global.d.ts +165 -0
- package/src/deps/esm.sh/@types/react@19.2.3/index.d.ts +4301 -0
- package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +1 -1
- package/src/src/agent/testing/live-evals/result.ts +43 -30
- package/src/src/build/embedded/preset.ts +0 -6
- package/src/src/html/dev-scripts.ts +2 -4
- package/src/src/mcp/server.ts +27 -6
- package/src/src/rendering/rsc/types.ts +0 -1
- package/src/src/server/handlers/dev/endpoints.handler.ts +0 -6
- package/src/src/server/services/rsc/endpoints/endpoint-router.ts +0 -4
- package/src/src/server/services/rsc/endpoints/rsc-bundles.generated.ts +2 -2
- package/src/src/server/services/rsc/endpoints/script-handlers.ts +12 -3
- package/src/src/server/services/rsc/orchestrators/handler.ts +0 -7
- package/src/src/server/services/rsc/orchestrators/page-handler.ts +1 -4
- package/src/src/types/index.ts +0 -1
- package/src/src/types/rsc.ts +0 -5
- package/src/src/utils/constants/server.ts +0 -3
- package/src/src/utils/version-constant.ts +1 -1
- package/esm/src/rendering/rsc/client-hydrator.ts +0 -210
- package/esm/src/server/handlers/dev/scripts/dev-loader.d.ts +0 -9
- package/esm/src/server/handlers/dev/scripts/dev-loader.d.ts.map +0 -1
- package/esm/src/server/handlers/dev/scripts/dev-loader.js +0 -16
- package/esm/src/server/services/rsc/orchestrators/hydrator-handler.d.ts +0 -12
- package/esm/src/server/services/rsc/orchestrators/hydrator-handler.d.ts.map +0 -1
- package/esm/src/server/services/rsc/orchestrators/hydrator-handler.js +0 -92
- package/src/src/server/handlers/dev/scripts/dev-loader.ts +0 -17
- package/src/src/server/services/rsc/orchestrators/hydrator-handler.ts +0 -107
|
@@ -42,7 +42,6 @@ export const INTERNAL_ENDPOINTS = {
|
|
|
42
42
|
// Development endpoints
|
|
43
43
|
HMR_RUNTIME: `${INTERNAL_PREFIX}/hmr-runtime.js`,
|
|
44
44
|
HMR: `${INTERNAL_PREFIX}/hmr.js`,
|
|
45
|
-
HYDRATE: `${INTERNAL_PREFIX}/hydrate.js`,
|
|
46
45
|
ERROR_OVERLAY: `${INTERNAL_PREFIX}/error-overlay.js`,
|
|
47
46
|
// Legacy endpoint retained for backward compatibility (no active handler).
|
|
48
47
|
DEV_LOADER: `${INTERNAL_PREFIX}/dev-loader.js`,
|
|
@@ -64,8 +63,6 @@ export const INTERNAL_ENDPOINTS = {
|
|
|
64
63
|
RSC_PAGE: `${INTERNAL_PREFIX}/rsc/page`,
|
|
65
64
|
RSC_MODULE: `${INTERNAL_PREFIX}/rsc/module`,
|
|
66
65
|
RSC_DOM: `${INTERNAL_PREFIX}/rsc/dom.js`,
|
|
67
|
-
RSC_HYDRATOR: `${INTERNAL_PREFIX}/rsc/hydrator.js`,
|
|
68
|
-
RSC_HYDRATE_CLIENT: `${INTERNAL_PREFIX}/rsc/hydrate-client.js`,
|
|
69
66
|
|
|
70
67
|
// Library module endpoints
|
|
71
68
|
LIB_CHAT_REACT: `${INTERNAL_PREFIX}/lib/chat/react.js`,
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
3
|
-
import { rscLogger } from "../client/browser-logger.ts";
|
|
4
|
-
import {
|
|
5
|
-
COMPILATION_ERROR,
|
|
6
|
-
MODULE_NOT_FOUND,
|
|
7
|
-
NETWORK_ERROR,
|
|
8
|
-
} from "#veryfront/errors/error-registry.ts";
|
|
9
|
-
import { isVeryfrontError } from "#veryfront/errors/http-error.ts";
|
|
10
|
-
import { createErrorDisplay } from "#veryfront/security/client/html-sanitizer.ts";
|
|
11
|
-
import type { RSCHydratorOptions } from "./types.ts";
|
|
12
|
-
|
|
13
|
-
interface WindowWithVeryfront extends Window {
|
|
14
|
-
__VERYFRONT_DEV__?: boolean;
|
|
15
|
-
__RSC_AUTO_HYDRATE__?: boolean;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class RSCHydrator {
|
|
19
|
-
private componentCache = new Map<string, React.ComponentType<Record<string, unknown>>>();
|
|
20
|
-
private manifestUrl: string;
|
|
21
|
-
private manifest: Record<string, string> | null = null;
|
|
22
|
-
private onError?: (error: Error) => void;
|
|
23
|
-
|
|
24
|
-
constructor(options: RSCHydratorOptions = {}) {
|
|
25
|
-
this.manifestUrl = options.manifestUrl ?? "/_veryfront/rsc/manifest";
|
|
26
|
-
this.onError = options.onError;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async hydrate(): Promise<void> {
|
|
30
|
-
try {
|
|
31
|
-
await this.loadManifest();
|
|
32
|
-
|
|
33
|
-
const placeholders = document.querySelectorAll("[data-rsc-component]");
|
|
34
|
-
rscLogger.info(`Found ${placeholders.length} components to hydrate`);
|
|
35
|
-
|
|
36
|
-
await Promise.all(
|
|
37
|
-
Array.from(
|
|
38
|
-
placeholders,
|
|
39
|
-
(placeholder) => this.hydratePlaceholder(placeholder as HTMLElement),
|
|
40
|
-
),
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
rscLogger.info("Hydration complete");
|
|
44
|
-
} catch (error) {
|
|
45
|
-
rscLogger.error("Hydration error:", error);
|
|
46
|
-
this.onError?.(error as Error);
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private async hydratePlaceholder(element: HTMLElement): Promise<void> {
|
|
52
|
-
const componentName = element.dataset.rscComponent;
|
|
53
|
-
if (!componentName) {
|
|
54
|
-
rscLogger.warn("Placeholder missing component name", element);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const propsJson = element.dataset.rscProps;
|
|
59
|
-
const instanceId = element.dataset.rscId;
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const props: Record<string, unknown> = propsJson ? JSON.parse(propsJson) : {};
|
|
63
|
-
const Component = await this.loadClientComponent(componentName);
|
|
64
|
-
const reactElement = React.createElement(Component, props);
|
|
65
|
-
|
|
66
|
-
if (element.innerHTML.trim()) {
|
|
67
|
-
rscLogger.debug(`Hydrating ${componentName} #${instanceId}`);
|
|
68
|
-
hydrateRoot(element, reactElement, {
|
|
69
|
-
identifierPrefix: "vf",
|
|
70
|
-
onRecoverableError: () => {},
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
rscLogger.debug(`Rendering ${componentName} #${instanceId}`);
|
|
76
|
-
createRoot(element).render(reactElement);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
rscLogger.error(`Failed to hydrate component ${componentName}:`, error);
|
|
79
|
-
this.onError?.(error as Error);
|
|
80
|
-
|
|
81
|
-
if (!this.isDevelopment()) return;
|
|
82
|
-
|
|
83
|
-
element.textContent = "";
|
|
84
|
-
element.appendChild(
|
|
85
|
-
createErrorDisplay({
|
|
86
|
-
title: "RSC Hydration Error",
|
|
87
|
-
message: `Component: ${componentName}`,
|
|
88
|
-
details: (error as Error).message,
|
|
89
|
-
}),
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private async loadClientComponent(
|
|
95
|
-
name: string,
|
|
96
|
-
): Promise<React.ComponentType<Record<string, unknown>>> {
|
|
97
|
-
const cached = this.componentCache.get(name);
|
|
98
|
-
if (cached) return cached;
|
|
99
|
-
|
|
100
|
-
const componentPath = await this.getComponentPath(name);
|
|
101
|
-
if (!componentPath) {
|
|
102
|
-
throw MODULE_NOT_FOUND.create({
|
|
103
|
-
detail: "Client component not found in manifest",
|
|
104
|
-
context: { name, manifest: this.manifest },
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
rscLogger.debug(`Loading component ${name} from ${componentPath}`);
|
|
110
|
-
const module = await import(componentPath);
|
|
111
|
-
const Component = module.default || module[name];
|
|
112
|
-
|
|
113
|
-
if (!Component) {
|
|
114
|
-
throw COMPILATION_ERROR.create({
|
|
115
|
-
detail: `Component ${name} not found in module`,
|
|
116
|
-
context: { componentPath, name },
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (typeof Component !== "function" && typeof Component !== "object") {
|
|
121
|
-
throw COMPILATION_ERROR.create({
|
|
122
|
-
detail: `Invalid component type for ${name}`,
|
|
123
|
-
context: { type: typeof Component, name },
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const validated = Component as React.ComponentType<Record<string, unknown>>;
|
|
128
|
-
this.componentCache.set(name, validated);
|
|
129
|
-
return validated;
|
|
130
|
-
} catch (error) {
|
|
131
|
-
rscLogger.error(`Failed to load component ${name}:`, error);
|
|
132
|
-
if (
|
|
133
|
-
isVeryfrontError(error) && (
|
|
134
|
-
error.slug === "compilation-error" ||
|
|
135
|
-
error.slug === "module-not-found" ||
|
|
136
|
-
error.slug === "network-error"
|
|
137
|
-
)
|
|
138
|
-
) {
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
throw COMPILATION_ERROR.create({
|
|
142
|
-
detail: `Failed to load client component ${name}`,
|
|
143
|
-
cause: error,
|
|
144
|
-
context: { name },
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private async getComponentPath(name: string): Promise<string | null> {
|
|
150
|
-
if (!this.manifest) await this.loadManifest();
|
|
151
|
-
return this.manifest?.[name] ?? null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
private async loadManifest(): Promise<void> {
|
|
155
|
-
if (this.manifest) return;
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
const response = await fetch(this.manifestUrl);
|
|
159
|
-
|
|
160
|
-
if (!response.ok) {
|
|
161
|
-
throw NETWORK_ERROR.create({
|
|
162
|
-
detail: "Failed to load manifest",
|
|
163
|
-
status: response.status,
|
|
164
|
-
context: { url: this.manifestUrl },
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const data: Record<string, unknown> = await response.json();
|
|
169
|
-
this.manifest = (data.components || data) as Record<string, string>;
|
|
170
|
-
|
|
171
|
-
rscLogger.debug("Loaded manifest:", this.manifest);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
rscLogger.error("Failed to load manifest:", error);
|
|
174
|
-
|
|
175
|
-
if (!this.isDevelopment()) throw error;
|
|
176
|
-
|
|
177
|
-
rscLogger.warn("Continuing without manifest - will try direct imports");
|
|
178
|
-
this.manifest = {};
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private isDevelopment(): boolean {
|
|
183
|
-
return !!(window as WindowWithVeryfront).__VERYFRONT_DEV__;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function hydrateRSC(options?: RSCHydratorOptions): Promise<void> {
|
|
188
|
-
return new RSCHydrator(options).hydrate();
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function autoHydrate(): void {
|
|
192
|
-
if ((window as WindowWithVeryfront).__RSC_AUTO_HYDRATE__ === false) return;
|
|
193
|
-
|
|
194
|
-
const run = (): void => {
|
|
195
|
-
hydrateRSC().catch((error) => {
|
|
196
|
-
rscLogger.error("Auto-hydration failed:", error);
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
if (document.readyState === "loading") {
|
|
201
|
-
document.addEventListener("DOMContentLoaded", run, { once: true });
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
run();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (typeof window !== "undefined") {
|
|
209
|
-
autoHydrate();
|
|
210
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/****
|
|
2
|
-
* Hydrate Script Generator
|
|
3
|
-
* Generates client-side JavaScript for hydration
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Hydration script that imports the RSC client and hydrates a project by slug.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getHydrateScript(_slug: string): string;
|
|
9
|
-
//# sourceMappingURL=dev-loader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev-loader.d.ts","sourceRoot":"","sources":["../../../../../../src/src/server/handlers/dev/scripts/dev-loader.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQtD"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/****
|
|
2
|
-
* Hydrate Script Generator
|
|
3
|
-
* Generates client-side JavaScript for hydration
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Hydration script that imports the RSC client and hydrates a project by slug.
|
|
7
|
-
*/
|
|
8
|
-
export function getHydrateScript(_slug) {
|
|
9
|
-
return `
|
|
10
|
-
// Veryfront hydration compatibility script
|
|
11
|
-
// Legacy full-document HTML still loads /_veryfront/hydrate.js. The
|
|
12
|
-
// modern RSC client auto-boots on import, so this shim only preserves the
|
|
13
|
-
// old URL without depending on a removed "hydrate" export.
|
|
14
|
-
import '/_veryfront/rsc/client.js';
|
|
15
|
-
`.trim();
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { FileSystemAdapter } from "../../../../platform/adapters/base.js";
|
|
2
|
-
export declare class HydratorHandler {
|
|
3
|
-
private fsAdapter?;
|
|
4
|
-
constructor(fsAdapter?: FileSystemAdapter | undefined);
|
|
5
|
-
handle(): Promise<Response>;
|
|
6
|
-
private readHydratorFile;
|
|
7
|
-
private bundleHydrator;
|
|
8
|
-
private fallbackToSource;
|
|
9
|
-
private createJavaScriptResponse;
|
|
10
|
-
private createFallbackResponse;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=hydrator-handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hydrator-handler.d.ts","sourceRoot":"","sources":["../../../../../../src/src/server/services/rsc/orchestrators/hydrator-handler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAS/E,qBAAa,eAAe;IACd,OAAO,CAAC,SAAS,CAAC;gBAAV,SAAS,CAAC,EAAE,iBAAiB,YAAA;IAE3C,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC;IAejC,OAAO,CAAC,gBAAgB;YAIV,cAAc;YAiDd,gBAAgB;IAU9B,OAAO,CAAC,wBAAwB;IAShC,OAAO,CAAC,sBAAsB;CAK/B"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
2
|
-
import { createError, toError } from "../../../../errors/veryfront-error.js";
|
|
3
|
-
import { createFileSystem } from "../../../../platform/compat/fs.js";
|
|
4
|
-
import * as pathHelper from "../../../../platform/compat/path/index.js";
|
|
5
|
-
import { serverLogger } from "../../../../utils/index.js";
|
|
6
|
-
const logger = serverLogger.component("rsc");
|
|
7
|
-
const compatFs = createFileSystem();
|
|
8
|
-
export class HydratorHandler {
|
|
9
|
-
fsAdapter;
|
|
10
|
-
constructor(fsAdapter) {
|
|
11
|
-
this.fsAdapter = fsAdapter;
|
|
12
|
-
}
|
|
13
|
-
async handle() {
|
|
14
|
-
const hydratorPath = pathHelper.join(pathHelper.dirname(pathHelper.fromFileUrl(globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).url)), "../../../../rendering/rsc/hydrate-client.ts");
|
|
15
|
-
try {
|
|
16
|
-
const bundled = await this.bundleHydrator(hydratorPath);
|
|
17
|
-
return this.createJavaScriptResponse(bundled);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
logger.error("Hydrator bundling failed:", error);
|
|
21
|
-
return this.fallbackToSource(hydratorPath);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
readHydratorFile(filePath) {
|
|
25
|
-
return this.fsAdapter?.readFile(filePath) ?? compatFs.readTextFile(filePath);
|
|
26
|
-
}
|
|
27
|
-
async bundleHydrator(filePath) {
|
|
28
|
-
const { build, stop } = await import("../../../../extensions/bundler/index.js");
|
|
29
|
-
try {
|
|
30
|
-
const source = await this.readHydratorFile(filePath);
|
|
31
|
-
const result = await build({
|
|
32
|
-
bundle: true,
|
|
33
|
-
write: false,
|
|
34
|
-
format: "esm",
|
|
35
|
-
platform: "browser",
|
|
36
|
-
target: "es2020",
|
|
37
|
-
stdin: {
|
|
38
|
-
contents: source,
|
|
39
|
-
loader: "ts",
|
|
40
|
-
resolveDir: pathHelper.dirname(filePath),
|
|
41
|
-
sourcefile: filePath,
|
|
42
|
-
},
|
|
43
|
-
external: [
|
|
44
|
-
"react",
|
|
45
|
-
"react-dom",
|
|
46
|
-
"react-dom/client",
|
|
47
|
-
"node:os",
|
|
48
|
-
"node:fs",
|
|
49
|
-
"node:fs/promises",
|
|
50
|
-
"node:process",
|
|
51
|
-
],
|
|
52
|
-
logLevel: "warning",
|
|
53
|
-
});
|
|
54
|
-
const outputText = result.outputFiles?.[0]?.text;
|
|
55
|
-
if (outputText == null) {
|
|
56
|
-
throw toError(createError({
|
|
57
|
-
type: "config",
|
|
58
|
-
message: "esbuild produced no output",
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
logger.debug("Hydrator bundled successfully", { size: outputText.length });
|
|
62
|
-
return outputText;
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
if (!("__vfTestPreserveEsbuild" in dntShim.dntGlobalThis)) {
|
|
66
|
-
await stop();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async fallbackToSource(filePath) {
|
|
71
|
-
try {
|
|
72
|
-
const source = await this.readHydratorFile(filePath);
|
|
73
|
-
return this.createJavaScriptResponse(source);
|
|
74
|
-
}
|
|
75
|
-
catch (readError) {
|
|
76
|
-
logger.error("Failed to read hydrator file:", readError);
|
|
77
|
-
return this.createFallbackResponse();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
createJavaScriptResponse(content) {
|
|
81
|
-
return new Response(content, {
|
|
82
|
-
headers: {
|
|
83
|
-
"content-type": "application/javascript",
|
|
84
|
-
"cache-control": "no-cache",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
createFallbackResponse() {
|
|
89
|
-
const fallback = `export async function hydrateRSC(){ console.log('[RSC] Hydrator not available'); }`;
|
|
90
|
-
return this.createJavaScriptResponse(fallback);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/****
|
|
2
|
-
* Hydrate Script Generator
|
|
3
|
-
* Generates client-side JavaScript for hydration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Hydration script that imports the RSC client and hydrates a project by slug.
|
|
8
|
-
*/
|
|
9
|
-
export function getHydrateScript(_slug: string): string {
|
|
10
|
-
return `
|
|
11
|
-
// Veryfront hydration compatibility script
|
|
12
|
-
// Legacy full-document HTML still loads /_veryfront/hydrate.js. The
|
|
13
|
-
// modern RSC client auto-boots on import, so this shim only preserves the
|
|
14
|
-
// old URL without depending on a removed "hydrate" export.
|
|
15
|
-
import '/_veryfront/rsc/client.js';
|
|
16
|
-
`.trim();
|
|
17
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "../../../../../_dnt.shims.js";
|
|
2
|
-
import { createError, toError } from "../../../../errors/veryfront-error.js";
|
|
3
|
-
import type { FileSystemAdapter } from "../../../../platform/adapters/base.js";
|
|
4
|
-
import { createFileSystem } from "../../../../platform/compat/fs.js";
|
|
5
|
-
import * as pathHelper from "../../../../platform/compat/path/index.js";
|
|
6
|
-
import { serverLogger } from "../../../../utils/index.js";
|
|
7
|
-
|
|
8
|
-
const logger = serverLogger.component("rsc");
|
|
9
|
-
|
|
10
|
-
const compatFs = createFileSystem();
|
|
11
|
-
|
|
12
|
-
export class HydratorHandler {
|
|
13
|
-
constructor(private fsAdapter?: FileSystemAdapter) {}
|
|
14
|
-
|
|
15
|
-
async handle(): Promise<Response> {
|
|
16
|
-
const hydratorPath = pathHelper.join(
|
|
17
|
-
pathHelper.dirname(pathHelper.fromFileUrl(import.meta.url)),
|
|
18
|
-
"../../../../rendering/rsc/hydrate-client.ts",
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const bundled = await this.bundleHydrator(hydratorPath);
|
|
23
|
-
return this.createJavaScriptResponse(bundled);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
logger.error("Hydrator bundling failed:", error);
|
|
26
|
-
return this.fallbackToSource(hydratorPath);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
private readHydratorFile(filePath: string): Promise<string> {
|
|
31
|
-
return this.fsAdapter?.readFile(filePath) ?? compatFs.readTextFile(filePath);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private async bundleHydrator(filePath: string): Promise<string> {
|
|
35
|
-
const { build, stop } = await import("../../../../extensions/bundler/index.js");
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
const source = await this.readHydratorFile(filePath);
|
|
39
|
-
|
|
40
|
-
const result = await build({
|
|
41
|
-
bundle: true,
|
|
42
|
-
write: false,
|
|
43
|
-
format: "esm",
|
|
44
|
-
platform: "browser",
|
|
45
|
-
target: "es2020",
|
|
46
|
-
stdin: {
|
|
47
|
-
contents: source,
|
|
48
|
-
loader: "ts",
|
|
49
|
-
resolveDir: pathHelper.dirname(filePath),
|
|
50
|
-
sourcefile: filePath,
|
|
51
|
-
},
|
|
52
|
-
external: [
|
|
53
|
-
"react",
|
|
54
|
-
"react-dom",
|
|
55
|
-
"react-dom/client",
|
|
56
|
-
"node:os",
|
|
57
|
-
"node:fs",
|
|
58
|
-
"node:fs/promises",
|
|
59
|
-
"node:process",
|
|
60
|
-
],
|
|
61
|
-
logLevel: "warning",
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const outputText = result.outputFiles?.[0]?.text;
|
|
65
|
-
if (outputText == null) {
|
|
66
|
-
throw toError(
|
|
67
|
-
createError({
|
|
68
|
-
type: "config",
|
|
69
|
-
message: "esbuild produced no output",
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
logger.debug("Hydrator bundled successfully", { size: outputText.length });
|
|
75
|
-
return outputText;
|
|
76
|
-
} finally {
|
|
77
|
-
if (!("__vfTestPreserveEsbuild" in dntShim.dntGlobalThis)) {
|
|
78
|
-
await stop();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private async fallbackToSource(filePath: string): Promise<Response> {
|
|
84
|
-
try {
|
|
85
|
-
const source = await this.readHydratorFile(filePath);
|
|
86
|
-
return this.createJavaScriptResponse(source);
|
|
87
|
-
} catch (readError) {
|
|
88
|
-
logger.error("Failed to read hydrator file:", readError);
|
|
89
|
-
return this.createFallbackResponse();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private createJavaScriptResponse(content: string): Response {
|
|
94
|
-
return new Response(content, {
|
|
95
|
-
headers: {
|
|
96
|
-
"content-type": "application/javascript",
|
|
97
|
-
"cache-control": "no-cache",
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private createFallbackResponse(): Response {
|
|
103
|
-
const fallback =
|
|
104
|
-
`export async function hydrateRSC(){ console.log('[RSC] Hydrator not available'); }`;
|
|
105
|
-
return this.createJavaScriptResponse(fallback);
|
|
106
|
-
}
|
|
107
|
-
}
|