Skip to content

Commit 9f60901

Browse files
author
Barthélémy Ledoux
authored
fix: avoid nextjs unsafeCache and watchOptions (#20440)
1 parent e896efc commit 9f60901

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

npm/react/plugins/next/findNextWebpackConfig.js

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ async function getNextWebpackConfig (config) {
4141

4242
checkSWC(nextWebpackConfig, config)
4343

44+
if (nextWebpackConfig.watchOptions && Array.isArray(nextWebpackConfig.watchOptions.ignored)) {
45+
nextWebpackConfig.watchOptions = {
46+
...nextWebpackConfig.watchOptions,
47+
ignored: [...nextWebpackConfig.watchOptions.ignored.filter((pattern) => !/node_modules/.test(pattern)), '**/node_modules/!(@cypress/webpack-dev-server/dist/browser.js)**'],
48+
}
49+
50+
debug('found options next.js watchOptions.ignored %O', nextWebpackConfig.watchOptions.ignored)
51+
}
52+
4453
return nextWebpackConfig
4554
}
4655

npm/webpack-dev-server/src/makeWebpackConfig.ts

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ export async function makeWebpackConfig (userWebpackConfig: webpack.Configuratio
7878
})
7979
}
8080

81+
if (typeof userWebpackConfig?.module?.unsafeCache === 'function') {
82+
const originalCachePredicate = userWebpackConfig.module.unsafeCache
83+
84+
userWebpackConfig.module.unsafeCache = (module: any) => {
85+
return originalCachePredicate(module) && !/[\\/]webpack-dev-server[\\/]dist[\\/]browser\.js/.test(module.resource)
86+
}
87+
}
88+
8189
const mergedConfig = merge<webpack.Configuration>(
8290
userWebpackConfig,
8391
makeDefaultWebpackConfig(template),

0 commit comments

Comments
 (0)