Add more features. Customize HTML. Add server logic and other page module exports to __root

This commit is contained in:
2026-03-23 19:14:56 +01:00
parent 67ed8749e2
commit 6f1db7c01f
15 changed files with 389 additions and 232 deletions
@@ -14,21 +14,25 @@ export default function grabPageReactComponentString({
}: Params): string | undefined {
try {
const target_path = pagePathTransform({ page_path: file_path });
const target_root_path = root_file_path
? pagePathTransform({ page_path: root_file_path })
: undefined;
let tsx = ``;
const server_res_json = JSON.stringify(
EJSON.stringify(server_res || {}) ?? "{}",
);
if (root_file_path) {
tsx += `import Root from "${root_file_path}"\n`;
if (target_root_path) {
tsx += `import Root from "${target_root_path}"\n`;
}
tsx += `import Page from "${target_path}"\n`;
tsx += `export default function Main() {\n\n`;
tsx += `const props = JSON.parse(${server_res_json})\n\n`;
tsx += ` return (\n`;
if (root_file_path) {
if (target_root_path) {
tsx += ` <Root suppressHydrationWarning={true} {...props}><Page {...props} /></Root>\n`;
} else {
tsx += ` <Page suppressHydrationWarning={true} {...props} />\n`;