Imporve HMR Post-build function speed

This commit is contained in:
2026-03-30 05:44:34 +01:00
parent 2b170d24e1
commit 86d4bb8d6c
16 changed files with 192 additions and 99 deletions
@@ -12,6 +12,7 @@ import grabRootFilePath from "./grab-root-file-path";
import grabPageServerRes from "./grab-page-server-res";
import grabPageServerPath from "./grab-page-server-path";
import type { JSX } from "react";
import grabPageCombinedServerRes from "./grab-page-combined-server-res";
type Params = {
file_path: string;
@@ -34,62 +35,26 @@ export default async function grabPageModules({
const root_module: BunextRootModule | undefined = root_file_path
? await import(`${root_file_path}?t=${now}`)
: undefined;
const { server_file_path: root_server_file_path } = root_file_path
? grabPageServerPath({ file_path: root_file_path })
: {};
const root_server_module: BunextPageServerModule = root_server_file_path
? await import(`${root_server_file_path}?t=${now}`)
: undefined;
const root_server_fn =
root_server_module?.default || root_server_module?.server;
const rootServerRes: BunextPageModuleServerReturn | undefined =
root_server_fn
? await grabPageServerRes({
server_function: root_server_fn,
url,
query,
routeParams,
})
: undefined;
if (debug) {
log.info(`rootServerRes:`, rootServerRes);
}
const module: BunextPageModule = await import(`${file_path}?t=${now}`);
const { server_file_path } = grabPageServerPath({ file_path });
const server_module: BunextPageServerModule = server_file_path
? await import(`${server_file_path}?t=${now}`)
: undefined;
if (debug) {
log.info(`module:`, module);
}
const server_fn = server_module?.default || server_module?.server;
const serverRes: BunextPageModuleServerReturn | undefined = server_fn
? await grabPageServerRes({
server_function: server_fn,
url,
query,
routeParams,
})
: undefined;
if (debug) {
log.info(`serverRes:`, serverRes);
}
const mergedServerRes = _.merge(rootServerRes || {}, serverRes || {});
const { serverRes } = await grabPageCombinedServerRes({
file_path,
debug,
query,
routeParams,
url,
});
const { component } =
(await grabPageBundledReactComponent({
file_path,
root_file_path,
server_res: mergedServerRes,
server_res: serverRes,
})) || {};
if (!component) {
@@ -102,7 +67,7 @@ export default async function grabPageModules({
return {
component,
serverRes: mergedServerRes,
serverRes,
module,
root_module,
};