Unverified Commit 6a2e8cd8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix memory leak from requiring pages (#7659)

parent 19f3c4d7
...@@ -274,6 +274,15 @@ export function isPageStatic( ...@@ -274,6 +274,15 @@ export function isPageStatic(
try { try {
nextEnvConfig.setConfig(runtimeEnvConfig) nextEnvConfig.setConfig(runtimeEnvConfig)
const Comp = require(serverBundle).default const Comp = require(serverBundle).default
// clear cache to prevent memory leak
const mod = require.cache[serverBundle]
delete require.cache[serverBundle]
if (mod.parent) {
const idx = mod.parent.children.indexOf(mod)
mod.parent.children.splice(idx, 1)
}
if (!Comp || !isValidElementType(Comp) || typeof Comp === 'string') { if (!Comp || !isValidElementType(Comp) || typeof Comp === 'string') {
const invalidPage = new Error('invalid-page') const invalidPage = new Error('invalid-page')
;(invalidPage as any).code = 'INVALID_DEFAULT_EXPORT' ;(invalidPage as any).code = 'INVALID_DEFAULT_EXPORT'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment