@@ -13,8 +13,8 @@ import {
13
13
publishStaticDir ,
14
14
unpublishStaticDir ,
15
15
} from './build/content/static.js'
16
- import { createEdgeHandlers } from './build/functions/edge.js'
17
- import { createServerHandler } from './build/functions/server.js'
16
+ import { clearStaleEdgeHandlers , createEdgeHandlers } from './build/functions/edge.js'
17
+ import { clearStaleServerHandlers , createServerHandler } from './build/functions/server.js'
18
18
import { setImageConfig } from './build/image-cdn.js'
19
19
import { PluginContext } from './build/plugin-context.js'
20
20
import {
@@ -38,8 +38,15 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
38
38
await tracer . withActiveSpan ( 'onPreBuild' , async ( ) => {
39
39
// Enable Next.js standalone mode at build time
40
40
process . env . NEXT_PRIVATE_STANDALONE = 'true'
41
- if ( ! options . constants . IS_LOCAL ) {
42
- await restoreBuildCache ( new PluginContext ( options ) )
41
+ const ctx = new PluginContext ( options )
42
+ if ( options . constants . IS_LOCAL ) {
43
+ // Only clear directory if we are running locally as then we might have stale functions from previous
44
+ // local builds. Directory clearing interferes with other integrations by deleting functions produced by them
45
+ // so ideally this is completely avoided.
46
+ await clearStaleServerHandlers ( ctx )
47
+ await clearStaleEdgeHandlers ( ctx )
48
+ } else {
49
+ await restoreBuildCache ( ctx )
43
50
}
44
51
} )
45
52
}
0 commit comments