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:
@@ -6,9 +6,9 @@ import grabPageServerPath from "./grab-page-server-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 grabPageCombinedServerRes({ file_path, debug, url, query, routeParams, }) {
|
||||
const now = Date.now();
|
||||
const { root_file_path } = grabRootFilePath();
|
||||
const { server_file_path: root_server_file_path } = root_file_path
|
||||
? grabPageServerPath({ file_path: root_file_path })
|
||||
@@ -23,7 +23,7 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
|
||||
// Loader.registry.delete(final_root_server_path);
|
||||
}
|
||||
const root_server_module = final_root_server_path
|
||||
? await import(`${final_root_server_path}?t=${now}`)
|
||||
? await importFresh(final_root_server_path)
|
||||
: undefined;
|
||||
const root_server_fn = root_server_module?.default || root_server_module?.server;
|
||||
const rootServerRes = await grabPageServerRes({
|
||||
@@ -46,7 +46,7 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
|
||||
// Loader.registry.delete(final_page_server_path);
|
||||
}
|
||||
const server_module = final_page_server_path
|
||||
? await import(`${final_page_server_path}?t=${now}`)
|
||||
? await importFresh(final_page_server_path)
|
||||
: undefined;
|
||||
const server_fn = server_module?.default || server_module?.server;
|
||||
const serverRes = await grabPageServerRes({
|
||||
|
||||
Reference in New Issue
Block a user