@@ -13,8 +13,8 @@ import {
1313 publishStaticDir ,
1414 unpublishStaticDir ,
1515} 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'
1818import { setImageConfig } from './build/image-cdn.js'
1919import { PluginContext } from './build/plugin-context.js'
2020import {
@@ -38,8 +38,15 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
3838 await tracer . withActiveSpan ( 'onPreBuild' , async ( ) => {
3939 // Enable Next.js standalone mode at build time
4040 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 )
4350 }
4451 } )
4552}
0 commit comments