Bugfix: Refactor SSR bundler. Fix stale cache SSR modules.
This commit is contained in:
@@ -11,9 +11,6 @@ export default async function rebuildBundler(params?: Params) {
|
||||
try {
|
||||
global.ROUTER.reload();
|
||||
|
||||
// await global.BUNDLER_CTX?.dispose();
|
||||
// global.BUNDLER_CTX = undefined;
|
||||
|
||||
const new_artifacts = await allPagesBunBundler({
|
||||
page_file_paths: params?.target_file_paths,
|
||||
});
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import _ from "lodash";
|
||||
import type { GlobalHMRControllerObject } from "../../types";
|
||||
import grabPageComponent from "./web-pages/grab-page-component";
|
||||
import initPages from "../bundler/init-pages";
|
||||
|
||||
export default async function serverPostBuildFn() {
|
||||
// if (!global.IS_FIRST_BUNDLE_READY) {
|
||||
// global.IS_FIRST_BUNDLE_READY = true;
|
||||
// }
|
||||
|
||||
if (!global.HMR_CONTROLLERS?.[0] || !global.BUNDLER_CTX_MAP) {
|
||||
return;
|
||||
}
|
||||
@@ -61,11 +56,5 @@ export default async function serverPostBuildFn() {
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
|
||||
global.REACT_DOM_MODULE_CACHE.delete(target_artifact.local_path);
|
||||
|
||||
initPages({
|
||||
target_page_file: target_artifact.local_path,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import grabDirNames from "../../utils/grab-dir-names";
|
||||
import { log } from "../../utils/log";
|
||||
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
|
||||
import serverPostBuildFn from "./server-post-build-fn";
|
||||
import initPages from "../bundler/init-pages";
|
||||
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
|
||||
@@ -129,9 +128,12 @@ async function fullRebuild(params?: { msg?: string }) {
|
||||
|
||||
await global.BUNDLER_CTX?.dispose();
|
||||
global.BUNDLER_CTX = undefined;
|
||||
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
|
||||
await global.SSR_BUNDLER_CTX?.dispose();
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
|
||||
allPagesESBuildContextBundler({
|
||||
post_build_fn: serverPostBuildFn,
|
||||
});
|
||||
@@ -143,8 +145,6 @@ async function fullRebuild(params?: { msg?: string }) {
|
||||
global.PAGES_SRC_WATCHER.close();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
|
||||
initPages();
|
||||
}
|
||||
|
||||
function reloadWatcher() {
|
||||
@@ -152,6 +152,4 @@ function reloadWatcher() {
|
||||
global.PAGES_SRC_WATCHER.close();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
|
||||
initPages();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import grabTsxStringModule from "./grab-tsx-string-module";
|
||||
import { log } from "../../../utils/log";
|
||||
import type { FC } from "react";
|
||||
import grabRootFilePath from "./grab-root-file-path";
|
||||
import path from "path";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
|
||||
type Params = {
|
||||
file_path: string;
|
||||
@@ -15,6 +19,16 @@ export default async function grabPageBundledReactComponent({
|
||||
return_tsx_only,
|
||||
}: Params): Promise<GrabPageReactBundledComponentRes | undefined> {
|
||||
try {
|
||||
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
||||
const mod = await import(
|
||||
path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[file_path].path)
|
||||
);
|
||||
|
||||
const Main = mod.default as FC;
|
||||
|
||||
return { component: Main };
|
||||
}
|
||||
|
||||
const { root_file_path } = grabRootFilePath();
|
||||
|
||||
let tsx = grabPageReactComponentString({
|
||||
|
||||
@@ -1,31 +1,23 @@
|
||||
import EJSON from "../../../utils/ejson";
|
||||
import { log } from "../../../utils/log";
|
||||
|
||||
type Params = {
|
||||
file_path: string;
|
||||
root_file_path?: string;
|
||||
// server_res?: any;
|
||||
};
|
||||
|
||||
export default function grabPageReactComponentString({
|
||||
file_path,
|
||||
root_file_path,
|
||||
// server_res,
|
||||
}: Params): string | undefined {
|
||||
try {
|
||||
let tsx = ``;
|
||||
|
||||
// const server_res_json = JSON.stringify(
|
||||
// EJSON.stringify(server_res || {}) ?? "{}",
|
||||
// );
|
||||
|
||||
if (root_file_path) {
|
||||
tsx += `import Root from "${root_file_path}"\n`;
|
||||
}
|
||||
|
||||
tsx += `import Page from "${file_path}"\n`;
|
||||
tsx += `export default function Main({...props}) {\n\n`;
|
||||
// tsx += `const props = JSON.parse(${server_res_json})\n\n`;
|
||||
tsx += ` return (\n`;
|
||||
if (root_file_path) {
|
||||
tsx += ` <Root {...props}><Page {...props} /></Root>\n`;
|
||||
|
||||
Reference in New Issue
Block a user