Skip to content

Commit b1e19ec

Browse files
authored
Remove obsolete deleteAppClientCache() call from webpack plugin (#68535)
The first iteration of `deleteAppClientCache()` was introduced in #41510. Its purpose was to remove stale client components (for SSR) from React's cache. Since React didn't (and still doesn't) offer an API for that, this was accomplished by deleting `react-server-dom-webpack` from the require cache. With the bundling that was introduced in #55362, `deleteAppClientCache()` was changed to delete the whole server runtimes (e.g. `app-page.runtime.dev.js`) from the require cache. This has the unfortunate side effect that also React's other module scope cache (back then `ReactCurrentCache`, now `ReactSharedInternals.A`) is reset between compilations. As a result, when fetching data from a route handler in a page, the fetch cache didn't work properly. This issue was masked though by response buffering for the static generation cache. In #68447 the response buffering will be removed which [uncovered the issue](https://github.com/vercel/next.js/actions/runs/10217197012/job/28270497496). React had two module-scoped caches for client components: - `chunkCache` – caches the loaded JS chunks, as specified in the SSR manifest - `asyncModuleCache` – caches the required modules, if marked as `async` in the SSR manifest The `asyncModuleCache` was subsequently dropped in facebook/react#26985. In addition, with Webpack, we don't create any client component chunks for SSR (removed from the manifest in #50959). So there's no need anymore to delete server runtime bundles from the require cache, and we can remove `deleteAppClientCache()` from the `NextJsRequireCacheHotReloader`. For Turbopack, the exported `deleteAppClientCache` function is still used because Turbopack does create SSR client component chunks. Ideally, React would offer an API to clear the chunk cache. But for now we can keep this logic, since Turbopack also handles this a bit more sophisticated than the Webpack plugin, so that the aforementioned fetch issue does not occur there. This PR in conjunction with #68193 should then also fix the issue that was reported in #52126.
1 parent 174fc2f commit b1e19ec

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

packages/next/src/build/webpack/plugins/nextjs-require-cache-hot-reloader.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,11 @@ export class NextJsRequireCacheHotReloader implements WebpackPluginInstance {
9494
// we need to make sure to clear all server entries from cache
9595
// since they can have a stale webpack-runtime cache
9696
// which needs to always be in-sync
97-
let hasAppEntry = false
9897
const entries = [...compilation.entries.keys()].filter((entry) => {
9998
const isAppPath = entry.toString().startsWith('app/')
100-
if (isAppPath) hasAppEntry = true
10199
return entry.toString().startsWith('pages/') || isAppPath
102100
})
103101

104-
if (hasAppEntry) {
105-
deleteAppClientCache()
106-
}
107-
108102
for (const page of entries) {
109103
const outputPath = path.join(
110104
compilation.outputOptions.path!,

0 commit comments

Comments
 (0)