Bugfix and major refactor. Update server-side page rendering logic.

This commit is contained in:
2026-03-19 05:26:20 +01:00
parent c2c63a1a99
commit ef53ab5f2a
9 changed files with 323 additions and 22 deletions
@@ -11,6 +11,7 @@ import path from "path";
import AppNames from "../../../utils/grab-app-names";
import { existsSync } from "fs";
import grabPageErrorComponent from "./grab-page-error-component";
import grabPageBundledReactComponent from "./grab-page-bundled-react-component";
class NotFoundError extends Error {}
@@ -63,8 +64,6 @@ export default async function grabPageComponent({
throw new Error(errMsg);
}
// const pageName = grabPageName({ path: file_path });
const root_pages_component_ts_file = `${path.join(PAGES_DIR, AppNames["RootPagesComponentName"])}.ts`;
const root_pages_component_tsx_file = `${path.join(PAGES_DIR, AppNames["RootPagesComponentName"])}.tsx`;
const root_pages_component_js_file = `${path.join(PAGES_DIR, AppNames["RootPagesComponentName"])}.js`;
@@ -82,17 +81,7 @@ export default async function grabPageComponent({
const now = Date.now();
const root_module = root_file
? await import(`${root_file}?t=${now}`)
: undefined;
const RootComponent = root_module?.default as FC<any> | undefined;
// const component_file_path = root_module
// ? `${file_path}`
// : `${file_path}?t=${global.LAST_BUILD_TIME ?? 0}`;
const module: BunextPageModule = await import(`${file_path}?t=${now}`);
const module: BunextPageModule = await import(file_path);
const serverRes: BunextPageModuleServerReturn = await (async () => {
try {
@@ -124,16 +113,18 @@ export default async function grabPageComponent({
: undefined
: undefined;
const Component = module.default as FC<any>;
const Head = module.Head as FC<any>;
const component = RootComponent ? (
<RootComponent {...serverRes}>
<Component {...serverRes} />
</RootComponent>
) : (
<Component {...serverRes} />
);
const { component } =
(await grabPageBundledReactComponent({
file_path,
root_file,
server_res: serverRes,
})) || {};
if (!component) {
throw new Error(`Couldn't grab page component`);
}
return {
component,
@@ -152,3 +143,34 @@ export default async function grabPageComponent({
});
}
}
// let root_module: any;
// if (root_file) {
// if (isDevelopment()) {
// root_module = await grabFilePathModule({
// file_path: root_file,
// });
// } else {
// root_module = root_file ? await import(root_file) : undefined;
// }
// }
// const RootComponent = root_module?.default as FC<any> | undefined;
// let module: BunextPageModule;
// if (isDevelopment()) {
// module = await grabFilePathModule({ file_path });
// } else {
// module = await import(file_path);
// }
// const Component = main_module.default as FC<any>;
// const component = RootComponent ? (
// <RootComponent {...serverRes}>
// <Component {...serverRes} />
// </RootComponent>
// ) : (
// <Component {...serverRes} />
// );