Stop per-request module re-imports leaking memory in production
Page rendering imported the SSR bundle and .server.ts modules with a unique ?t= query on every request, in production too. Each one became a new, never-evicted module record (and re-ran module top-level code), so RSS grew with request count. Cache-bust only in dev via importFresh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -5,6 +5,7 @@ import grabRootFilePath from "./grab-root-file-path";
|
||||
import path from "path";
|
||||
import grabDirNames from "../../../utils/grab-dir-names";
|
||||
import grabRelativePath from "../../../utils/grab-relative-path";
|
||||
import importFresh from "../../../utils/import-fresh";
|
||||
const { ROOT_DIR } = grabDirNames();
|
||||
export default async function grabPageBundledReactComponent({ file_path, return_tsx_only, }) {
|
||||
try {
|
||||
@@ -12,7 +13,7 @@ export default async function grabPageBundledReactComponent({ file_path, return_
|
||||
if (global.BUNEXT_SSR_BUNDLER_CTX_MAP?.[relative_path]) {
|
||||
const abs = path.join(ROOT_DIR, global.BUNEXT_SSR_BUNDLER_CTX_MAP[relative_path].path);
|
||||
// Loader.registry.delete(abs);
|
||||
const mod = await import(`${abs}?t=${Date.now()}`);
|
||||
const mod = await importFresh(abs);
|
||||
const Main = mod.default;
|
||||
return {
|
||||
component: Main,
|
||||
|
||||
Reference in New Issue
Block a user