Unverified Commit ea2157cd authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[turbopack] Clear chunk cache on HMR instead of creating new `next-server` VM (#81664)

parent 43b64ccd
...@@ -37,7 +37,7 @@ import { ...@@ -37,7 +37,7 @@ import {
} from './middleware-turbopack' } from './middleware-turbopack'
import { PageNotFoundError } from '../../shared/lib/utils' import { PageNotFoundError } from '../../shared/lib/utils'
import { debounce } from '../utils' import { debounce } from '../utils'
import { deleteCache, deleteFromRequireCache } from './require-cache' import { deleteCache } from './require-cache'
import { import {
clearAllModuleContexts, clearAllModuleContexts,
clearModuleContext, clearModuleContext,
...@@ -342,30 +342,12 @@ export async function createHotReloaderTurbopack( ...@@ -342,30 +342,12 @@ export async function createHotReloaderTurbopack(
resetFetch() resetFetch()
const hasAppPaths = writtenEndpoint.serverPaths.some(({ path: p }) =>
p.startsWith('server/app')
)
// Edge uses the browser runtime which already disposes chunks individually. // Edge uses the browser runtime which already disposes chunks individually.
// TODO: process.env.NEXT_RUNTIME is 'nodejs' even though Node.js runtime is not used. // TODO: process.env.NEXT_RUNTIME is 'nodejs' even though Node.js runtime is not used.
if ('__turbopack_clear_chunk_cache__' in globalThis) { if ('__turbopack_clear_chunk_cache__' in globalThis) {
;(globalThis as any).__turbopack_clear_chunk_cache__() ;(globalThis as any).__turbopack_clear_chunk_cache__()
} }
// TODO: Stop re-evaluating React Client once it relies on Turbopack's chunk cache.
if (hasAppPaths) {
deleteFromRequireCache(
require.resolve(
'next/dist/compiled/next-server/app-page-turbo.runtime.dev.js'
)
)
deleteFromRequireCache(
require.resolve(
'next/dist/compiled/next-server/app-page-turbo-experimental.runtime.dev.js'
)
)
}
const serverPaths = writtenEndpoint.serverPaths.map(({ path: p }) => const serverPaths = writtenEndpoint.serverPaths.map(({ path: p }) =>
join(distDir, p) join(distDir, p)
) )
......
...@@ -2,7 +2,7 @@ import isError from '../../lib/is-error' ...@@ -2,7 +2,7 @@ import isError from '../../lib/is-error'
import { realpathSync } from '../../lib/realpath' import { realpathSync } from '../../lib/realpath'
import { clearManifestCache } from '../load-manifest.external' import { clearManifestCache } from '../load-manifest.external'
export function deleteFromRequireCache(filePath: string) { function deleteFromRequireCache(filePath: string) {
try { try {
filePath = realpathSync(filePath) filePath = realpathSync(filePath)
} catch (e) { } catch (e) {
......
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