Refactor SSR strategy. Redirect before bundling any page component. Additional bugfixes for dev environment

This commit is contained in:
2026-04-12 16:20:16 +01:00
parent 84d490b189
commit f0aae8a8fa
27 changed files with 210 additions and 87 deletions
@@ -1,5 +1,6 @@
import type {
BunextPageModule,
BunextPageModuleServerReturn,
BunextRootModule,
BunxRouteParams,
} from "../../../types";
@@ -8,6 +9,7 @@ import _ from "lodash";
import { log } from "../../../utils/log";
import grabRootFilePath from "./grab-root-file-path";
import grabPageCombinedServerRes from "./grab-page-combined-server-res";
import type { FC } from "react";
type Params = {
file_path: string;
@@ -18,6 +20,13 @@ type Params = {
skip_server_res?: boolean;
};
type Return = {
component: FC;
serverRes: BunextPageModuleServerReturn | undefined;
module: BunextPageModule;
root_module: BunextPageModule | undefined;
};
export default async function grabPageModules({
file_path,
debug,
@@ -25,9 +34,28 @@ export default async function grabPageModules({
query,
routeParams,
skip_server_res,
}: Params) {
}: Params): Promise<Return | Response> {
const now = Date.now();
const { serverRes } = skip_server_res
? {}
: await grabPageCombinedServerRes({
file_path,
debug,
query,
routeParams,
url,
});
if (serverRes?.redirect?.destination) {
return Response.redirect(
serverRes.redirect.destination,
serverRes.redirect.permanent
? 301
: serverRes.redirect.status_code || 302,
);
}
const { root_file_path } = grabRootFilePath();
const root_module: BunextRootModule | undefined = root_file_path
? await import(`${root_file_path}?t=${now}`)
@@ -39,16 +67,6 @@ export default async function grabPageModules({
log.info(`module:`, module);
}
const { serverRes } = skip_server_res
? {}
: await grabPageCombinedServerRes({
file_path,
debug,
query,
routeParams,
url,
});
const { component } =
(await grabPageBundledReactComponent({
file_path,