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:
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Dev: bypass Bun's module registry so rebuilt files are picked up.
|
||||
* Prod: import by stable path so each module is loaded (and kept) once.
|
||||
* A unique `?t=` per call creates a new, never-evicted module record, so
|
||||
* using it in production leaks memory on every request.
|
||||
*/
|
||||
export default function importFresh<T = any>(file_path: string): Promise<T>;
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import isDevelopment from "./is-development";
|
||||
/**
|
||||
* Dev: bypass Bun's module registry so rebuilt files are picked up.
|
||||
* Prod: import by stable path so each module is loaded (and kept) once.
|
||||
* A unique `?t=` per call creates a new, never-evicted module record, so
|
||||
* using it in production leaks memory on every request.
|
||||
*/
|
||||
export default function importFresh(file_path) {
|
||||
return import(isDevelopment() ? `${file_path}?t=${Date.now()}` : file_path);
|
||||
}
|
||||
Reference in New Issue
Block a user