未验证 提交 6a2e8cd8 编写于 作者: J JJ Kasper 提交者: GitHub

Fix memory leak from requiring pages (#7659)

上级 19f3c4d7
......@@ -274,6 +274,15 @@ export function isPageStatic(
try {
nextEnvConfig.setConfig(runtimeEnvConfig)
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') {
const invalidPage = new Error('invalid-page')
;(invalidPage as any).code = 'INVALID_DEFAULT_EXPORT'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册