Core RSC Plugins
Examine the compiler plugins coordinating Client Manifest generations, Server Action IPC proxying, and React 19 compilations.
Key Files Location:
• Client Manifest:./dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.mjs
• Actions Proxy:./dinou/esbuild/plugins-esbuild/server-functions-plugin.mjs
• React 19 Compiler:./dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.mjs
💡 Overview
React Server Components require tight compiler integrations: client component bundles must be indexed so they can be referenced in server streams, and Server Actions (which contain private backend database lookups) must be replaced with proxy callbacks before sending code to browser clients.
📊 Client Manifest Plugin Flow
The flowchart below traces the client component export parsing and manifest indexing process:
📊 Server Functions Proxy Flow
The flowchart below shows how Server Actions are transformed into client-side fetch proxy calls:
📊 React Compiler Bridge Flow
The flowchart below shows the Babel bridge that compiles React 19 auto-memoized trees:
⚙️ react-client-manifest-plugin.mjs
Below is the full, complete code of the React client manifest compiler plugin:
import fs from "node:fs/promises";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { readFileSync } from "node:fs";
import parseExports from "../../core/parse-exports.js";
import { useClientRegex } from "../../constants.js";
export default function reactClientManifestPlugin({
manifestPath = "react_client_manifest/react-client-manifest.json",
manifest = {},
} = {}) {
return {
name: "react-client-manifest",
setup(build) {
build.onEnd(async (result) => {
try {
const meta = result.metafile;
if (meta && meta.outputs) {
for (const [outFile, outInfo] of Object.entries(meta.outputs)) {
const fileName = outFile.replace(/\\/g, "/").split(/[\/]/).pop();
const outUrl = "/" + fileName;
const modulePath = outInfo.entryPoint;
if (!modulePath || modulePath.startsWith("dinou-asset-entry:")) {
continue;
}
const absModulePath = path.resolve(modulePath);
const baseFileUrl = pathToFileURL(absModulePath).href;
const code = readFileSync(absModulePath, "utf8");
const isClientModule = useClientRegex.test(code.trim());
if (!isClientModule) {
continue;
}
const exports = parseExports(code);
for (const expName of exports) {
const manifestKey =
expName === "default"
? baseFileUrl
: `${baseFileUrl}#${expName}`;
if (manifest[manifestKey]) {
manifest[manifestKey].id = outUrl; // Map module url to the final build file path
}
}
}
}
await fs.mkdir(path.dirname(manifestPath), { recursive: true });
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2), "utf8");
} catch (err) {
console.warn("[react-client-manifest] onEnd error:", err.message);
}
});
},
};
}⚙️ server-functions-plugin.mjs
Below is the full, complete code of the Server Action proxy compiler plugin:
import path from "path";
import fs from "node:fs/promises";
import parseExports from "../../core/parse-exports.js";
import { useServerRegex } from "../../constants.js";
export default function serverFunctionsPlugin(manifestData = {}) {
return {
name: "server-functions-proxy",
setup(build) {
const root = process.cwd();
const serverFunctions = new Map();
// 1. Intercept "use server" actions and compile proxy skeletons
build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
const code = await fs.readFile(args.path, "utf8");
if (!useServerRegex.test(code.trim())) return null;
const exports = parseExports(code);
if (exports.length === 0) return null;
const relativePath = path.relative(root, args.path).replace(/\\/g, "/");
serverFunctions.set(relativePath, new Set(exports));
const fileUrl = `file:///${relativePath}`;
let proxyCode = `import { createServerFunctionProxy } from "/__SERVER_FUNCTION_PROXY__";\n`;
for (const exp of exports) {
const key = exp === "default" ? `${fileUrl}#default` : `${fileUrl}#${exp}`;
if (exp === "default") {
proxyCode += `export default createServerFunctionProxy(${JSON.stringify(key)});
`;
} else {
proxyCode += `export const ${exp} = createServerFunctionProxy(${JSON.stringify(key)});
`;
}
}
return { contents: proxyCode, loader: "js" };
});
// 2. Map placeholder path to final compiled build file
build.onEnd(async (result) => {
const hashedProxy = "/" + (manifestData["serverFunctionProxy.js"] || "serverFunctionProxy.js");
for (const outputFile of Object.values(result.outputFiles)) {
const fileCode = new TextDecoder().decode(outputFile.contents);
if (!fileCode) continue;
if (fileCode.includes("/__SERVER_FUNCTION_PROXY__")) {
const newCode = fileCode.replace(/\/__SERVER_FUNCTION_PROXY__/g, hashedProxy);
outputFile.contents = new TextEncoder().encode(newCode);
}
}
const manifestObj = {};
for (const [path, exportsSet] of serverFunctions.entries()) {
manifestObj[path] = Array.from(exportsSet);
}
const manifestPath = path.join("server_functions_manifest", "server-functions-manifest.json");
await fs.mkdir(path.dirname(manifestPath), { recursive: true });
await fs.writeFile(manifestPath, JSON.stringify(manifestObj, null, 2));
});
},
};
}⚙️ babel-react-compiler-plugin.mjs
Below is the full, complete code of the Babel React Compiler plugin bridge:
import babel from "@babel/core";
import fs from "node:fs/promises";
import path from "node:path";
const norm = (p) => path.resolve(p).replace(/\\/g, "/");
export default function babelReactCompilerPlugin() {
return {
name: "babel-react-compiler-bridge",
setup(build) {
const entryPoints = build.initialOptions.entryPoints;
build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
if (args.path.includes("node_modules")) return;
const abs = path.resolve(args.path);
const absNorm = norm(abs);
const isAnEntryPoint = Object.values(entryPoints).some(
(val) => norm(path.resolve(val)) === absNorm,
);
if (!isAnEntryPoint) return;
try {
const source = await fs.readFile(args.path, "utf8");
const filename = args.path;
// Compile code using Babel and the new React 19 compiler memoizer plugin
const result = await babel.transformAsync(source, {
filename,
presets: [
["@babel/preset-react", { runtime: "automatic" }],
"@babel/preset-typescript",
],
plugins: ["babel-plugin-react-compiler"],
sourceMaps: true,
configFile: false,
});
if (!result || !result.code) return;
return { contents: result.code, loader: "js" };
} catch (error) {
return { errors: [{ text: error.message, detail: error }] };
}
});
},
};
}